-
Notifications
You must be signed in to change notification settings - Fork 61
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
Heap corruption on Python when torch
is imported before juliacall
, but not the reverse
#215
Comments
Oof, fun error! If the root cause is the same as in the comment you linked (which looks highly plausible) then I doubt it can be fixed from JuliaCall. It could/should be documented in a troubleshooting/FAQ section in the docs. We could maybe add a warning via an import hook, but that seems a bit much. |
Thanks - is there a way that solution 1 could be used here? (is this similar to how JuliaCall works?) i.e.,
Unfortunately the solutions 2 and 3 don't seem to help me (maybe because I'm on a mac). |
I'm not sure what |
Ah, yes, I think you are right... Thanks! |
Just added a warning for this to PySR until it gets solved - feel free to do something similar in PythonCall.jl! I think this will prevent users getting discouraged, as a random segfault when starting julia would be a mystery - especially if torch is imported by a package rather than directly imported. def check_for_conflicting_libraries(): # pragma: no cover
"""Check whether there are conflicting modules, and display warnings."""
# See https://github.com/pytorch/pytorch/issues/78829: importing
# pytorch before running `pysr.fit` causes a segfault.
torch_is_loaded = "torch" in sys.modules
if torch_is_loaded:
warnings.warn(
"`torch` was loaded before the Julia instance started. "
"This may cause a segfault when running `PySRRegressor.fit`. "
"To avoid this, please run `pysr.julia_helpers.init_julia()` *before* "
"importing `torch`. "
"For updates, see https://github.com/pytorch/pytorch/issues/78829"
) This simple
|
Good idea. I'm documenting it in a new Troubleshooting section in the docs. |
Here is my system information:
I have not tested this on other systems.
Here is the trigger:
and the error:
However, I can run the following just fine:
Here are some related issues: JuliaPy/pyjulia#125, pytorch/pytorch#78829. Particularly, check out the comment from @tttc3: pytorch/pytorch#78829 (comment).
The text was updated successfully, but these errors were encountered: