-
Notifications
You must be signed in to change notification settings - Fork 326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix fasthmath precision issue #1048
Fix fasthmath precision issue #1048
Conversation
@seanlaw |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1048 +/- ##
==========================================
- Coverage 96.97% 96.70% -0.28%
==========================================
Files 90 93 +3
Lines 15104 15214 +110
==========================================
+ Hits 14647 14712 +65
- Misses 457 502 +45 ☔ View full report in Codecov by Sentry. |
@seanlaw Can you please check out the change and merge the branch if it is all good? I tested the change locally and all unit tests are passing when Numba== |
@NimaSarajpoor As I think about it more, I am starting to question whether turning off
and now we are adding a third variant |
A small part of me is questioning whether we should/could update the unit test but I want to avoid it as it may hide other problems. This is a tough one! |
Correct. What if we remove We can try to measure how much performance is hit by that. I was looking at the description of flags. While there might be other flags that may affect a floating-point value,
Since STUMPY tries to have a good precision, I was wondering if we should just remove the flag
This triggered me to look into the STUMPY's unit tests. I noticed we use Lines 288 to 296 in 3165d1c
should be trusted up to So, we can create a private function (Btw, this approach sounds weird to me!) |
Yes, I think we should look at the performance and see how much of a hit we take. If it's less than 5% difference then it might be a good idea to turn it off. We might be able to give power users the option of making things faster setting a global configuration variable.
Agreed. Let's check the performance first and at least be armed with data to make a decision |
Is I measured the impact of removing (1) fastmath is True: Used the current version of STUMPY, i.e. v1.13.0 (2) fastmath 7 flags: Replaced (3) fastmath 6 flags: Replaced It turns out that there is a considerable impact on the running time when we switch from (1) to (2).
|
According to
@NimaSarajpoor I'm struggling a little to think through what our goal is so maybe you can help me. It's clear that ANY use of
Additionally, the use of So, if I think about it from a user's perspective, 99.9% of users won't care about the imprecision/IEEE 754 compliance as they likely care about performance way more. However, for the 0.1% of users that care, we should have a way to allow them to easily set/unset custom In other words, I think the default
However, the issue is that we currently have a mixture of What do you think @NimaSarajpoor? |
One possible solution would be to add default configurations to the
Then, when you do something like:
Note:
I'd like to hear your thoughts on this @NimaSarajpoor. |
Thanks for detailed explanation! I do agree for the most part and was wondering if such manipulation can happen in Now here is the tricky part. On one hand, we understand that there can be slight loss of precision and, logically speaking, we should not compare them with naive version. On the other hand, we cannot just manipulate flags in the unit testing since, at the end of the day, users use a code that has those flags by default. This is like a paradox. we currently ASSUME that the loss of precision is so little that it does not affects the unit tests, and we include flags in the unit testing, which is what STUMPY does. Now, we should ACCEPT that the ASSUMPTION can be wrong sometimes, like in
I was wondering if we should go with
|
Yes, and it's annoying as hell! Maybe we can do something like
It's a little bit of cheating in that we "compare" the computed values BUT we don't assert until we know they match. Thoughts? What I don't know is whether or not |
This is a nice idea! This is like trying the next best assertion.
I tried and it failed. I am reading some relevant discussion on numba Discourse. One suggested solution was to get the python function and create new njit function:
However this does not solve our problem. because, I think, As a side, there is one hacky solution here but I prefer to avoid it for now as this creates code branching. |
@NimaSarajpoor What about clearing the cache via |
@seanlaw
Going to revert my changes and check again to make sure I did not miss anything. |
@seanlaw Note:
This assertion fails. And this test:
also fails. |
Great! I noticed that each
Not sure if this is helpful. |
@seanlaw (1)
Now, if I ADD the following two lines just before computing
(2) Unfortunately, adding those two lines above to the
|
@NimaSarajpoor In case it may be helpful, you could possibly use this function to help recompile everything:
|
It's really strange. I did some tests:
Somehow, the final Even if I try to force
Note that Let's not worry about |
Recompiling all njit functions seems to take a negligible time. I think it is safer to just recompile all functions. For instance, in the future, if something is changed, we know that this part will be still okay because we just recompile everything. Need to think if there is a more elegant way to do it but I tried this and it worked:
Going to follow these steps: We can stop here. Or, we can continue and add the changes that @seanlaw suggested here: (4) Revise config and refactor (3). As suggested, we can add new function for reseting values (and recompile everything). Similarly, we can add a function that set config vars to new values, and recompile everything.
@seanlaw |
The Lines 68 to 72 in 3165d1c
So, we should probably reuse/refactor/share some of the code by doing:
Using
Personally, I think that following my previous comment is my preference because it really anchors (and pushes the user) back to a clearly defined set of default values. More importantly, I think that the
Hmm, I am really questioning WHY the initial/first compilation takes SO long but recompilation is SO fast?! |
👍
In fact, I did change it locally and noticed the test function seems to be dirty, and hence created the function
I am curious to know the answer too! I created a small njit-decorated function |
@seanlaw
And this gives me:
And I tried to go deeper by printing out
but why do I see [Update] [Update2] I checked the metadata and noticed the sum of times reported in the pipeline time of the first compilation is almost the same as the |
@NimaSarajpoor Did you need anything from me? |
@seanlaw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanlaw
I made some changes to address the recently-raised concerns. Also, we now have test for the fastmath.py
module thanks to your suggestion. I added a couple of comments for now to seek your advice.
@NimaSarajpoor Do you think we're ready to merge? Everything looks good to me. After it has merged, I can trigger the "other" workflows (https://github.com/stumpy-dev/automate/actions) to see if things fail/pass |
@seanlaw Just one question: Do you think we should add test to check for |
Yes, let's do it! Maybe we should should include it inside of the call to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seanlaw
I added a new function to ./fastmath.py
. I left some comments. Could you please take a look and let me know what you think?
@NimaSarajpoor After staring at the code and trying to convince myself that "it's okay", I came to the conclusion that it's way too complicated. I tried to understand the approach but it's too convoluted (I came to that result when you commented about using
For 5 lines of code, I think this is "good enough" as it:
Apologies if I steered you in the wrong way and made it feel like adding it to |
Thanks for the explanation! As I was adding more nested for-loops/if-blocks, I was smelling it but then tried to avoid it to some extent 😅
Right.... The regex pattern is also simple and can be read easily.
All good, no apology needed! It actually helps me improve my thinking process! |
dd5cc64
to
2369e33
Compare
@seanlaw |
@NimaSarajpoor Thanks again for your time and effort here! |
@NimaSarajpoor commit db1958a now enables coverage testing of |
Okay, we now have proper coverage for |
See: stumpy-dev/automate#3
See MWE: stumpy-dev/automate#3 (comment)
The tests are passing for both numba version 0.60 and 0.61.0rc1