-
Notifications
You must be signed in to change notification settings - Fork 65
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. |
I am still seeing this error on macos, but I see the error when loading juliacall after numba. Here's the CI that is failing: pydata/sparse#767. I'm willing to put some development effort into this, but it's a little bit out of my wheelhouse. I suspect the issue is also with llvm symbols. Does anyone know what it would take to fix this? Is a PR to numba required? |
So @tttc3 has the deepest understanding of this issue although it was back in 2022 so things might have changed since then. They wrote up this super useful and detailed comment describing what they had looked at: pytorch/pytorch#78829 (comment). I will copy it here for visibility:
My guess is that if the issue is anything like the PyTorch one, then yes, a PR to numba is required. The potential fix would have been to change PyTorch to use |
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: