Repository navigation
Conversation
Graph-safe generator handles share state with the active CUDA generator. Saving only the handles lets forward advance the saved RNG position, so dropout recomputation can produce a different mask and incorrect input gradients. Save seed and offset values separately and rewind the original states only while recomputing. Restore the live values on exit so aliases and CUDA graph registrations stay valid. During capture, keep using the graph-safe handles. Captured dropout recomputation remains a separate limitation. Cover both checkpoint modes with default, tracked, and shared RNG streams, and verify that an existing graph can replay after an eager checkpoint. Signed-off-by: losewayy <104015127+losewayy@users.noreply.github.com>
losewayy
marked this pull request as ready for review
November 8, 2026 14:23
Contributor
[Medium impact] The PR appears safe to merge, with no new actionable issues found. SummaryShares RNG save and restore code between both checkpoint modes while preserving the original generator handles.
Reviews (2) · Last reviewed commit: "[PyTorch] Test CUDA RNG restoration afte..." · Reviewed by Greptile |
Draw from the default and tracked CUDA generators between forward and backward. Compare their states before and after backward in both checkpoint modes to catch any change to the live streams. Signed-off-by: losewayy <104015127+losewayy@users.noreply.github.com>
This branch has not been deployed
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.
Description
Checkpointing saves graph-safe generator handles before forward. Those handles share mutable CUDA RNG state, so forward advances the offsets that recompute later reads. Dropout can then produce a different mask and incorrect input gradients.
Save the seed and offset separately from the handles, rewind the original states in place for recompute, and restore the live values on exit. This preserves shared RNG streams and the state already registered with CUDA graphs. The captured dropout recompute mismatch reported in #3834 remains.
Fixes #3833
Type of change
Changes
On an RTX 5070 Ti Laptop GPU with PyTorch 2.14.1+cu130, tracked-dropout gradient mismatches fell from 2017 of 4096 elements to zero. The checkpoint test selection passed all 33 cases, including eight regression cases. An explicit generator registration probe also passed capture and replay on PyTorch 2.11.0+cu128. The graph regression exercises the registration API that PyTorch 2.14 reports as deprecated.
Checklist: