-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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 caching allocator of out-of-tree device is destructed before the … #126677
Conversation
…destruction of tensors cached by autocast
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/126677
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (3 Unrelated Failures)As of commit 086e2da with merge base d9c3485 (): BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Hey! I would be curious in general, how do we handle a Tensor of privateuse1 device that outlives the .so providing that support (let's say we manually unload the shared lib to trigger this without static initialization ordering being involved)? @FFFrog might have an idea? |
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.
Even if it doesn't completely solve the problem, this seems harmless enough
@pytorchbot merge |
Merge failedReason: This PR needs a If not, please add the To add a label, you can comment to pytorchbot, for example For more information, see Details for Dev Infra teamRaised by workflow job |
@pytorchbot merge |
Merge startedYour change will be merged once all checks pass (ETA 0-4 Hours). Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Yes, currently there is such a possibility. For example, |
Sorry, I can't find any other good ideas to solve this problem other than trying to avoid it. In my opinion, defining a global variable directly is almost the same as defining a variable in a function, with just a few differences: Similarities: Difference: Therefore, we can defer the registration of cached_casts through the latter, and it will be deconstructed first (before the allocator is deconstructed) when the program exits. I completely agree that autoloading would fundamentally avoid this problem, but it only avoids it rather than solving it. |
…destruction of tensors cached by autocast
Root Cause
For out-of-tree device extension it is loaded after torch (different .so), so the global variable
cached_casts
may be constructed before caching allocator and then destructed in reversed order when exit.Fix
Lazily initialize
cached_casts
to correct the order.How to Reproduce && Test
Modify the testcase
TestAutocastGPU.test_cast_cache_is_global
in test/test_autocast.py to run on your out-of-tree device. You will see following failure in the end of test.cc @mcarilli @ptrblck @leslie-fang-intel @jgong5 @albanD @ezyang