Skip to content

Parallelism ​

Use this reference to select attention, dense-layer, MoE, pipeline, and data parallelism, including distributed launch geometry and expert placement.

Use --tensor-parallel-size for simple launches. When attention, dense, and MoE layers need different process groups, use the TokenSpeed-specific split knobs. The following table lists the parallelism and distributed launch parameters:

ParameterPurpose
--tensor-parallel-size, --tpFamiliar alias for setting attention tensor parallel size.
--attn-tp-sizeTensor parallel size for attention.
--kv-parallel-sizeKV parallelism (KVP): shard full-history KV pages (MLA/DSA latent and index-K, DeepSeek V4.1 global KV) cyclically over a consecutive subgroup of attention TP; must divide --attn-tp-size. Each rank then stores one shard of every request's pages, so the KV capacity per GPU grows by that factor and the DSA indexer scores only owned pages. Aggregated and PD decode engines require matching --decode-context-parallel-size. PD sides shard their caches independently (a transfer edge copies only the pages both its prefill rank and decode rank own); the prefill role writes them with or without --query-context-parallel-size. GPU MLA/DSA speculative decoding is supported within each backend's device, dtype, and draft-attention capabilities: the recipe shards the draft group like the target's, FlashMLA verification uses per-query local causal lengths and GPU DSA uses causal Top-K selection; non-causal DSA block drafts remain unsupported. The Host KVStore, retraction snapshot pool, and L3 storage (--kvstore-storage-backend) use the same cyclic owner translation. L3 keys name a payload replica so an allocation may restore on a different owner; startup rejects head-partitioned fields in page-sharded groups. For Device/Host copies, the scheduler allocates every Host block in its Device block's residue class and each rank copies the blocks it owns.
--decode-context-parallel-sizeDecode context parallelism (DCP) in aggregated or PD decode engines: every rank attends the KV pages it owns under --kv-parallel-size and the partials are merged across the KVP group by their log-sum-exp (KV and context-parallel layouts). Requires --disaggregation-mode null (the default) or decode and must equal --kv-parallel-size, which requires it in turn on those roles: a sharded cache has no other decode, so the launch names the compute explicitly. The backends key the DCP path on the mapping's KVP size, which the drafter's decode-shaped steps on a sharded prefill engine take as well. 1 (default) is off.
--attn-head-tp-sizeShard the MLA head projections (q_b_proj, kv_b_proj, o_proj) by heads over this many contiguous ranks that hold different rows; the attention exchanges heads for tokens around its core. Over attention-DP ranks (needs attention TP 1, attention DP, and --disaggregation-mode decode; each rank keeps its own KV) the layout serves decode rows only, so it sets --disable-prefill-graph and tunes on a decode step; it admits any max_new_tokens, because a retracted request resumes by restore rather than by a recovery prefill. Over the query shards of a prefill engine (must equal --query-context-parallel-size) the extend rows run the absorbed sparse prefill through the exchange and none of the decode-only rules apply. Defaults to the ranks holding the same rows: the attention TP size, or 1 (head-replicated) under --query-context-parallel-size. See Decode-side TP layouts under attention DP.
--ple-table-layoutQwen4-Exp PLE vocabulary layout. global_sharded (default) shards one table across the pipeline stage. attn_tp_sharded shards within each attention TP group, replicating across DP. Both support GPU and host storage. With PLE offloading enabled, shared maps one complete host table per node and peer_sharded maps every rank-owned shard on the same node (the whole table group must fit on that node). Both shared layouts read local IDs directly. The PLE hot cache supports single-table addressing and cannot be enabled with peer_sharded.
--lm-head-tp-sizeVocab-shard the LM head over this many contiguous ranks. Under attention DP the default 1 replicates it; 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. Not combinable with --dp-sampling; under attention DP, requests asking for prompt logprobs (logprob_start_len) are refused.
--tp-batch-invariantnone (default), attn, or attn+dense: make the head-sharded o_proj and the dense down_proj column-parallel on hidden (all-gather of the reduction dim, full-K GEMM, all-to-all back to own rows) so no cross-rank sum remains outside MoE and the bits equal a TP1 full-K GEMM. attn needs --attn-head-tp-size > 1; attn+dense also needs a dense TP group wider than attention TP (so not under --query-context-parallel-size, whose dense group is 1 or the attention TP width; only attn applies there). Both require unquantized o_proj; attn+dense accepts unquantized or weight-only block FP8 (w8a16_fp8_block) down_proj. Admission uses the checkpoint's resolved quantization: a quantized checkpoint must exclude self_attn in disable_quant_module; for attn+dense, it must also exclude dense_mlp / mlps unless the resolved method is w8a16_fp8_block.
--head-tp-exchange-max-rowsRows per rank the head-TP Lamport exchanges are prepared for (the absorbed query, the latent attention output, and, under --tp-batch-invariant, the o_proj rows). The symmetric-memory scratch is allocated before CUDA-graph capture; larger forwards fall back to the generic all-to-all. Only used with --attn-head-tp-size > 1. 256 (default).
--query-context-parallel-sizeQuery context parallelism (QCP) on the PD prefill role: shard every extend forward's rows over the attention TP group, each request split into 2N near-equal segments with rank r computing segments r and 2N - 1 - r against the gathered KV history (the KV write, index-K write, sampled rows, and prompt-logprob rows are gathered across the group; the scheduler, cache allocation, and PD transfer are unchanged, and --chunked-prefill-size keeps counting the whole chunk). Requires --disaggregation-mode prefill and must equal both --attn-tp-size and --kv-parallel-size (the shard is a layout over the sharded pages, so it inherits KVP's rules: Host KVStore, snapshot pool, and L3 use the same owner translation); attention DP 1, no --enable-mixed-batch, --dense-tp-size, and the MoE TP×EP group each 1 or the attention TP width; GPU DSA attention with a bf16 KV cache (the gathered write stores native latent rows), checked where the attention config is built. The prefill stays eager—the GPU DSA backend declares no prefill graph under a shard—without --disable-prefill-graph on the launch. The attention weights are head-replicated unless --attn-head-tp-size equals it, which shards them over the shard group. 1 (default) is off.
--dense-tp-sizeTensor parallel size for dense layers. Defaults to the attention TP width: the full world without DP attention, one replica with it.
--moe-tp-sizeTensor parallel size for MoE layers.
--data-parallel-sizeNumber of data-parallel replicas.
--mm-encoder-tp-modeMultimodal encoder parallelism: weights shards encoder weights with attention TP; data uses TP1 whole-item DP and currently requires aggregate serving or the prefill role.
--enable-expert-parallelSet expert parallelism across the selected world size.
--expert-parallel-size, --ep-sizeExplicit expert parallel size.
--pipeline-parallel-sizePipeline stages for prefill chunk pipelining. Requires --disaggregation-mode prefill; forces eager execution; every per-layer parallelism resolves inside one stage's world.
--pp-layer-partitionExplicit per-stage layer counts, front to back ("24,24,24,21"); one entry per stage, summing to the model's layer count. Default: even split with the remainder on the front stages.
--world-sizeTotal worker process count across all nodes.
--nprocs-per-nodeWorker process count per node.
--base-gpu-idFirst visible GPU ordinal used on each node. Default 0.
--gpu-id-stepSpacing between local workers' GPU ordinals. Default 1.
--nnodesNumber of nodes.
--node-rankRank of the current node.
--dist-init-addrDistributed initialization address.
--emulate-rank-zeroRun only global rank 0 of the configured layout on one GPU, with local stand-ins for its collectives. For single-GPU performance work; outputs are not meaningful. See Emulating rank 0 on one GPU.

Expert placement ​

The following table lists the expert placement and rebalancing parameters:

ParameterPurpose
--ep-num-redundant-expertsExtra physical expert slots per MoE layer for replicas of hot experts (P = E + R, must divide over the EP size; needs ep_size > 1). Default 0.
--init-expert-locationtrivial (default). Otherwise the form is decided in order: inline JSON when the value starts with {, a directory of per-rank *.expert-load.pt records (merged), an existing .pt/.json file, else a glob over record files (merged). A logical_count [layers, experts] load record derives the placement with the EPLB algorithm, a physical_to_logical_map [layers, slots] pins one exactly.
--ep-dispatch-algorithmHow routing picks among an expert's replicas; required with a positive --ep-num-redundant-experts, a non-trivial --init-expert-location, --expert-distribution-recorder-mode, or --enable-eplb. static_with_zero_expert for models with zero experts (LongCat), static otherwise; dynamic/dynamic_with_zero_expert/fake draw at random (refused under --numerics rl-bitwise and on replicated-input EP).
--eplb-algorithmauto (default), deepseek, or deepseek_hierarchical.
--expert-distribution-recorder-modestat (the only mode): count the routes to every physical expert so the EXPERT_LOAD profile activity can write each rank's load record when its profile stops and --enable-eplb can rebalance from the counters.
--enable-eplbOnline expert rebalancing: every --eplb-rebalance-num-iterations forwards the sampled routing load is rebalanced with the EPLB algorithm and the expert weights move between slots. Requires --expert-distribution-recorder-mode stat and a static --ep-dispatch-algorithm, both explicit, and ep_size > 1; --ep-num-redundant-experts 0 is allowed (permutation only). RebalanceExpertsReqInput triggers a manual cycle. Under a --numerics envelope it rides the placement-independent slot-order MoE combine the envelope folds in (--moe-combine-order slot).
--eplb-rebalance-num-iterationsForwards between two load snapshots; required with --enable-eplb, > 0.
--eplb-window-sizeForwards sampled per snapshot (1 ≤ W ≤ interval). The first snapshot is taken after W forwards, then one per interval. Defaults to the entire interval.
--[no-]eplb-balance-draftChoose whether to rebalance the draft independently. An explicit choice is required with --enable-eplb and an eligible draft.
--eplb-rebalance-layers-per-chunkMoE layers whose experts move in one scheduling round; 1..num MoE layers, default min(8, target MoE layers). Fewer layers per chunk bound the per-round stall.

These expert-placement parameters apply only to models that opt in to expert placement (LongCat-Flash, DeepSeek-V4.1-Flash with attention TP1 and MegaMoE, Inkling2 for static placements, and Kimi-K3 with attention DP and EP-only MoE, a static dispatch, and no load recording); other models refuse them at startup. For the record → place → route flow and the two dispatch flavors, see static expert placement. For the online variant, see dynamic expert rebalancing.

TokenSpeed documentation