Repository navigation
[Fix] cuda_graph: Wait for in-flight layer loads before breakable replays that capture state reads - #44414
Closed
alphabetc1 wants to merge 1 commit into
Closed
[Fix] cuda_graph: Wait for in-flight layer loads before breakable replays that capture state reads#44414alphabetc1 wants to merge 1 commit into
alphabetc1 wants to merge 1 commit into
Conversation
alphabetc1
requested review from
Fridge003,
HaiShaw,
Qiaolin-Yu,
Ying1123,
hanming-lu,
hebiao064,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann,
yizhang2077 and
yuan-luo
as code owners
October 15, 2026 05:30
Merged
3 tasks done
This was referenced Oct 15, 2026
Closed
alphabetc1
force-pushed
the
fix/bcg-captured-extend-load-wait
branch
from
October 19, 2026 05:46
0838241 to
d7745aa
Compare
Collaborator
Author
|
Closing in favor of #45839, which fixes the same breakable-replay race (captured KDA extend reading state before its layer-wise load lands) while keeping per-layer load/compute overlap, instead of waiting for the whole load before replay as this PR does. |
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.
Motivation
#44220 (merged) makes a Full prefill CUDA graph replay wait for an in-flight HiCache / external-linker layer-wise load, and leaves breakable replays alone because their eager breaks still run the per-layer waits in the pool accessors.
That holds only while every read of loaded state happens at an eager break. Since #41105, a breakable graph captures the Triton KDA extend inside a graph segment instead of breaking at each KDA layer. Its KDA state reads then run inside the replayed segment, where no per-layer wait runs, so a loading batch can read KDA state before that layer's load lands and produce wrong logits silently.
This is reachable with default flags: GLM-5.3-Flash enables breakable prefill graphs by default (#42845), and on Hopper the KDA extend defaults to the Triton kernel (
flashinfer_kda_prefill_defaultpicks FlashInfer only on SM100/SM103). With HiCache on, a host-tier hit then replays the captured KDA extend over an unfinished load. On Blackwell the default FlashInfer KDA prefill is not captured, but--enable-deterministic-inferenceor--linear-attn-prefill-backend tritonbrings the Triton path back.Modifications
AttentionBackend.breakable_graph_reads_captured_state(default False): set when a breakable prefill graph reads layer state inside a captured segment.HybridLinearAttnBackendsets it exactly when it captures the linear extend, the same decision that enables the capture.PrefillCudaGraphRunner: a replay waits for the whole in-flight load first when the backend is Full, or breakable with captured state reads (_replay_waits_for_whole_load, resolved once at init). Every other breakable replay keeps per-layer load/compute overlap, so e.g. Inkling and DeepSeek-V4 under breakable graphs are unchanged.use_captured_forward_metadata_for_breakable_cuda_graphis not reused: DeepSeek-V4 sets it for captured attention metadata while its KV reads still run at eager breaks, so keying on it would drop their overlap for no reason.Accuracy Tests
GLM-5.3-Flash (FP8), 4x GB300, TP4,
--cuda-graph-backend-prefill breakable --linear-attn-prefill-backend triton(log confirms "Breakable prefill CUDA graphs capture the KDAAttnBackend extend"), HiCache L1+L2 with a tight device pool (--max-total-tokens 8192 --max-mamba-cache-size 32) so turns hit the host tier,SGLANG_TEST_HICACHE_H2D_DELAY_CYCLES=50000000. Multi-turn branching workload (9 samples), KL against a cold replay; 24 replays with an in-flight load per run. GLM has no bit-exact oracle and rare single-sample outliers, so medians are compared.SGLANG_DISABLE_KDA_PREFILL_GRAPH_EXTEND=1)The last row measures the same wait through a variant that applies it to every breakable replay. This exact commit, rebased onto main (which now includes #44220), was then measured on 8x B300 (4 GPUs, TP4). GLM-5.3-Flash used bf16 weights, FP8 KV and TRT-LLM DSA, with the same breakable + Triton KDA flags, pools and delay. The same 9-sample harness ran 3 times per arm, each run with 22 prefill-graph replays and 6168 loaded tokens. Samples 1-8 move between the same few values in every arm, including the no-delay floor. Only sample 9 separates the arms:
The wiring is checked below.
Default-flag check on 1x H200 (an 8-layer GLM-5.3-Flash with dummy weights, no graph or KDA flags): the log shows
extend=TritonKDAKerneland "Breakable prefill CUDA graphs capture the KDAAttnBackend extend", with breakable replays carrying an in-flight HiCache load. Dummy weights are too flat to show the KL effect, so the KL table above uses real weights with the Triton path forced. On this PR's tree the same server logswaits_for_whole_load=TrueforHybridLinearAttnBackend, so those replays now wait.Tests
test_prefill_cuda_graph_runner.py::TestPrefillCudaGraphRunnerLayerLoads::test_breakable_replay_waits_when_it_captures_state_reads: Full waits, breakable without captured state reads does not, breakable with captured state reads does. Negative control: ignoring the flag fails it (False != True).test_prefill_cuda_graph_runner.py: 19 passed.Checklist
CI States
Latest PR Test (Base): ❌ Missing
run-cilabel -- add it to run CI tests.Latest PR Test (Extra): ❌ Blocked --
run-ciis required first.Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.