Skip to content

[Runtime] Add decode CUDA graph hooks for eager logits processing - #40222

Merged
merrymercy merged 2 commits into
sgl-project:mainfrom
mxz297:mxz/decode-cuda-graph-output-hooks
Sep 19, 2026
Merged

merrymercy merged 2 commits into
sgl-project:mainfrom
mxz297:mxz/decode-cuda-graph-output-hooks

Conversation

@mxz297

@mxz297 mxz297 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Runners that capture the transformer body and compute logits after replay need to retain every token-row hidden state across graph buckets. Request-count output sizing can truncate those states, and reconstructing LogitsProcessorOutput drops fields produced by the eager tail.

Modifications

  • Add explicit graph-output row and capacity hooks, and use them in the breakable backend when allocating and slicing shared output storage.
  • Allow runners to override shared logits-buffer capacity and process graph outputs eagerly after replay, within the existing device timer.
  • Preserve extra LogitsProcessorOutput fields with dataclasses.replace when slicing padded logits and hidden states.
  • Add ForwardBatch.defer_logits_to_eager for model implementations that support transformer-only capture. Copy it into TBO child batches and test inheritance of both False and True; otherwise the TBO completeness guard rejects even the default value.

The hooks default to current sizing and pass-through behavior. This ports all six shared-runtime files from the source change and adds the TBO inheritance fix and regression subtest from #40226. Current upstream speculative pipeline-output slicing is preserved. Model-specific consumers and verification kernels are outside this port.

Accuracy Tests

46 tests and 16 subtests passed at 75b46430c5. These cover the complete batch-overlap unit directory, decode profiling, shared-read fences, hidden-state capture, backend selection, and adaptive logits-buffer sizing. Before the fix, all four marker tests reproduced the missing defer_logits_to_eager error. The previous head also failed both the marker and dummy-token-mask tests in base CI for the same reason.

Earlier local CUDA smoke check passed at 066f3ef21e (not rerun for the TBO-only follow-up): real breakable-graph capture/replay with 1- and 4-request buckets, three token rows per request, and a padded 3-request replay. Checked shared output storage across capture sizes, eager-tail timing, preservation of subclass and auxiliary output fields, default hook behavior, and shared logits-buffer capacity. The smoke harness was run locally and is not added to CI.

Validation commands

Using an existing Python environment with the checkout's python/ directory on PYTHONPATH:

CUDA_VISIBLE_DEVICES=4 uv run --no-project --active pytest -q -ra --disable-warnings \
  test/registered/unit/batch_overlap \
  test/registered/unit/model_executor/test_model_runner_decode_rows.py \
  test/registered/unit/model_executor/runner/test_decode_cuda_graph_runner.py \
  test/registered/unit/model_executor/runner/test_decode_cuda_graph_shared_read_fence.py \
  test/registered/unit/model_executor/runner/test_hidden_state_graph_recapture.py \
  test/registered/unit/model_executor/runner_backend/test_backend_resolution.py \
  test/registered/unit/model_executor/runner_backend/test_full_cuda_graph_backend.py

uv run --no-project --active pre-commit run --from-ref main --to-ref HEAD
git diff --check main...HEAD

The unit-test invocation hides GPUs with a non-existent device index. The separate local smoke harness used one CUDA device, with graph deduplication, graph-pool borrowing, and pre-carving disabled.

Speed Tests and Profiling

Full-model accuracy evaluations and performance benchmarks were not run for this port. No throughput or latency improvement is claimed here.

Checklist

  • Upstream pre-commit checks pass.
  • Existing unit tests and a focused CUDA smoke check pass.
  • New extension points are documented in code.
  • Existing subclass/caller compatibility reviewed; current upstream pipeline-output slicing retained.
  • Full-model accuracy and speed benchmarks (not run).

Original commits

  • 7f3a5b86011525df3a954e0d403ddda4f60041db

CI States

Latest PR Test (Base): ❌ Run #35390299130
Latest PR Test (Extra): ❌ Run #35390297779
Latest PR Test (AMD ROCm 10): ❌ Run #35390298003

Allow specialized runners to size shared logits buffers, preserve token-row
outputs in breakable graphs, and process outputs after replay. Preserve
additional LogitsProcessorOutput fields when trimming padded output rows.

Co-authored-by: Xiaozhu Meng <mxz297@gmail.com>
@mxz297

mxz297 commented Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@ZYHowell ZYHowell added the run-ci CI: run the baseline test suite on this PR label Sep 18, 2026
@merrymercy

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

@merrymercy
merrymercy merged commit 111aeed into sgl-project:main Sep 19, 2026
336 of 407 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants