Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: initialize torch.compile per thread, even for backward thread#1511

Merged
dxqb merged 2 commits into
Nerogar:masterfrom
dxqb:recompile-limit
Jun 7, 2026
Merged

fix: initialize torch.compile per thread, even for backward thread#1511
dxqb merged 2 commits into
Nerogar:masterfrom
dxqb:recompile-limit

Conversation

@dxqb

@dxqb dxqb commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator

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-files passes
  • Launched the affected UI or script and exercised the change
  • Tested with at least one real preset / config when relevant (note which: Flux2)

AI assistance

  • AI-assisted — I have read every line in this diff and can defend each change

dxqb and others added 2 commits June 7, 2026 14:12
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.
@dxqb dxqb mentioned this pull request Jun 7, 2026
5 tasks
@dxqb dxqb merged commit 6b6090a into Nerogar:master Jun 7, 2026
1 check passed
@dxqb dxqb deleted the recompile-limit branch June 7, 2026 12:51
BitcrushedHeart pushed a commit to BitcrushedHeart/OneTrainer that referenced this pull request Jun 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant