Configure split parallelism
Use split parallelism when attention, dense, and mixture-of-experts (MoE) layers need different process groups. For one shared tensor-parallel (TP) group, start with tensor parallelism instead.
Prerequisites
Determine the total worker count, the worker count per node, and the TP size for each layer family. Replace <model> with your model ID or local path.
Start with split TP sizes
Start the server with your total world size and the attention, dense, and MoE TP sizes. This example uses eight workers and TP size 4 for every layer family. Replace
<model>with your model ID or local path, and replace the example sizes with your values:bashtokenspeed serve <model> \ --world-size 8 \ --attn-tp-size 4 \ --dense-tp-size 4 \ --moe-tp-size 4Validate the parallel deployment before sending benchmark traffic. Confirm that the worker count matches
--world-size, readiness returns HTTP200 OK, and the validation prompt returns4.
Select the layout controls
The following table describes the process-count and layer-layout controls:
| Parameter | Use |
|---|---|
--world-size | Total worker processes across all nodes. |
--nprocs-per-node | Worker processes launched on each node. |
--attn-tp-size | Attention tensor parallel size. |
--dense-tp-size | Dense layer tensor parallel size. Defaults to the attention TP width: the full world without DP attention, one replica with it. |
--moe-tp-size | MoE layer tensor parallel size. |
--data-parallel-size | Replicated data-parallel groups. |
--kv-parallel-size | KV parallelism: shard the full-history KV pages over a consecutive subgroup of attention TP on an aggregated or PD engine (see KV parallelism). |
--decode-context-parallel-size | Decode context parallelism in aggregated or PD decode engines; required with and equal to --kv-parallel-size there. |
--query-context-parallel-size | Query context parallelism: the prefill role's query-row sharding over the sharded pages; equal to --kv-parallel-size and --attn-tp-size (see Query context parallelism). |
--mm-encoder-tp-mode | weights (default), or TP1 whole-item DP within each attention TP group (data). |
--enable-expert-parallel | Expert parallelism across the selected world size. |
--expert-parallel-size | Explicit expert parallel size. |
For the complete server option reference, see Parallelism server parameters.
Kimi-K3 TP8 deployments must combine --tensor-parallel-size 8 with --mm-encoder-tp-mode data. This keeps the text model at TP8 while running the wide-QKV MoonViT encoder at TP1 with whole-item DP8.
Decode-side TP layouts under attention DP
An MLA decode engine runs attention at TP1 with DP across the world: the per-token latent KV cannot shard by heads, so every rank keeps its own KV. That layout replicates every non-MoE weight on every rank: the MLA head projections (q_b_proj, kv_b_proj, o_proj), the dense MLPs, and the LM head. On a large model that is tens of GB per rank that could hold KV instead. Three knobs shard those weights over contiguous groups of DP ranks (one node, typically) while attention and the KV stay TP1/DP.
The following table describes the weight-sharding controls and the batch-invariant numerics option:
| Parameter | Use |
|---|---|
--attn-head-tp-size W | Shard q_b_proj, kv_b_proj, and o_proj by heads over W contiguous ranks that hold different rows. Over DP ranks: requires attention TP 1, attention DP, W dividing the stage world, num_heads % W == 0, and a decode engine (--disaggregation-mode decode). Over the query shards of a prefill engine: W equal to --query-context-parallel-size (see Query context parallelism). |
--lm-head-tp-size W | Vocab-shard the LM head over W contiguous ranks. Under attention DP the default is 1 (replicated); a wider group gathers distinct DP groups' rows before the logits GEMM and transposes the vocabulary shards back. Attention TP greater than one is supported; LM-head and attention TP widths must tile each other. Without attention DP it must equal the attention TP size. A model with tied word embeddings keeps its head on the embedding's attention TP group and refuses any other width. |
--dense-tp-size W | Already shards the dense MLPs over W ranks (token all-gather in, token reduce-scatter out). |
--tp-batch-invariant {none,attn,attn+dense} | Make the sharded o_proj (attn) and dense down_proj (attn+dense) column-parallel on hidden so no cross-rank sum remains outside MoE; see batch-invariant numerics. |
Trace the attention head exchange
--attn-head-tp-size is the one that changes the attention data flow. With W ranks holding T_full decode rows together and this rank owning T_own of them, each attention layer runs:
- token all-gather of the normalized q latent:
[T_own, q_lora]to[T_full, q_lora]; q_b_projand the absorption on this rank'sH / Wheads:[T_full, H / W, kv_lora + rope];- all-to-all, heads to tokens:
[T_own, H, kv_lora + rope]-- every head of this rank's own tokens; - the attention prologue (RoPE, KV write) and core attention on this rank's own KV, with the full head count;
- all-to-all, tokens to heads:
[T_full, H / W, kv_lora]; - the value projection with the local
w_vc:[T_full, H / W * v]; - the
o_projtail back to[T_own, hidden]: row-parallelo_projand a token reduce-scatter of the head partials, or, under--tp-batch-invariant attn, an all-gather of the heads, the column-parallelo_proj([T_full, hidden / W]) and an all-to-all back to this rank's rows.
The head exchange precedes the prologue, so the prologue sees one row count for the query, the latent and the write slots (RoPE commutes with the head permutation). The KV write and any sparse-attention indexer stay as they are.
The head group's ranks all take part in every leg, including a DP rank with no rows this step: it still owns a head shard of the group's tokens. That participation lives in the attention module alone -- every decoder layer calls its attention on an idle forward too, with its empty rows, and the attention joins the exchanges or returns at once depending on the layout -- so no layer branches on the layout (the NextN and Eagle3 drafters' layers and LongCat's two-attention layer included). A head group whose ranks are all idle moves nothing and skips its collectives together.
The exchange counts come from the gathered per-rank token tables, so there is no device sync: the legs up to core attention move the forward's input rows, the legs after it the rows a narrowing draft step reported as its collective sizing (one live row per request), and an idle rank sizes by the same tables. Decode CUDA graphs pad every DP rank to the same batch.
Restrict the layout to decode rows
Decode rows only. An expanded prefill needs every head's K and V for the cached prefix. Under head TP each rank holds kv_b_proj for its H / W heads and the latent cache for its own requests only, so no rank can expand the other heads of its prefix, and no other rank holds that prefix to expand it for it: the full-head K/V of a prefill is not available on the layout. TokenSpeed therefore refuses the layout over DP ranks outside --disaggregation-mode decode (head TP over the query shards of a prefill engine serves its extend rows through the absorbed sparse prefill instead; see head TP over the query shards), and the decode engine keeps every extend-shaped forward off its path:
- startup tunes on a decode step instead of the usual extend-shaped dummy forward, and the prefill CUDA graph (which records extend forwards) is turned off (
--disable-prefill-graphis set, with a log line); - a decode node runs no prefill of its own in any case: a request a capacity retraction suspends is imaged to Host and copied back by a restore (see sections 2 and 4 of the scheduler design), never recomputed, so the layout needs no admission rule and no generation cap -- any
max_new_tokensis admitted, as on every other engine.
A prefill row reaching the attention is then an invariant violation and raises, not a configuration the operator can hit.
Shard the LM head
--lm-head-tp-size under attention DP gathers distinct DP groups' logits rows, runs the vocab-shard GEMM and transposes the shards back to each rank's own rows ([T_own, V]), so sampling and logprobs downstream see the same full-vocab rows as a replicated head. With attention TP greater than one, only one peer writes each DP slot into a zeroed hidden-state buffer, which is all-reduced across the LM-head group. The vocabulary shards are gathered and each attention TP peer reads its DP slot. This avoids multiplying the LM-head GEMM rows by attention TP. LM-head and attention TP widths must tile each other. For example, DP4/TP2 supports an explicit LM-head TP8 while its default stays replicated. A shared MTP head uses the same row layout. When the LM-head group stays within a single attention TP group (including when LM-head TP equals attention TP), its peers already hold identical hidden states, so the input row exchange is skipped. The output still gathers the vocabulary unless the consumer requests greedy token IDs.
For greedy heads, eligible cross-DP layouts reduce each row's vocabulary maximum and global token ID before selecting the owning DP rows. They use fused distributed argmax with alternating slot bands when supported, and otherwise the packed-key argmax collective, instead of gathering full logits. The alternating bands allow consecutive target/draft calls without an extra group barrier; calls sharing a state must still be ordered across streams. The greedy DSpark draft walk runs each Markov position (bias, add, and argmax) as one launch that exchanges candidates through the same slots and band order. Returned logits remain vocabulary-sharded and are not a full distribution. Sampled draft distributions and consumers requiring full logits keep the vocabulary exchange; padded vocabularies, softcapping, and other argmax eligibility limits also retain the full-logit fallback.
On the decode path the row counts come from the per-rank token tables (every rank's logits rows are its decode tokens, or the live rows a narrowing draft step reported), so the step has no host sync. The shapes without a table -- a prefill's one row per request or its logprob rows, a MIXED round, a model selecting its own logits rows -- exchange the counts. A drafter sharing the target's head must build its own head on the same layout (the NextN, Eagle3-MLA and Llama-Eagle3 drafters do; TokenSpeed refuses the others with a clear error). It cannot combine with --dp-sampling, and admission refuses a request asking for prompt logprobs (logprob_start_len): that path pushes the prompt rows through the LM head in per-request chunks, a per-rank number of row exchanges the group cannot agree on.
LM-head vocabulary gathering uses a separate communication buffer sized for sampling and speculative verification rows, rather than the attention prefill chunk. With attention DP, its capacity covers the global request limit times the number of speculative verification tokens (at least 128 rows). Larger batches, including prompt-logprob batches, fall back to NCCL without growing the persistent multicast buffer.
Preserve batch-invariant numerics
--tp-batch-invariant replaces the two reduce-scatters of these layouts (after o_proj, after the dense down_proj) with column-parallel GEMMs on hidden: the ranks all-gather the reduction dimension (heads, intermediate channels), every rank computes its hidden shard of every token with full K, and an all-to-all returns the rows. Every collective is then a pure permutation of bytes, so the result is bitwise the full-K GEMM a TP1 or replicated layer computes -- the point when a prefill engine with such a layer must agree with the decode engine. It moves about the bytes of the reduce-scatter it replaces and needs unquantized o_proj / down_proj. attn requires head TP, and attn+dense also requires a dense TP group wider than attention TP (never under query context parallelism, whose dense group is 1 or the attention TP width).
Launch the 128-way DP MLA decode preset
The decode preset for a 128-way DP MLA model reuses one node-local group of 8 three times. Replace <model> with your model ID or local path, and supply the remaining server arguments represented by ...:
tokenspeed serve --headless <model> \
--world-size 128 --nprocs-per-node 8 --attn-tp-size 1 --data-parallel-size 128 \
--attn-head-tp-size 8 --dense-tp-size 8 --lm-head-tp-size 8 \
--tp-batch-invariant attn+dense --disaggregation-mode decode ...--tp-batch-invariant attn+dense needs the checkpoint's o_proj and dense down_proj in the loading dtype. A quantized checkpoint qualifies only when its disable_quant_module keeps those modules unquantized (self_attn for o_proj; dense_mlp, or mlps for LongCat, for down_proj); the check runs against the checkpoint's resolved quantization, not only --quantization, and the layers check their own weights once built. Without such an exclusion drop --tp-batch-invariant (the ordered-fold reduce-scatter remains batch-invariant; see the numerics design).
Before benchmarking, validate the parallel deployment and confirm output correctness for the selected layout.
Pin a request to an attention-DP rank
Each attention-DP rank owns a private prefix cache, so multi-turn requests only reuse their cache when every turn lands on the same rank. The data_parallel_rank field of the wire request a frontend submits pins a request to one rank: the frontend dispatches it straight there, bypassing load balancing — overload spill is the router's job. A pin that names no rank fails that request. The engine keeps serving.
Disaggregated prefill and decode requests each honor their own rank pin, since any decode rank finds the prefill rank from the room. The bootstrap_room still identifies the prefill KV source: room % dp_size must match the rank a prefill pin selects, so a frontend pins the prefill rank and mints the room from one decision. Without a pin, a PD request follows the room residue (room % dp_size).
Under ts serve, the engine's attention-DP ranks register with the bundled gateway as one grouped worker, which places each unpinned request on its least-loaded rank itself; the gateway's --dp-aware expansion does not apply to it.
Identify scheduler ranks
Scheduler process names in ps include their parallel ranks, for example tokenspeed::scheduler_tp1_ep3_dp0. tp always identifies the attention TP rank, including tp0 for a single process. Other suffixes appear only when their parallel size exceeds one: ep for MoE expert parallelism, dp and kvp for attention data and KV parallelism, and pp for pipeline parallelism. These are zero-based ranks within their respective groups, not parallel sizes.