Skip to content

Configure KV parallelism ​

KV parallelism (KVP) shards full-history KV pages to increase KV capacity per GPU. Choose the related compute layout separately for decode and prefill.

Distinguish the context-parallel layouts ​

Three context-parallel terms appear in this project, and they name different things:

  • KVP (KV parallelism) is a storage layout. It deals full-history KV cache pages page-cyclically over a consecutive subgroup of attention TP by virtual block ID. Each rank stores 1/N of every request's pages, so the KV capacity per GPU grows by N. --kv-parallel-size N selects this layout, and mapping.attn.kvp_size / kvp_rank / kvp_group describe it. The cache, scheduler feedback, Host tiers, and PD transfer use the layout to track page ownership, residue classes, owner translation, and sharded page tables.
  • DCP (decode context parallelism) is the decode-side compute over KVP pages. Every rank keeps all of its query heads, attends only to the pages it owns, and merges partial outputs across the KVP group by their log-sum-exp (LSE). --decode-context-parallel-size N selects this layout in aggregated or PD decode engines. These roles require DCP with a matching --kv-parallel-size N because DCP is the only way to decode over a sharded cache. The attention backends' decode algorithms, their kernels, and the LSE-merge code carry the DCP name and key on kvp_size. The drafter's steps on a sharded prefill engine also use this size.
  • QCP (query context parallelism) is the prefill-side compute layout. It shards query rows over the attention TP group against the full, gathered KV history without an LSE merge. --query-context-parallel-size selects this layout on the PD prefill role.

Check cache and storage requirements ​

--kv-parallel-size N must divide --attn-tp-size. The KVP subgroups are aligned runs of N consecutive attention-TP ranks. KVP applies to the full-history groups of MLA/DSA models (latent KV and index-K) and to DeepSeek V4.1's global KV. Groups whose contents every rank reads whole, such as sliding windows and compressor state, stay replicated.

The attention backend decides how it attends to the sharded pages: DCP decode, chunked prefill history, or gathered prefill history. The scheduler plans the same virtual blocks on every rank, and the runtime translates ownership where it reads, writes, or copies them. For the ownership model, see Cache concepts.

An aggregated engine combines the existing sharded-history prefill with DCP decode, without a PD transfer or QCP. In a PD deployment, a prefill engine (with or without a query shard) and a decode engine (with --decode-context-parallel-size) each shard their cache independently. A transfer edge copies only the pages that its prefill rank and decode rank both own.

KVP works with the Host KVStore, the retraction snapshot pool, and L3 storage. The Host KVStore supports the write_through and write_back values of --kvstore-write-policy. write_back works on aggregated, prefill, and decode engines, but requires Host L2, --pipeline-parallel-size 1, --query-context-parallel-size 1, and no L3 storage. L3 reuse requires the same CP layout. For all write_back requirements, see Host L2 and Mooncake Store L3.

Start non-PD MLA serving with KVP ​

For non-PD MLA serving, use a DCP-capable backend. Keep --disaggregation-mode at null and QCP at 1.

  1. Start the server. Replace MODEL with your model ID or local path. This example selects flashmla, eight attention TP ranks, and matching KVP and DCP sizes:

    bash
    ts serve --model MODEL --attention-backend flashmla \
      --attn-tp-size 8 --kv-parallel-size 8 --decode-context-parallel-size 8
  2. Validate the parallel deployment, including rank startup, API readiness, and output correctness, before benchmarking.

With --enable-mixed-batch, a mixed round runs its KVP extend rows and DCP decode rows in one forward. MLA decode remains absorbed; MLA/KDA hybrids shard only MLA history. Ordinary TP with KVP = DCP = 1 is unaffected.

Speculative decoding runs on a sharded cache with the backends whose DCP decode takes a verify window (FlashMLA, CuTe MLA, and GPU DSA); the draft group shards like the target's. A FlashMLA verify under KVP runs one kernel row per query against that query's local causal length, so a width-w window reads each request's owned pages w times instead of once. The full rule set is in the parallelism parameter reference.

Gather chunked-prefill history ​

The chunked prefill of an MLA model reads each prefix chunk's history from its page owners, a window of chunks per all-gather. On SM100 and SM103 GPUs (GB200, GB300), a KVP group of 2, 4, or 8 ranks (on one host, or across hosts over an NVLink fabric) gathers these windows with a fused all-gather kernel instead of a pack copy plus an NCCL all-gather. Each owner stores its rows straight from its cache into every rank's receive slot. The kernel uses NVLink multicast where the group supports it, and otherwise uses one store per peer.

There is no flag. Startup selects the path for the whole group and reserves two receive slots per GPU before sizing the KV cache. Each slot holds one chunk's history capacity (--chunked-prefill-size x --mla-chunk-multiplier rows) from every rank, for a total of 2 x kvp_size x capacity x row bytes. For example, KVP 8 with the defaults (8192 x 4) and an FP8 MLA cache (576-byte rows) reserves 288 MiB.

The group keeps NCCL in the following cases:

  • The GPUs or KVP group size do not meet the preceding requirements.
  • DeepSeek V4.1 gathers its own history.
  • The engine is a PD decode engine.
  • Chunked prefill is disabled.
  • One receive slot would use 2 GiB or more, such as at KVP 8 with an FP8 cache and --chunked-prefill-size 131072.
  • The cache uses --kv-cache-quant-method per_token_head. An FP8 --kv-cache-dtype cache does not by itself disable the fused gather.
  • A configured kernel waits on other ranks inside a kernel that needs the whole GPU. This includes MegaMoE, an all-to-all backend such as DeepEP, fused DP projections, or an MoE backend or solution that the runtime does not list as safe.

A reader whose cache rows differ from the target's, such as rows with another width or dtype, uses NCCL. TokenSpeed ends the fused kernel's waits 30 s before --distributed-timeout-seconds, or at half of that timeout when it is under 90 s.

The group's first rank logs the selected path. Verify that the log contains KVP history group ... gathers through the fused all-gather, or ... keeps its NCCL all-gather: with the reason.

TokenSpeed documentation