Skip to content

Configure MoE deployments ​

Choose a parallelism shape and backend for a mixture-of-experts (MoE) model, then apply the model-family and transport constraints for that deployment.

Choose a deployment shape ​

For a large MoE model, choose one of these shapes:

  • Tensor parallelism (TP) only: simplest startup path, often best for smaller MoE checkpoints.
  • TP + expert parallelism (EP): tensor parallelism within a replica, expert parallelism across ranks.
  • Data parallelism (DP) + EP: multiple replicated decode groups with experts distributed inside each group.

Start with the recipe closest to your model family, then tune:

  • --tensor-parallel-size or split TP values
  • --enable-expert-parallel
  • --moe-backend
  • --all2all-backend
  • --deepep-mode

Account for backend padding and kernel selection ​

With --moe-backend flashinfer_trtllm, TokenSpeed automatically pads NVFP4 expert shards to a multiple of 64 along their per-rank intermediate dimension. TokenSpeed zero-pads BF16 SiLU/SwiGLU expert shards the same way to a multiple of 64 (128 when it cannot adapt the installed FlashInfer launcher, or when FlashInfer's JIT cannot build the adapted one). For the zero-fill behavior and padding examples, see MoE backend padding details.

On Hopper, MXFP4 routed experts with a SiLU/SwiGLU activation and dense EP (--all2all-backend none) default to the FlashInfer CUTLASS mixed-input kernel (flashinfer_cutlass), which needs the per-rank intermediate size and the hidden size to be multiples of 128. Other widths, SiTU experts, and DeepEP all-to-all layouts keep marlin. --moe-mxfp4-fp8-activation selects its W4A8 variant.

Mixed MoE TP and EP ​

With --all2all-backend none and no attention DP, --ep-size and --moe-tp-size can both exceed one, for example --ep-size 2 --moe-tp-size 4 with --tensor-parallel-size 8. Each EP rank then holds its share of the routed experts, split over its MoE TP ranks along their intermediate size, and the MoE's all-reduce sums the partial results across the TP x EP group. Each GPU stores the same expert bytes as under MoE TP8. Startup fails when the selected routed-expert kernel cannot run the split, for example with MegaMoE.

Kimi-K3 attention DP with MoE EP ​

With none, agrs, or flashinfer transport and attention DP greater than one, Kimi-K3 requires MoE TP 1 and attention TP x attention DP == MoE EP == world size. Only the routed experts require dispatch/combine communication. With attention TP 1 (DEP), shared experts and attention projections are replicated. With attention TP greater than one, each attention-TP rank routes a slice of its replica's rows and the shared experts shard over the replica's attention-TP group. For example, two attention replicas of TP8 with KV parallelism 8 and routed EP16 across both: --attn-tp-size 8 --data-parallel-size 2 --kv-parallel-size 8 --decode-context-parallel-size 8 --moe-tp-size 1 --expert-parallel-size 16. Static expert placement requires attention TP 1. On this path (any transport but deepep, or MegaMoE), an EP size that does not divide the 896 routed experts takes redundant slots (static expert placement), for example --ep-num-redundant-experts 4 --ep-dispatch-algorithm static at EP20.

Select the transport with --all2all-backend:

  • none (default): automatically use FlashInfer on NVIDIA ranks sharing a CUDA fabric, otherwise AG/RS.
  • agrs: use reference all-gather dispatch and reduce-scatter combine.
  • flashinfer: use FlashInfer MNNVL all-to-all; errors without the required CUDA fabric.
  • deepep: Hopper Marlin supports attention TP combined with DP and pipeline parallelism. It requires attention CP=1, MoE TP=1/DP=1, and MoE EP == attention TP * attention DP within each pipeline stage. DeepEP owns routed dispatch/combine. Shared experts stay in the attention TP group. The construction-selected KimiLinearMoEDeepEP keeps this token ownership and its projection/shared-expert weight placement in one module. See Kimi-K3 Hopper PD for deployment layouts.

For NVIDIA NVFP4 and MXFP4 checkpoints, you can select --moe-backend mega_moe. It requires --all2all-backend none and returns BF16 outputs. For MegaMoE dispatch, AG/RS activation quantization, and combine details, see MoE transport and quantization internals.

Tensor-parallel subgroups within DP ​

Set the same values on every worker before launch. Unset or 1 keeps that component replicated. Non-integer values produce a warning and use 1. Workers must agree on the resulting sizes before creating TP subgroups.

The following table lists the independent settings for sharding selected dense weights across contiguous groups of DP ranks:

Environment variableSharded computation
TOKENSPEED_KIMI_K3_QKV_PROJ_TP_SIZEKDA QKV/gates and MLA QKV-A/output gate
TOKENSPEED_KIMI_K3_O_PROJ_TP_SIZEKDA and MLA output projections
TOKENSPEED_KIMI_K3_SHARED_EXPERT_TP_SIZEBF16 shared-expert MLP

Each size must be a positive divisor of world size. Shared-expert TP must also be smaller than world size and divide the MLP intermediate width. Keep attention and linear attention at TP1/DPworld, routed MoE at TP1/EPworld, and pipeline parallelism disabled. QKV and output projection sharding also require attention head-TP at 1. DEP16 can use TP2, TP4, or TP8 subgroups. These settings do not change attention caches or token ownership.

QKV and output projection sharding support BF16 and 128×128 block-FP8 weights with BF16 activations, including the FP8 attention weights in an NVFP4 checkpoint. The sharding preserves checkpoint FP8 codes and scales. QKV TP requires gated MLA with Q-LoRA. TokenSpeed rejects gated MLA without Q-LoRA even with replicated projections. MLA Q-B, KV-B, KDA convolution, and norms keep their existing mapping. Target-model projection settings do not change the draft model. Kimi-K3.1 sparse MLA (DSA) supports the same QKV and output projection settings.

Empty ranks still join collectives when peers have work. Uneven batches pad to the subgroup's largest physical token count. Native collectives cover the configured decode batch bound including speculative tokens; larger batches retain NCCL. Place each subgroup on a CUDA-IPC-accessible node to use the optimized paths. For collective data flow, buffer reuse, and routed/shared ordering, see Kimi-K3 subgroup communication and fusion layouts.

Automatic projection fusion uses TP2 or TP4. Column fusion requires input widths and output shard widths aligned to 128 channels. Row fusion requires input and output widths aligned to TP × 128 channels. BF16 TP4 sparse-MLA QKV-A can fuse with 96-channel shard alignment on SM100 and SM103.

Block-FP8 and BF16 fusion support SM100 and SM103. A subgroup can span nodes within one NVLink domain when every rank can allocate fabric memory. The subgroup maximum must be at least 32 physical rows for BF16 column fusion and 64 for BF16 row or block-FP8 fusion. Unsupported configurations use the ordinary projection collectives. For stored-channel layouts, tile selection, and rounding, see Kimi-K3 subgroup communication and fusion layouts.

These projection settings apply to DEP; DWDP still requires them to be 1. Shared-expert TP requires BF16 weights.

TP4 reduces the selected weights to approximately one quarter per GPU, not total model memory or latency. Communication and padding can outweigh GEMM savings, especially for uneven traffic or large prefill batches. Compare TTFT, decode latency, and cache capacity separately with real weights and the full model. A fixed memory budget can turn weight savings into more cache rather than lower device usage. Reduced-layer tests do not establish full-model capacity.

DEP16 example with TP4 subgroups ​

This example enables all three settings. Set any one to 1 to keep that component replicated, or set all three to 1 for the DEP16 baseline.

Prepare four nodes with four GPUs each. Launch one server process per node, using the same checkpoint, container, and environment. On Slurm, reserve a persistent allocation with salloc, then launch through the site's submit wrapper or srun.

  1. On every node, set the three subgroup sizes:

    bash
    export TOKENSPEED_KIMI_K3_QKV_PROJ_TP_SIZE=4
    export TOKENSPEED_KIMI_K3_O_PROJ_TP_SIZE=4
    export TOKENSPEED_KIMI_K3_SHARED_EXPERT_TP_SIZE=4
  2. Replace MODEL_DIR with the checkpoint path and HEAD_NODE with the allocated head node, not localhost. Start one server process on each node:

    bash
    python -m tokenspeed.cli serve \
      --model MODEL_DIR --quantization nvfp4 --dtype bfloat16 \
      --world-size 16 --nprocs-per-node 4 \
      --attn-tp-size 1 --data-parallel-size 16 --dense-tp-size 1 \
      --moe-tp-size 1 --expert-parallel-size 16 \
      --all2all-backend flashinfer --moe-backend flashinfer_trtllm \
      --attention-backend tokenspeed_mla --kda-backend cudnn \
      --dist-init-addr HEAD_NODE:29500 \
      --max-num-seqs 256 --max-model-len 4096 \
      --chunked-prefill-size 1024 --max-prefill-tokens 1024 \
      --enable-prefix-caching --disable-kvstore \
      --max-cudagraph-capture-size 16 --cudagraph-capture-sizes 1 2 4 8 16
  3. Validate the parallel deployment and check cache admission. The global sequence limit in this example allows 16 requests per rank. For higher concurrency, increase both the sequence budget and graph capture sizes and check cache admission.

Keep hardware, inputs, and serving settings fixed when comparing TP configurations.

DeepEP all-to-all ​

--all2all-backend deepep moves expert routing off all-gather and onto DeepEP dispatch/combine. It requires a MoE backend whose kernels own those legs: --moe-backend deep_gemm (block-scale FP8), --moe-backend flashinfer_cutedsl (NVFP4, decode-shaped batches only), or --moe-backend marlin (MXFP4 W4A16 with BF16 activations, normal and low-latency legs). K3 on Hopper uses the Marlin bridge with disjoint TP token slices. Its shared experts and restored output stay within each attention-TP group. See the K3 Hopper PD guide for PP4/TP8/EP8 prefill and DP4/TP8/EP32 decode.

The DeepEP capacity remains the explicit server setting (256 by default), with no model-name-based sizing in ModelRunner. For buffer reservation, geometry, and reuse checks, see DeepEP communication buffer lifecycle.

The following table lists the --deepep-mode values and the DeepEP legs that each value uses:

ModeLegsBatch shape or serving mode
low_latencyIBGDA dispatch into a preallocated per-expert bufferDecode-shaped batches up to --low-latency-max-num-tokens-per-gpu
normalHigh-throughput dispatch, tokens permuted into per-expert row blocksExtend-shaped batches of any size
auto (default)Both are allocated; each forward picksAggregated serving, which mixes both shapes

For block-scale FP8 with deep_gemm, keep auto unless the instance only ever sees one shape—for example, a decode-only worker in a PD split, which can pin low_latency and skip the normal-mode buffers. The NVFP4 flashinfer_cutedsl kernel implements only the low-latency legs, so it requires an explicit --deepep-mode low_latency. TokenSpeed rejects auto and normal while building the execution plan. Every forward on such an instance, including any prefill, must fit --low-latency-max-num-tokens-per-gpu.

The runtime rejects a batch above the low-latency capacity rather than truncating it. If decode plus speculative draft tokens exceed the capacity, raise --low-latency-max-num-tokens-per-gpu. All current DeepEP MoE backends require BF16 activations and do not support --dtype float16.

Each forward picks the mode from a value every rank agrees on, because the two modes are different collectives. With DP attention that value is "every DP rank is decoding", so one extending rank moves the whole group to the normal legs.

When DeepEP is selected, TokenSpeed disables the prefill CUDA graph: normal-mode dispatch reports its per-expert receive counts to the host, and a graph cannot capture a host sync. Decode graphs replay the low-latency legs; --deepep-mode normal has none to replay, so it disables CUDA graphs altogether.

For low-latency routing metadata, quantization, scale layouts, and MN-major fallback behavior, see DeepEP kernel and scale layouts.

TokenSpeed documentation