fix: initialize torch.compile per thread, even for backward thread#1511
Merged
Conversation
Since torch 2.12, dynamo config overrides are stored in ContextVars (pytorch/pytorch#173568), which threads don't inherit. The recompile limit raised by init_compile() therefore no longer applied to the autograd worker threads, which recompute checkpointed modules during the backward pass - training crashed with FailOnRecompileLimitHit once enough input shapes accumulated, despite the raised limit. Call init_compile() in OffloadCheckpointLayer.__checkpointing_forward so the recomputation thread sets its own config. The non-offload CheckpointLayer is unaffected: it is compiled as a whole, so its recomputation runs inside the compiled backward without re-entering dynamo. The Mod.eval patch is applied once at import time instead. Co-Authored-By: Claude Opus 4.8 <[email protected]>
Updated comments regarding the handling of negative numbers in Mod.eval and related issues.
BitcrushedHeart
pushed a commit
to BitcrushedHeart/OneTrainer
that referenced
this pull request
Jun 20, 2026
…hread (Nerogar#1511) --------- Co-authored-by: Claude Opus 4.8 <[email protected]>
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.
Summary
Workaround for pytorch/pytorch#186537 on top of #1495, which wasn't sufficient, because it didn't address the backward thread
Test plan
pre-commit run --all-filespassesAI assistance