Skip to content

[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
sgl-project:mainfrom
alphabetc1:fix/bcg-captured-extend-load-wait
Closed

alphabetc1 wants to merge 1 commit into
sgl-project:mainfrom
alphabetc1:fix/bcg-captured-extend-load-wait

Conversation

@alphabetc1

@alphabetc1 alphabetc1 commented Oct 15, 2026 •

Copy link
Copy Markdown
Collaborator

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_default picks 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-inference or --linear-attn-prefill-backend triton brings 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. HybridLinearAttnBackend sets 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.
  • The existing use_captured_forward_metadata_for_breakable_cuda_graph is 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.

Tree H2D delay KDA capture median KL
#44220 head no on 1.9e-4 (floor)
#44220 head (2 runs) yes on 3.5e-3 / 4.1e-3
#44220 head yes off (SGLANG_DISABLE_KDA_PREFILL_GRAPH_EXTEND=1) 1.2e-4
every breakable replay waits for the whole load (the wait this PR applies in this configuration) yes on 1.4e-4

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:

Tree H2D delay sample-9 KL (3 runs)
main no 4.1e-4 / 1.1e-3 / 3.7e-3 (floor)
main yes 4.5e-2 / 4.5e-2 / 1.5e-2
this PR yes 8.3e-4 / 4.1e-4 / 9.6e-4

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=TritonKDAKernel and "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 logs waits_for_whole_load=True for HybridLinearAttnBackend, 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

  • Format your code according to the Code Formatting with Pre-Commit.
  • Add unit tests.
  • Provide accuracy evaluation results.

CI States

Latest PR Test (Base): ❌ Missing run-ci label -- add it to run CI tests.
Latest PR Test (Extra): ❌ Blocked -- run-ci is required first.
Latest PR Test (AMD ROCm 10): ➖ No AMD PR run found for this commit.

@alphabetc1
alphabetc1 force-pushed the fix/bcg-captured-extend-load-wait branch from 0838241 to d7745aa Compare October 19, 2026 05:46
@alphabetc1

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant