-
Notifications
You must be signed in to change notification settings - Fork 329
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
Fixed #1066 Permanently Remove Recompile #1067
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,12 +54,15 @@ def _set(module_name, func_name, flag): | |
module = importlib.import_module(f".{module_name}", package="stumpy") | ||
func = getattr(module, func_name) | ||
try: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there any particular advantage in using try-except block? If not, what do you think about using a simple if-block?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If I think about "normal" usage, I will think about this more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Makes sense!! Thanks for helping me understand your view! The if-block might seem cleaner but it creates branching here which is not the case when we think about the regular scenario. |
||
func.targetoptions["fastmath"] = flag | ||
func.recompile() | ||
py_func = func.py_func # Copy raw Python function (independent of `njit`) | ||
njit_signature = func.targetoptions.copy() # Copy the `njit` arguments | ||
njit_signature.pop("nopython", None) # Pop redundant `nopython` declaration | ||
njit_signature["fastmath"] = flag # Apply new `fastmath` flag | ||
func = njit(py_func, **njit_signature) # Assign `njit` function with new target | ||
setattr(module, func_name, func) # Monkey-patch `njit` into global space | ||
except AttributeError as e: | ||
if numba.config.DISABLE_JIT and ( | ||
str(e) == "'function' object has no attribute 'targetoptions'" | ||
or str(e) == "'function' object has no attribute 'recompile'" | ||
str(e) == "'function' object has no attribute 'py_func'" | ||
): | ||
pass | ||
else: # pragma: no cover | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,7 @@ | |
from numba import cuda | ||
|
||
import stumpy | ||
from stumpy import cache, config, core, fastmath | ||
from stumpy import config, core, fastmath | ||
|
||
try: | ||
from numba.errors import NumbaPerformanceWarning | ||
|
@@ -156,7 +156,6 @@ def test_snippets(): | |
fastmath._set( | ||
"core", "_calculate_squared_distance", {"nsz", "arcp", "contract", "afn"} | ||
) | ||
cache._recompile() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right. I did not appreciate this and did not capture this in my original code. I will explore more |
||
|
||
( | ||
cmp_snippets, | ||
|
@@ -187,7 +186,6 @@ def test_snippets(): | |
if not numba.config.DISABLE_JIT: # pragma: no cover | ||
# Revert fastmath flag back to their default values | ||
fastmath._reset("core", "_calculate_squared_distance") | ||
cache._recompile() | ||
|
||
|
||
@pytest.mark.filterwarnings("ignore", category=NumbaPerformanceWarning) | ||
|
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.
Removing
_recompile
here means that_save
only doescache._enable()
, which does nothing if a njit function is already compiled. The reason thattests/test_cache.py::test_cache_save_after_clear
is still passing is because bothref_cache
andcomp_cache
are now empty.stumpy/tests/test_cache.py
Lines 11 to 27 in bbc97e4
To have a better test, we should move up the first call of
cache.save()
, and put it just before calling the functionstumpy.stump
. This way we know that we have some files in ref. Then, the test in this version should fail and expose the issue to us.However, when I made such change, I noticed that the tests are NOT failing still. The returned cache files is still an empty list. There is a deeper issue here. According to Numba's document:
So, I turned on
NUMBA_CACHE_DIR
and noticed that it writes to the local git directory "stumpy", in the path./stumpy/__pycache__
, however,cache._get_cache()
reads the files from the following path, which is where stumpy is installed.and that's why it returns 0 files.
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.
This is unexpected behavior. I will look into this
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
Correction: "I turned on
NUMBA_DEBUG_CACHE
"