Skip to content

[unified-memory] Enable prefill cuda-graph capture - #37418

Merged
ch-wan merged 2 commits into
mainfrom
cheng/um-prefill-cuda-graph
Sep 14, 2026
Merged

ch-wan merged 2 commits into
mainfrom
cheng/um-prefill-cuda-graph

Conversation

@ch-wan

@ch-wan ch-wan commented Sep 1, 2026 •

Copy link
Copy Markdown
Collaborator

Stack 2/3: main → #37506 → #37418 → #37507. Base: #37506.

Enable unified-memory prefill CUDA graphs. Full-prefill FA3/FA4 metadata rebuilds read tables from the current virtual-to-physical mapping and derives SWA write locations from the already translated full-attention write locations. Replay refreshes the existing buffers and clears inactive SWA write slots.

The FULL graph compatibility gate checks the resolved prefill backend, including mixed prefill/decode configurations. Unsupported or unresolved prefill backends fall back to disabled FULL prefill graphs; the decode backend does not disable a supported prefill backend.

Validation on cheng-wan-b200-4gpu: all four Inkling FA4 full-prefill graph tests passed, covering generation, input/output logprob consistency, prefix reuse, and decoding beyond the SWA window. Eight metadata/backend-gate tests plus 12 subtests passed, including relocation between capture and replay with stable buffer addresses. Repository pre-commit checks passed.


CI States

Latest PR Test (Base): ❌ Run #34780139542
Latest PR Test (Extra): ❌ Run #34780139435
Latest PR Test (AMD ROCm 10): ❌ Run #34780139556

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 1, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-13T02:31:28.343182Z b29cb16 New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f34cc91779

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

Comment on lines +277 to +279
backends = set(attention_backends_of(resolved_view(server_args)))
backends.discard(None)
if not backends <= full_cg_backends:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Check only the prefill attention backend

When unified memory uses split attention backends, such as --prefill-attention-backend fa4 --decode-attention-backend triton, attention_backends_of returns both values, so this set comparison disables FULL prefill capture solely because the unrelated decode backend is not FA3/FA4. The metadata capability being guarded belongs only to the prefill backend; inspect the first tuple element so supported mixed-backend configurations retain the requested FULL graph.

Useful? React with 👍 / 👎.

@github-actions github-actions Bot added documentation Improvements or additions to documentation quant LLM Quantization amd dependencies Pull requests that update a dependency file Multi-modal multi-modal language model deepseek hicache Hierarchical Caching for SGLang blackwell SM100/SM120 npu diffusion SGLang Diffusion apple-silicon jit-kernel memory-pool labels Sep 2, 2026
@ch-wan
ch-wan changed the base branch from cheng/um-pd-tri to cheng/um-pd September 2, 2026 01:53
@ch-wan ch-wan added run-ci CI: run the baseline test suite on this PR and removed run-ci CI: run the baseline test suite on this PR labels Sep 2, 2026
ch-wan and others added 2 commits September 13, 2026 20:13
`--enable-unified-memory` + PD disaggregation supported MLA hybrid-Mamba models
only (kimi-linear); the configurator refused every other shape at boot. This
covers the rest: MHA full attention (Qwen3.5, Qwen3-Next), hybrid sliding-window
(gpt-oss), and the tri-pool that is both (Inkling).

The transfer contract generalises for free, which is the load-bearing fact
here. Every unified sub-pool is anchored at BYTE 0 of the same raw buffer and
addressed by its own stride -- they overlap, and the allocator is what separates
them -- so MLA's whole-page-envelope registration (one region,
`raw_ptr + physical_page * page_envelope_bytes`) works verbatim for an MHA
envelope (`2 * layer_num` row-blocks per page) and for an SWA sub-pool with its
own page_bytes. No anchor arithmetic is needed.

What was actually missing sat on the allocator and the wire, and every piece of
it fails SILENTLY rather than loudly:

  * `UnifiedMHATokenToKVPool.get_contiguous_buf_infos` raised, so any non-MLA
    full side was refused. It is the same envelope.
  * `force_flat` on `send_kvcache` / `maybe_send_extra`. Without it the MHA
    branch of `_send_kvcache_generic` halves the single registered region into
    K and V, computes `num_kv_layers = len(src_data_ptrs) // 2 == 0`, and
    transfers NOTHING -- garbage decode, no error. MLA already reached the flat
    branch via `is_mla_backend`.
  * `UnifiedSWATokenToKVPoolAllocator` inherited the IDENTITY
    `translate_kv_indices_for_transfer`, putting VIRTUAL ids on the wire. They
    address real bytes, so the peer gets plausible garbage.
  * The SWA side needs its own transfer translate:
    `translate_loc_from_full_to_swa` returns KERNEL-FACING ids for the read
    path, while the transfer addresses raw page envelopes. Hence
    `translate_swa_indices_for_transfer`, base-defaulted to the read-path
    translate (an identity change for static pools).
  * `set_disagg_move_gate` was missing on the SWA composite and reached only
    two of three members on the tri-pool, so a page could relocate under
    in-flight RDMA.
  * The tri-pool's `UnifiedHybridReqToTokenPool` had no `pre_alloc_size`, so a
    decode node had no rows for preallocated transfers.
  * `page_size > 1` turns on the decode SWA-tail prealloc, whose inherited body
    allocates the swa side independently (`assert is_id_owner`). It cannot be
    ported: the two sides share ONE virtual id space here, which is why
    `set_full_to_swa_mapping` is a no-op on this allocator. The override
    expresses the tail by binding swa for the tail's virtual pages only; an
    unbound page reads as the sink and `free`'s `swa_v2p_page > 0` mask skips
    it -- the same state the window ratchet reaches via `free_swa`.

Also fixes a latent decode-node bug this is the first configuration to reach:
`resolve_decode_retraction_backup` defaults to `host_pool` for any `SWAKVPool`
without recurrent state and sizes it from `kv_cache.size`, which under the
unified pool is a kernel-facing ROW count. gpt-oss-20b reported 85M "tokens"
and tried to allocate 418 GB of host memory per component.

Validated on H200, 1 prefill + 1 decode, mooncake:
  * Qwen3.5-4B: GSM8K(200, 5-shot) 0.870 through PD with unified memory vs
    0.875 for the same pair on the static pools.
  * gpt-oss-20b and Inkling: logprob parity against a non-PD unified reference
    (the new CI cells). GSM8K is not the gate on gpt-oss -- single-server
    unified and static both score 0.570, but PD runs of either span 0.540-0.610.
  * All five unified-PD test classes pass together.

Refreshes the `--enable-unified-memory` help text, which still claimed PD
disaggregation was unsupported.

Co-Authored-By: Claude Opus 5 <[email protected]>
`--enable-unified-memory` disabled prefill capture for EVERY backend, on the
grounds that "the prefill graph runner bypasses the unified virtual->physical
loc rebind". That is not what the runner does: it builds its ForwardBatch from
the InputBuffer registry slot, and `populate_from_forward_batch` fills that slot
from `forward_batch.out_cache_loc` -- already rebound to kernel-facing ids by
`ForwardBatch.init_new` -- before every replay. The read tables are likewise
refilled out-of-graph from the live v2p, so a page moved by compaction since
capture is picked up. The blanket gate cost every unified run its prefill graph,
including the BREAKABLE default nobody asks for by name.

One backend really was broken, for a different reason. The FULL prefill backend
builds its block table in `_init_full_cg_prefill_metadata`, which:

  * copied raw `req_to_token` page ids into the block table -- VIRTUAL ids where
    the kernels want kernel-facing ones. Silent: virtual ids address real pages.
  * re-ran `translate_loc_from_full_to_swa` on `out_cache_loc` for the SWA write
    loc. By then `out_cache_loc` is FULL-side KERNEL-FACING, so the gather runs
    far past the swa v2p table -- a device-side "index out of bounds" assert on
    the first forward. Phase 2 of the write contract
    (`sliding_window_write_loc_for`) is what derives the swa loc from those
    values, exactly as the eager extend branch's `_unified_read` fixup does.

Both are fixed by routing through the translator, writing straight into the
already capture-stable buffers.

The remaining gate is narrow and not about unified memory at all: FULL prefill
capture needs fa3/fa4, the only family implementing that metadata path. Inkling
declares FULL as a MODEL default, indistinguishable at that point from a flag
the user typed, so it warns and falls back rather than refusing to boot.

Validated on H200, all under `--enable-unified-memory`:
  * Inkling with its own default FULL graph over fa4 -- previously a hard boot
    failure. Greedy text and per-token logprobs BIT-IDENTICAL to the same server
    with capture off across 5 prompts (max delta 0.0); the repeated-prefix rerun
    reproduces exactly; a 512-token generation slides past the SWA window;
    24-way concurrent load holds.
  * Qwen3.5-4B, BREAKABLE (default): GSM8K(200, 5-shot) 0.865 / 0 invalid,
    against 0.870 with capture off.
  * gpt-oss-20b, BREAKABLE (default): 0.565 / 0.155 invalid, against 0.570.

Non-unified paths are untouched by construction: the handler early-returns
without the flag, and the FA change sits behind `kv_index_translator.
is_translating`.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang memory-pool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant