Skip to content

perf(glm5next): gather full C4 cache for DCP prefill - #517

Merged
lukealonso merged 7 commits into
fix/b12x-memory-profiling-warmup-lifetimefrom
perf/glm5next-b12x-dcp-full-ckv
Aug 31, 2026
Merged

perf(glm5next): gather full C4 cache for DCP prefill#517
lukealonso merged 7 commits into
fix/b12x-memory-profiling-warmup-lifetimefrom
perf/glm5next-b12x-dcp-full-ckv

Conversation

@voipmonitor

@voipmonitor voipmonitor commented Aug 29, 2026

Copy link
Copy Markdown

Purpose

Give GLM5Next B12X C4 prefill a global compressed-key/value view under decode
context parallelism. Each rank normally selects candidates from only its local
KV shard, which reduces selector quality and leaves most C4 candidates
invisible during prefill.

Resulting behavior

When VLLM_B12X_MLA_CKV_GATHER=1, an eligible pure-prefill batch:

  • packs each DCP rank's visible FP8 compressed-KV page-tail records;
  • gathers the records synchronously into caller-owned workspace;
  • applies the B12X C4 selector to the rank-major full cache;
  • remaps selected indices to the gathered cache layout;
  • supplies global causal lengths and each rank's local query heads; and
  • supports multiple requests, chunked prefill, and prefix-cache hits.

Eligibility requires num_decode_tokens == 0. Decode and MTP verification
batches cannot enter this path. The implementation uses one synchronous
workspace slot and does not introduce side-stream prefetch.

Cache page geometry is finalized before memory profiling. B12X plans, packed
capacity, gather workspace, persistent-pool reservation, and cache binding use
the same immutable physical page size. Full-CKV prefill executes eagerly;
CUDA-graph profiling uses ordinary DCP attention, while decode and eligible
serving paths retain PIECEWISE and FULL graphs.

The environment-variable source default is disabled. No B12X source or kernel
is changed.

Review-stack boundary

This pull request is based on #516, which supplies startup-only B12X profiling
warmup safety. Pull request #516 is based on #515, which supplies CUDA-graph
profiling resource lifetime. The lower review stack also contains #531 and
#532, which reuse immutable B12X C4 plans and parallelize packed C4 pool writes.
The head tree for this pull request is
265353fc996f5a788aaac069f58f9484e3d7be41.

The diff in this pull request contains only the GLM5Next synchronous full-CKV
operation contract, immutable page geometry, cache-binding lifecycle, and
associated tests.

Duplicate-work check

Searches covered GLM5Next, B12X, DCP, CKV gathering, and CKV prefetch in both
local-inference-lab/vllm and vllm-project/vllm.

Verified review findings from #488

Luke Alonso's #488 review notes were checked against
e72447af820d4f996b33710cc0232a3144460722 and minimal reproducers:

  1. A provisional 64-token page reserves 131,200 local records for DCP4, 32
    sequences, interleave 4, and a 524,288-token CKV limit. Binding the
    2,304-token hybrid page requires 131,328 records, leaving a depth-1 lane
    608,256 bytes short. This implementation finalizes the page before memory
    profiling and rejects post-allocation geometry changes.
  2. VLLM_B12X_MLA_SPEC_EXTEND_AS_DECODE defaults to disabled even though a
    routing test passes an enabled flag directly. Full-CKV eligibility therefore
    derives from the batch's decode-token count and excludes MTP verification.
  3. perf(glm5next): complete B12X CKV support for DCP and MTP #488 defaults to depth-1 prefetch without a demonstrated GLM5Next gain over
    synchronous gathering and allocates approximately 1.2 GiB for the second
    lane. This implementation remains synchronous. Side-stream prefetch requires
    independent profiling and qualification.

Source provenance

Substantially transferred commits retain their Git authors:

  • Koushik Dutta authored the synchronous full-C4-cache gathering derived from
    [gg-rebased] perf(dcp): split prefill queries and gather selected CKV #120 commit d98b9b245c1430e02090e06edc4a836018f1e727.
  • Jack Zampolin authored parallel-configuration scratch sizing, local query
    selection, and GLM5Next packed page-tail fixtures.
  • Martin Vit authored immutable pre-profile geometry, selector-metadata
    fixtures, and decode-token eligibility.

Validation

Hardware and model conditions: four NVIDIA RTX PRO 6000 Blackwell Workstation
Edition GPUs, physical device IDs 4, 5, 6, and 7; TP4; DCP4; FP8 target KV;
max_num_batched_tokens=4096; GLM-5.3-Flash-NVFP4 revision
520de24eabf507659eaef7c70f14fd584527facc; composed vLLM head
3609a3db498698314bdc44920cad9f2d25796eb9; and B12X head
0a73e97fe4dd67500999b0152d8a3c41ba238715.

Correctness:

  • Six greedy cases produced identical text and token sequences against
    ordinary DCP and perf(glm5next): complete B12X CKV support for DCP and MTP #488 depth 0: 256 tokens, chunked 32,768 tokens, two
    concurrent 32,768-token requests, and two 32,768-token requests sharing a
    30,720-token prefix.
  • Maximum selected-token log-probability delta was 0.019841991 against ordinary
    DCP and 0.0041269148 against perf(glm5next): complete B12X CKV support for DCP and MTP #488 depth 0.
  • CKV, selector, cache-binding, and CUDA-graph tests: 90 passed, 302 skipped,
    with no implementation failure.
  • GPU-worker page-geometry ordering: 3 passed.
  • Ruff check, Ruff format check, and git diff --check: passed.

Performance used llm-decode-bench 0.4.30, concurrency 1, its 32k standalone
prefill workload with 32,320 measured prompt tokens, one output token, unique
cold-prefix requests, and a 30-second client measurement window:

Configuration Prompt throughput samples Median
Synchronous full-CKV 9,602, 9,598, 9,567 tok/s 9,598 tok/s
Ordinary DCP on the same tree 8,731, 8,758, 8,755 tok/s 8,755 tok/s

The adjacent median gain is 9.63%. The measured gain applies to non-speculative
serving at the declared 4,096-token scheduler batch limit; it is not a claim
for a different batch limit or speculative mode.

An earlier source-isolation qualification compared this implementation with
#488 depth 0 under the same model, B12X revision, hardware, and 4,096-token
scheduler batch limit. Their median difference was 0.15%, which establishes
performance parity with #488 depth 0 rather than a speedup over #488.

AI assistance disclosure

OpenAI Codex assisted with source analysis, implementation, tests, runtime
qualification, and pull-request preparation. A human maintainer must review
every changed line and understand and defend the behavior before merge.

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 48 minutes.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 4e71fff8-8314-4ee7-8f79-4787a2a17e77

📥 Commits

Reviewing files that changed from the base of the PR and between db0f144 and 92d807a.

📒 Files selected for processing (10)
  • tests/v1/attention/test_b12x_sparse_mla_api.py
  • tests/v1/attention/test_mla_backends.py
  • tests/v1/worker/test_workspace.py
  • vllm/envs.py
  • vllm/model_executor/layers/attention/mla_attention.py
  • vllm/model_executor/layers/attention_layer_base.py
  • vllm/platforms/interface.py
  • vllm/v1/attention/backend.py
  • vllm/v1/attention/backends/mla/b12x_mla_sparse.py
  • vllm/v1/worker/workspace.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@voipmonitor
voipmonitor marked this pull request as ready for review August 29, 2026 17:02
@voipmonitor

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 29, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

koush and others added 7 commits August 30, 2026 09:33
Pure-prefill DCP batches pack each rank-local CKV shard, gather the full cache in rank-major order, remap global C4 selections, and execute B12X extend attention with local query heads and global causal lengths. Decode, speculative verification, CUDA-graph capture, and ineligible batches retain the ordinary DCP attention path.

The implementation excludes indexer query splitting and cross-layer asynchronous prefetch. Those mechanisms have independent topology and ownership contracts and are not required for synchronous full-CKV prefill.

(cherry picked from commit d98b9b2)

Co-authored-by: Jack Zampolin <jack.zampolin@gmail.com>

Co-authored-by: opencode <opencode@anthropic.ai>
(cherry picked from commit ddfa3d558079fbba8d5b874e1c1c269ec0506ce2)

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Co-authored-by: OpenAI Codex <noreply@openai.com>
(cherry picked from commit d71b3ca)
(cherry picked from commit 208f574034cfc38076e9b69007b78fad64a7927f)
(cherry picked from commit 6bfb5fc7c9fb78c12bd88dcd361c3b1e881dd45f)

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Co-Authored-By: Claude opus <noreply@anthropic.com>
(cherry picked from commit ea338d7)
(cherry picked from commit 0cb13562a9763fc349c2d3761bea315aa0d00e4d)
(cherry picked from commit c17abaeb08b4b7893a396585c19ea6845afbbd94)

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Hybrid cache alignment applies the resolved page size to loaded attention implementations before device-memory profiling. B12X rebuilds its plans from that immutable geometry and reserves every workspace execution slot, so the KV-cache budget includes full-CKV gather storage.

KV-cache binding validates the finalized page size and fails closed when full-CKV gathering reaches binding without pre-profile finalization. The 64-to-2304-token page transition and multi-slot workspace reservation have regression coverage.

Validation: uvx ruff check and format on changed files; 11 targeted pytest cases passed in the source-compatible runtime image.
(cherry picked from commit 65fc70fe002c5318b4ea9ccf998353368fe2cb4a)
(cherry picked from commit 87b9d1195a133a9aa328f989c63549fbb34b1031)

Signed-off-by: Martin Vit <martin@voipmonitor.org>
Co-authored-by: OpenAI Codex <noreply@openai.com>
(cherry picked from commit 68eb9de)
(cherry picked from commit 710fe52ba4373f2e7b52efdfc821b7726b302b00)
Selector-state fixture stubs expose prefill, decode-token, and speculative-decode fields required by the sparse-MLA metadata builder. The bare builder disables full-CKV eligibility so selector-state staging tests remain isolated from DCP cache-gather behavior.

(cherry picked from commit 702004ec703c2f36237b160fa2cb9c2cb01754aa)
Enable the synchronous full-cache gather only when B12X metadata reports zero decode tokens. This excludes ordinary and speculative decode without depending on a metadata field that the sparse MLA builder does not define, including during CUDA graph memory profiling.

(cherry picked from commit eeae70219b9f86889108afa734f6de1bbd42d99e)

Signed-off-by: Martin Vit <martin@voipmonitor.org>
@voipmonitor
voipmonitor force-pushed the fix/b12x-memory-profiling-warmup-lifetime branch from 089ce1e to db0f144 Compare August 30, 2026 14:18
@voipmonitor
voipmonitor requested a review from mgoin as a code owner August 30, 2026 14:18
@voipmonitor
voipmonitor force-pushed the perf/glm5next-b12x-dcp-full-ckv branch from 675ff25 to 92d807a Compare August 30, 2026 14:18
@voipmonitor

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 30, 2026

Copy link
Copy Markdown
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants