Repository navigation
Conversation
The tf32_off context manager mutates process-global TF32 state (torch.backends.cuda.matmul plus the cudnn flags) with a per-entry save/restore. Multithreaded test runners such as MultiThreadedTestCase execute the decorated test body once per rank thread, so linalg OpInfo tests carrying with_tf32_off enter tf32_off concurrently: a thread can snapshot already-modified state and restore it last, leaking modified flags past the final exit. The fp32 precision leak detector added in #185236 now catches this in the distributed dtensor CPU shards (cuda.matmul fp32_precision "none" -> "ieee", cudnn conv/rnn "tf32" -> "none", the exact signature of the interleaved cudnn.flags entry write surviving). The fix makes tf32_off first-in/last-out: a refcount guarded by a lock so only the first concurrent entry saves state and applies the writes, and only the last exit restores. The lock is held only around the bookkeeping, never across the yield, so rank threads still run concurrently and dtensor collectives cannot deadlock. The writes themselves are unchanged, and the cudnn.flags context manager is kept (entered and exited manually so the exit can run at last-out) because it handles the frozen-flags machinery test suites enable. tf32_on is untouched since it is only reachable through the already device-gated tf32_on_and_off, which multithreaded runners do not use. An alternative was a thread-local implementation via at::NoTF32Guard, which already exists and is consulted in the cuBLAS handle pool, but it has no Python binding, no cudnn coverage, and is invisible to compiled-code paths that read the global flag at compile time; that remains a possible follow-up. Authored with Claude Code (Claude).
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/190285
Note: Links to docs will display an error until the docs builds have been completed. This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
Collaborator
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The
tf32_offcontext manager mutates process-global TF32 state (torch.backends.cuda.matmulplus the cudnn flags) with a per-entry save/restore. Multithreaded test runners such asMultiThreadedTestCaseexecute the decorated test body once per rank thread, so linalg OpInfo tests carryingwith_tf32_offentertf32_offconcurrently: a thread can snapshot already-modified state and restore it last, leaking modified flags past the final exit. The fp32 precision leak detector added in #185236 now catches this in the distributed dtensor CPU shards (cuda.matmulfp32_precision "none" -> "ieee", cudnn conv/rnn "tf32" -> "none", the exact signature of the interleavedcudnn.flagsentry write surviving).The fix makes
tf32_offfirst-in/last-out: a refcount guarded by a lock so only the first concurrent entry saves state and applies the writes, and only the last exit restores. The lock is held only around the bookkeeping, never across the yield, so rank threads still run concurrently and dtensor collectives cannot deadlock. The writes themselves are unchanged, and thecudnn.flagscontext manager is kept (entered and exited manually so the exit can run at last-out) because it handles the frozen-flags machinery test suites enable.tf32_onis untouched since it is only reachable through the already device-gatedtf32_on_and_off, which multithreaded runners do not use.An alternative was a thread-local implementation via
at::NoTF32Guard, which already exists and is consulted in the cuBLAS handle pool, but it has no Python binding, no cudnn coverage, and is invisible to compiled-code paths that read the global flag at compile time; that remains a possible follow-up.Authored with an AI assistant (Claude Code).