Configure query context parallelism on the prefill role
Query context parallelism (QCP) splits every extend forward's rows over the attention TP group of a prefill engine in prefill/decode disaggregation (PD).
Shard prefill query rows
--query-context-parallel-size N splits every extend forward's rows request by request in zigzag: every request's new rows are cut into 2N near-equal segments and rank r computes segments r and 2N - 1 - r of every request, against the full KV history of the request. For sufficiently long requests, each rank holds an early and a late part, balancing causal attention and letting the ranks compute each history group in parallel. Short requests can leave some ranks empty; they still participate in all collectives. It is a layout of the Mapping (mapping.attn.qcp_size / qcp_rank / qcp_group), not a mode: the scheduler plans the same chunk on every rank, cache allocation and the P->D transfer see page ownership only, and --chunked-prefill-size keeps counting the whole chunk, so size it as N x rows-per-rank.
For each layer, the rows a rank holds are its shard. Attention needs no gather or reduce around the shard: its weights are head-replicated by default, or its own head-TP tail returns the shard's rows. For more information, see Head TP over the query shards. The rest of the per-layer data flow uses the shard as follows:
- The dense and MoE legs run the all-gather / reduce-scatter path over the shard's row table.
- The KV write all-gathers each rank's rotated latent to the whole span before the owner-masked store.
- The sparse DSA indexer and attention score the gathered history of each request group.
- The model exit gathers only the sampled rows (one per request) before the LM head.
Every QCP collective is data movement, so a row's bits do not depend on which rank computes it (see the numerics design).
DSA packs whole request histories into contiguous groups within its reserved history workspace. It keeps the minimum group count that fits the workspace, then minimizes the largest group's history row count. Request order and query ownership stay unchanged. This reduces the peak rows presented to the indexer without adding history gathers; latency still depends on query distribution and the selected kernels. A request whose history exceeds the workspace is rejected.
Check requirements
QCP requires all of the following configuration constraints:
--disaggregation-mode prefillwith--kv-parallel-size N. The query shard is a layout over the sharded pages; the engine keeps the Host KVStore, the retraction snapshot pool and L3 storage, as every KVP engine does, but not yet--kvstore-write-policy write_back.N == --attn-tp-size, attention DP 1, and no--enable-mixed-batch.- GPU DSA attention with a bf16 KV cache, checked where the attention config is built.
--dense-tp-sizeand the MoE TP×EP group each 1 orN. Attention returns complete rows, so the drafter's replicated decode rows are never scattered and a narrower group would have nothing to gather.
The prefill stays eager: the GPU DSA backend declares no prefill graph under a shard, so the launch need not say --disable-prefill-graph. The drafter's extend step is sharded like the target's; its decode steps run every row on every rank.
Head TP over the query shards
Without --attn-head-tp-size, the shard group's ranks hold different rows and every rank holds every head of q_b_proj, kv_b_proj, and o_proj (the mapping resolves attn.head_tp_size to 1). --attn-head-tp-size N shards those three projections by heads over the shard group instead. This is the same head group the decode-side layout builds over DP ranks, here == qcp_group, with the same exchange around core attention:
- The ranks token-all-gather the normalized q latent to the span.
q_b_projruns this rank'sH / Nheads of every row.- The heads-to-tokens all-to-all returns the shard's rows with every head.
- The prologue rotates them on the shard's own positions and writes the gathered KV as every QCP forward does.
- The sparse core attends the gathered history with every head.
- The tokens-to-heads all-to-all hands the head slice of every row to the local
w_vc. - The
o_projtail returns the shard's rows through row-parallelo_projplus a token reduce-scatter. Under--tp-batch-invariant attn, it instead uses column-parallelo_projwith an all-gather of the heads in front and an all-to-all back.
The exchange counts are the shard plan's, so there is no host sync. A rank whose shard is empty joins every leg.
The drafter's decode steps hold every row on every rank, exchange nothing, attend this rank's head slice (the DCP arm over the KVP pages -- the page-sharded KV of --kv-parallel-size -- as attention TP runs it), and all-reduce the o_proj partials (all-gather the hidden shards under --tp-batch-invariant attn).
The expanded (dense MLA) prefill still refuses head TP; the layout serves the absorbed sparse prefill only. The decode-only rules of the DP layout (role, decode-shaped autotune) do not apply: the prefill role's requirements and --attn-head-tp-size == --query-context-parallel-size gate it.
Reduce attention weight memory
The head-shardable weights of one attention instance go from the whole matrices to 1 / N of them per rank. For a model with hidden 8192, 64 heads, q_lora 1536, kv_lora 512, qk 192 and v 128 that is q_b_proj + kv_b_proj + o_proj ≈ 94M parameters = 189 MB (bf16) per instance down to ≈ 24 MB per rank at N = 8. A five-layer pipeline stage of a model with two attention instances per layer saves ≈ 1.7 GB per rank, which the KV cache takes.
Preserve numerics
With row-parallel o_proj the shard group computes the same per-rank head partials the plain TP8 prefill engine does and reduce-scatters them where TP8 all-reduces. Under --numerics rl-bitwise both are the rank-ordered fold, so the two engines sum o_proj bitwise alike, and so do the QCP engine's own drafter decode steps (replicated rows, all-reduced). With --tp-batch-invariant attn there is no cross-rank sum in o_proj, and QCP is bitwise the TP1 / head-replicated form the decode engine's batch-invariant layout computes. For more information, see "Layout invariance of query context parallelism" in the numerics design.
Launch the eight-GPU prefill preset
This preset enables head TP and the batch-invariant o_proj on an eight-GPU prefill engine. Confirm all QCP requirements before launch. --tp-batch-invariant attn needs an unquantized o_proj, as on the decode side.
Replace
<dsa-model>with your DSA model ID or local path, and then start the prefill engine:bashtokenspeed serve --headless <dsa-model> \ --disaggregation-mode prefill \ --attn-tp-size 8 --dense-tp-size 1 --enable-expert-parallel \ --kv-parallel-size 8 --query-context-parallel-size 8 \ --attn-head-tp-size 8 --tp-batch-invariant attn \ --chunked-prefill-size 16384Validate the parallel deployment before sending benchmark traffic. Confirm that every expected rank runs on its assigned GPU, readiness through the serving frontend returns HTTP
200 OK, and the validation prompt returns4.
Drop --attn-head-tp-size 8 --tp-batch-invariant attn for the head-replicated layout (the same bits, 189 MB more attention weight per instance per rank), or --tp-batch-invariant attn alone for TP8's head partials, summed in the fold's order.
A model supports the layout by slicing its rows by ctx.query_shard and, for head TP, threading the attention module's head-TP hooks around its sparse core (see "Query context parallelism" in the unified path design). Every other model refuses it at construction.