Repository navigation
[unified-memory] Enable prefill cuda-graph capture - #37418
Conversation
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. |
There was a problem hiding this comment.
💡 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".
| backends = set(attention_backends_of(resolved_view(server_args))) | ||
| backends.discard(None) | ||
| if not backends <= full_cg_backends: |
There was a problem hiding this comment.
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 👍 / 👎.
f34cc91 to
cc9b186
Compare
`--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]>
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