Repository navigation
Block CUDA graphs: only release the cudagraph pool for tree functions the block backend compiled - #15777
Merged
Conversation
…ackend compiled it The pool release counted every cudagraph tree function created during a graphed block call as the block's. A third-party torch.compile(mode="reduce-overhead") region first called inside a block (behind a graph break) was counted too, so going past the shape cap reset the shared tree and its next call failed with "Running CUDAGraph after shutdown". The graphs-on block compile now uses an inductor backend that notes the compile ids it builds; only those count as ours, anything else keeps the pool.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
# Conflicts: # unsloth/models/_block_compile.py [skip ci]
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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.
Problem
With
UNSLOTH_BLOCK_CUDAGRAPHS=1, going past the shape cap turns block graphs off and releases the cudagraph tree pool viareset_cudagraph_trees(), but only when every tree function belongs to a block compile (#15352). Ownership was taken as every tree function created during a graphed block call (ids_to_funcsbefore / after delta in_graphed_call).A third-party
torch.compile(mode="reduce-overhead")function that is first called inside a block (behind a graph break, e.g. through atorch.compiler.disablehelper) registers its tree function during that same call, so it was counted as the block's. Past the cap the release then reset the shared tree, and the next call of that function failed withAssertionError: Running CUDAGraph after shutdown.Change
The graphs-on block compile now uses a subclass of the stock inductor backend (
torch._TorchCompileInductorWrapper, same options) that recordsCompileContext.current_compile_id()for every graph it compiles. A foreign region compiles through its own backend, so its compile ids are never recorded._graphed_callonly counts new tree functions whose compile id the block backend recorded; anything else makes the release verdict "foreign" and the pool is kept, as already happens for regions created before the first block call. The backward tree function carries the forward's compile id, so a block-only tree is still released. If the backend cannot be built, nothing counts as the block's and the pool is kept. The graphs-off copy and runs withoutUNSLOTH_BLOCK_CUDAGRAPHS=1are unchanged.Tests
tests/test_block_cudagraphs_clone.py:test_foreign_function_first_called_inside_a_block_is_not_ours: a mocked tree manager gets a block and a foreign tree function during one_graphed_call; only the block one is ours and the verdict is "foreign". Fails on main.test_block_backend_notes_the_compile_ids_it_builds,test_only_the_graphs_on_compile_gets_the_owning_backend: the backend records the compile id and keeps the block options; only the graphs-on compile gets it.test_graphed_call_records_the_compile_ids_it_createdupdated for the recorded ids.CPU:
test_block_cudagraphs_clone.py,test_block_compile.py,test_block_compile_discovery.py,test_legacy_block_compile_install.py,test_fsdp2_native_block_cudagraphs*_gloo.py: 138 passed, 6 skipped, 1 failed (test_sm_count_is_read_outside_the_traceneeds a CUDA device and fails the same way on main).GPU (RTX PRO 6000 Blackwell, torch 2.14.1+cu130): one decoder layer whose forward calls a
reduce-overheadhelper through atorch.compiler.disableboundary, sequence lengths 40, 48, 56 so the third shape passes the cap of 2:Running CUDAGraph after shutdownat step 8Not covered
torch 2.7 to 2.13 on GPU were not run (the backend class and
CompileContext.current_compile_id()exist across that range). Multi GPU runs were not run.