Skip to content

Kimi K3.1 Pro ​

Kimi-K3.1 (KimiK31ForConditionalGeneration) is Kimi-K3 with a DSA lightning indexer on each of its 24 MLA layers: every MLA layer attends only the 2048 history tokens (index_topk) its own indexer selects. The KDA layers, the MoE, the vision encoder, the parsers, and the cache family are Kimi-K3's, so the Kimi K3 recipe notes apply unless a note in this recipe says otherwise.

Prerequisites ​

Before you start, prepare the following resources:

  • Use the moonshotai/Kimi-K3.1-Pro target checkpoint. Both launch commands also use the released Inferact/Kimi-K3.1-Pro-DSpark draft checkpoint.
  • Choose a supported hardware topology:
    • NVIDIA: 8 Blackwell GPUs, or 2 nodes with 4 GPUs each. The multi-node variation includes specific settings for Vera Rubin (SM107) GPUs.
    • AMD: 8x MI350X/MI355X GPUs (gfx950).
  • For NVIDIA, install flash-linear-attention for the KDA layers, as for Kimi K3. The NVIDIA procedure includes the installation command.
  • Leave --attention-backend unset, or pass dsa. The MLA layers then run the dsa sparse-MLA backend inside the KDA hybrid wrapper. The dense MLA backends do not run the indexer.

Serve on NVIDIA GPUs ​

This procedure serves the target with the released DSpark draft.

  1. Install the package required by the KDA layers on NVIDIA:

    bash
    pip install flash-linear-attention
  2. Start TokenSpeed on 8 Blackwell GPUs. The command exposes the model as kimi-k3.1 and listens on port 8000; change --host and --port if your deployment needs a different HTTP address.

    bash
    tokenspeed serve moonshotai/Kimi-K3.1-Pro \
      --served-model-name kimi-k3.1 \
      --trust-remote-code \
      --kv-cache-dtype fp8 \
      --tensor-parallel-size 8 \
      --mm-encoder-tp-mode data \
      --moe-backend flashinfer_trtllm \
      --max-num-seqs 64 \
      --prefill-graph-capture-batch-sizes 1 64 \
      --speculative-algorithm DSPARK \
      --speculative-draft-model-path Inferact/Kimi-K3.1-Pro-DSpark \
      --speculative-num-draft-tokens 8 \
      --drafter-attention-backend mha \
      --host 0.0.0.0 \
      --port 8000

    The context length is the checkpoint's 1,048,576 tokens. To serve without the draft, drop the four speculative flags: --speculative-algorithm, --speculative-draft-model-path, --speculative-num-draft-tokens, and --drafter-attention-backend.

  3. Optional: For a deployment on 2 nodes with 4 GPUs each, start every node with the preceding command and additional distributed-launch flags. Replace <rank> with the node's rank (0 on the first node and 1 on the second), and replace <first-node>:<port> with the first node's address and a free port on it:

    --nnodes 2 --node-rank <rank> --dist-init-addr <first-node>:<port>

    On 2 nodes of 4 Vera Rubin (SM107) GPUs, also add --kv-parallel-size 8 --decode-context-parallel-size 8.

  4. Verify that the server is ready.

Tune NVIDIA prefill graphs ​

On NVIDIA, prefill CUDA graphs replay with the DSA attention at eager breaks on the PD prefill role (with --disaggregation-layerwise-interval 0) and on the aggregated role, mixed rounds included; elsewhere prefill runs eager. --disable-prefill-graph turns them off. On the aggregated role, the default bucket ladder takes about 7.5 GB more per GPU, out of the KV cache, and adds about 7 minutes to startup. Use --prefill-graph-capture-token-sizes to capture fewer buckets.

The NVIDIA command captures each prefill bucket for 1 and for up to 64 requests (--prefill-graph-capture-batch-sizes 1 64), so a prefill of several requests also runs its KDA layers inside the graph instead of at eager breaks. On 2 GB300 nodes with the MLA preview draft, this cut the time-to-first-token of 2 to 64 concurrent short prompts by 40% to 55%, for about 0.7 GB less KV cache per GPU and 2 to 3 more minutes of startup.

Optional: Tune multi-node MoE parallelism ​

On 2 nodes of 4 Vera Rubin (SM107) GPUs, adding --ep-size 2 --moe-tp-size 4 (mixed MoE TP and EP) cut the decode step by 3 to 5% at 16 to 64 concurrent requests and the time to first token of 8k- and 16k-token prompts by about 3.5%. However, this layout turns off the Kimi-K3 decode chain, which needs MoE EP 1, so 8 concurrent requests decode about 8% slower.

Serve on AMD GPUs ​

Use this procedure for TP8 with KV parallelism 8 and the released Kimi-K3.1 DSpark draft.

  1. Start TokenSpeed on 8x MI350X/MI355X GPUs (gfx950). The command exposes the model as kimi-k3.1 and listens on port 8000; change --host and --port if your deployment needs a different HTTP address.

    bash
    GPU_MAX_HW_QUEUES=2 tokenspeed serve moonshotai/Kimi-K3.1-Pro \
      --served-model-name kimi-k3.1 \
      --trust-remote-code \
      --max-model-len 131072 \
      --kv-cache-dtype fp8 \
      --dsa-index-k-format mxfp4 \
      --tensor-parallel-size 8 \
      --mm-encoder-tp-mode data \
      --kv-parallel-size 8 \
      --decode-context-parallel-size 8 \
      --speculative-algorithm DSPARK \
      --speculative-draft-model-path Inferact/Kimi-K3.1-Pro-DSpark \
      --speculative-num-steps 5 \
      --drafter-attention-backend mha \
      --prefill-graph-max-tokens 3072 \
      --prefill-graph-capture-token-sizes 256 512 1024 1536 2048 3072 \
      --disable-kvstore \
      --enable-startup-requests \
      --host 0.0.0.0 \
      --port 8000

    CI's Kimi-K3.1 AMD accuracy and performance jobs serve this same command, and test/ci_system/test_eval_configs.py fails if the two drift apart.

  2. Verify that the server is ready.

Review AMD defaults and constraints ​

The following defaults, limits, and tuning options apply to the AMD launch:

  • Options not shown in the command use the defaults: TP8 without expert parallelism, automatic MoE selection, the dsa attention backend, an 8192-token prefill budget, --gpu-memory-utilization 0.95, prefix caching, and CUDA graph capture sizes up to the speculative --max-num-seqs default.
  • --max-model-len 131072 caps requests at 128K tokens. Raise it for longer prompts; at the checkpoint's full 1M context, the speculative verify padding runs past the RoPE tables, and the server warns at startup.
  • --mm-encoder-tp-mode data: the vision encoder's 12 heads don't split 8 ways, so each GPU keeps a copy of the encoder and encodes whole images.
  • --kv-parallel-size 8 --decode-context-parallel-size 8: each GPU stores one eighth of every request's full-attention pages, and decode attends each GPU's share of the selected keys. For more information, see KV parallelism.
  • --dsa-index-k-format mxfp4 stores the indexer keys as MXFP4 (68 bytes per token per layer instead of FP8's 132) and scores them against MXFP4 queries.
  • --speculative-num-steps 5 drafts 5 tokens per step (a 6-token verify window) instead of the draft checkpoint's 7, which suits many concurrent requests better than a single one. A step count equal to the default of 3 doesn't override the checkpoint; pass --speculative-num-draft-tokens 4 with it.
  • --drafter-attention-backend mha runs the released draft's sliding-window GQA layers, causally within the block and under KVP. For more information, see Use the released DSpark draft.
  • Prefill CUDA graphs replay under KV parallelism too, with the DSA attention and the KV history gather at eager breaks. --prefill-graph-max-tokens 3072 captures only chunks of up to 3072 new tokens; longer chunks run faster eager. --prefill-graph-capture-token-sizes captures 6 buckets instead of the default ladder's 44, which reserves about 10 GB per GPU at startup and leaves too few KV cache blocks with KV parallelism at a 1M-token context.
  • GPU_MAX_HW_QUEUES=2 gives each stream priority one hardware queue per compute pipe. With ROCm's default of 4, two queues share a pipe, so prefill's high-priority side kernels can wait behind the forward's GEMMs.
  • --enable-startup-requests has the engine serve a few requests of its own before it reports ready, so eager prefill and the request bookkeeping are compiled before the first client request instead of during it.
  • --disable-kvstore turns off the host-memory KV tier; prefix caching on the GPU stays on.
  • The Kimi-K3 AMD note on greedy sampling applies.

Review DSA and MoE behavior ​

The following constraints apply across deployment topologies:

  • Under attention DP with MoE EP, use --moe-backend mega_moe --all2all-backend none to run the MXFP4 routed experts through FlashInfer's Kimi K3 MegaMoE instead of the all-to-all transport and the TRT-LLM kernel.
  • The indexer keys live in an index-K plane beside each MLA layer's latent plane in the full-attention cache group, so prefix caching, PD transfer, and frees treat them with the latent rows. The plane stores the keys as FP8 with one FP32 scale per 128 channels, 132 bytes per token per layer, whatever --kv-cache-dtype sets for the latent.
  • The checkpoint ships no modeling code. The indexer follows DeepSeek-V3.2: queries from the normalized MLA q latent, LayerNorm keys without RoPE, and per-head ReLU scores weighted by weights_proj. Loading validates dsa_config against that and fails on anything else, on an indexer tensor without a parameter, and on an indexer parameter the checkpoint does not fill.
  • Speculative verify takes up to 8 query rows per request on Blackwell and up to 6 on gfx950.
  • The DSA layers run attention TP only; TokenSpeed refuses the Kimi-K3 QKV and output projection TP subgroups at startup.

Choose a DSpark draft ​

The launch commands use the released DSpark draft. TokenSpeed also supports the earlier MLA preview draft, with different attention and width settings.

Use the released DSpark draft ​

The released Kimi-K3.1 DSpark draft (Inferact/Kimi-K3.1-Pro-DSpark) is saved by the speculators library. TokenSpeed converts its configuration to the DFlash layout at load time: draft layers from transformer_layer_config, target taps one below each aux_hidden_state_layer_ids entry, and the mask token, whose trained embedding row replaces the target's. Its five GQA layers slide over a 2048-token window and attend causally within the block, so serve it with --drafter-attention-backend mha, which also runs it under KVP. Its block_size of 7 is the number of drafted tokens, so the verify window is one larger (--speculative-num-draft-tokens 8). Other speculators DSpark drafts load the same way.

Use the earlier MLA preview draft ​

The earlier MLA preview draft (Inferact/Kimi-K3.1-Pro-DSpark-preview) proposes up to 7 tokens per step: its checkpoint sets 7 drafts with --speculative-num-draft-tokens 8 by default, and explicit widths draft fewer (--speculative-num-steps 3 --speculative-num-draft-tokens 4). Unlike Kimi-K3's draft, it attends causally within its block (its configuration sets dflash_config.causal). --drafter-attention-backend tokenspeed_mla, mla, and gluon run causal blocks; mla and gluon also run them under KVP. The other MLA drafter backends refuse the draft at startup.

Send requests with an XTML encoder ​

If your checkpoint has a Python XTML encoder and no Jinja chat template, use its tokenizer's apply_chat_template to encode messages. Pass the token IDs as input_ids to the native /generate endpoint.

Verify the server ​

After either launch, query the gateway's readiness endpoint. If you changed the HTTP address, replace 127.0.0.1:8000 with your server's address:

bash
curl --fail http://127.0.0.1:8000/readiness

The endpoint returns HTTP 200 OK after the engine registers, and curl --fail exits with status 0. The startup log also prints ts serve ready on .... For API requests that take a model name, use kimi-k3.1.

TokenSpeed documentation