Kimi K3
Use this recipe to serve moonshotai/Kimi-K3 on NVIDIA or AMD GPUs. Kimi-K3 combines a MoonViT vision encoder with a hybrid KDA (linear-attention) and NoPE-MLA (full-attention) decoder and a DeepSeek-V3-style latent MoE.
For Hopper MXFP4 serving with pipeline prefill, attention-DP decode, DeepEP, DSpark, and decode CUDA graphs, see the K3 Hopper PD configuration and validation guide. For attention-DP serving with independently sharded QKV, output projections, and shared experts, see Kimi-K3 DP with TP subgroups.
Prerequisites
Prepare the model, hardware, and dependencies before starting the server:
- Model and frontend: Use
moonshotai/Kimi-K3. The SMG packages pinned by TokenSpeed resolve this checkpoint directly. You no longer need a flattened local checkpoint and a separately staged remote-code cache. - NVIDIA hardware: The recommended NVIDIA configuration uses 8x B300 GPUs.
- AMD hardware: The Eagle3 and speculator-free configurations use 8x MI350X/MI355X (gfx950) GPUs. The Gluon Petit MegaMoE configuration uses one node with 8x gfx950 GPUs.
On NVIDIA, the KDA layers use flash-linear-attention kernels. Install the package in the same Python environment as TokenSpeed:
pip install flash-linear-attentionNVIDIA
On 8x B300 GPUs, start TokenSpeed with expert parallelism (recommended). This configuration serves the model as kimi-k3 on port 8000:
tokenspeed serve moonshotai/Kimi-K3 \
--served-model-name kimi-k3 \
--trust-remote-code \
--max-model-len 32768 \
--kv-cache-dtype fp8 \
--tensor-parallel-size 8 \
--mm-encoder-tp-mode data \
--ep-size 8 \
--moe-backend flashinfer_trtllm \
--max-num-seqs 32 \
--disable-kvstore \
--host 0.0.0.0 \
--port 8000Plain TP8 (drop --ep-size 8) works too. The fused MoE path needs a Blackwell GPU (B200/B300). On other NVIDIA platforms, use --moe-backend triton.
After the server reports ready, verify the served model.
AMD
Choose an AMD configuration based on whether you need speculative decoding or the Gluon Petit MegaMoE backend.
Serve with the Eagle3 draft
On 8x MI350X/MI355X (gfx950), serve with the Eagle3 draft at TP8 and expert parallelism disabled. This is the configuration of the per-commit MI35x 50K-input/500-output perf job. Against the speculator-free TP8/EP8 launch in Serve without speculative decoding, TP8/EP1 cuts prefill latency enough to improve end-to-end latency at concurrency 16, despite a higher per-token decode latency.
Start the server with the following configuration:
tokenspeed serve moonshotai/Kimi-K3 \
--served-model-name kimi-k3 \
--trust-remote-code \
--max-model-len 65536 \
--kv-cache-dtype fp8 \
--tensor-parallel-size 8 \
--ep-size 1 \
--mm-encoder-tp-mode data \
--speculative-algorithm EAGLE3 \
--speculative-draft-model-path lightseekorg/kimi-k3-eagle3-mla \
--speculative-num-steps 3 \
--speculative-num-draft-tokens 4 \
--speculative-eagle-topk 1 \
--speculative-draft-model-quantization unquant \
--eagle3-layers-to-capture 2,46,90 \
--attention-backend gluon \
--drafter-attention-backend gluon \
--moe-backend auto \
--max-num-seqs 16 \
--chunked-prefill-size 8192 \
--max-prefill-tokens 8192 \
--max-cudagraph-capture-size 16 \
--cudagraph-capture-sizes 1 2 4 8 16 \
--disable-prefill-graph \
--gpu-memory-utilization 0.92 \
--disable-kvstore \
--host 0.0.0.0 \
--port 8000Use the following constraints and tuning options with this configuration:
gluonrequires Gluon MLA kernels for both the target and its MLA drafter. The explicit policy fails fast when the current GPU, dtype, or attention shape has no registered Gluon kernel, instead of silently selecting another solution.--attention-backend mla --drafter-attention-backend mlalets TokenSpeed select the MLA kernels automatically.--disable-prefill-graphskips prefill CUDA graphs, which need 40 buckets on top of the decode ones and run out of memory at this memory fraction. Speculative decoding runs on the decode graphs.- To raise
--max-num-seqs, extend--cudagraph-capture-sizesand--max-cudagraph-capture-sizewith it. - AMD defaults to greedy sampling, which ignores per-request
temperature,top_p, andtop_k.
After the server reports ready, verify the served model.
Serve without speculative decoding
Without speculative decoding, use TP8/EP8. Automatic MoE selection then uses the specialized Gluon SiTU kernels:
tokenspeed serve moonshotai/Kimi-K3 \
--served-model-name kimi-k3 \
--trust-remote-code \
--max-model-len 8192 \
--kv-cache-dtype fp8 \
--tensor-parallel-size 8 \
--mm-encoder-tp-mode data \
--enable-expert-parallel \
--attention-backend mla \
--moe-backend auto \
--max-num-seqs 32 \
--disable-kvstore \
--host 0.0.0.0 \
--port 8000On gfx950, the replicated 7168↔3584 latent projections automatically select among a one-token Triton GEMV, tuned Gluon GEMMs, and the vendor GEMM according to the current token count. At TP8/EP8, eligible one-token decode also combines the routed MXFP4 experts with the shared-expert down projection, then applies their joint reduction before the fused latent up-projection epilogue. Other shapes and unsupported layouts retain the ordinary composed path. The fused sigmoid-bias top-k route supports the full scheduled token count.
After the server reports ready, verify the served model.
Serve with Gluon Petit MegaMoE
For Gluon Petit MegaMoE on one node with 8x gfx950 and MXFP4 expert weights, use attention DP8 and EP8, with at most 1024 tokens per rank:
TORCH_NCCL_BLOCKING_WAIT=1 tokenspeed serve moonshotai/Kimi-K3 \
--trust-remote-code --dtype bfloat16 \
--tensor-parallel-size 1 --data-parallel-size 8 --ep-size 8 \
--attention-backend mla --kv-cache-dtype fp8 \
--moe-backend gluon_petit --all2all-backend gluon_petit \
--max-model-len 8192 --max-num-seqs 32 \
--chunked-prefill-size 1024 --max-prefill-tokens 1024 \
--disable-kvstore --disable-autotuneAfter the server reports ready, verify the served model. Because this command doesn't set --served-model-name, use moonshotai/Kimi-K3 as the model ID in the verification request.
Verify the server
Send a chat completion request to confirm that the server can generate a response. Replace 8000 if you configured a different port, and replace kimi-k3 if you set a different served model name:
curl --fail http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{
"model": "kimi-k3",
"messages": [{"role": "user", "content": "What is 2 + 2?"}],
"max_tokens": 64
}'A successful request returns a JSON chat completion with a choices array.
Configure runtime defaults and backends
The following defaults and backend constraints apply to Kimi K3.
Runtime and parser defaults
- K3 uses the cache-group scheduler and KDA state groups.
tokenspeed serveauto-selects thekimi_k3reasoning and tool-call parsers. Explicit parser flags override these defaults.
Attention and KDA backends
- The NVIDIA default selects
tokenspeed_mla(FP8 KV), whose current kernels support Blackwell. On Hopper, explicitly select--attention-backend flashmlaormlawith--kv-cache-dtype bfloat16. AMD uses themlabackend. - KDA dispatch is vendor-neutral at the runtime boundary. The kernel registry selects the existing FLA-derived NVIDIA implementation or the native AMD implementation, including each backend's preferred recurrent-state layout. The runtime does not transpose or reinterpret that state.
Blackwell dense GEMM backend
On Blackwell, --dense-gemm-backend trtllm_cutedsl opts the block-FP8 attention projections into TRT-LLM CuTe-DSL: KDA fused QKV/gates and output, and MLA fused QKV-a/gate, Q-b, and output. Consider the following behavior and requirements before selecting this backend:
- With
auto, compatible GEMMs prefer CuTe-DSL at M > 16 rows and FlashInfer at M <= 16. Unsupported CuTe-DSL inputs retain compatible fallback selection. M is the actual GEMM row count, not necessarily request concurrency. Explicittrtllm_cutedslalso selects CuTe-DSL for smaller M. This shared option applies across models to standard 128x128 block-FP8 dense linears. BF16/NVFP4 linears, MXFP8, per-tensor FP8, specialized grouped projections, and routed experts are unchanged. It does not change tensor-parallel mapping. - This backend preserves checkpoint FP8 values and their FP32 128x128 block scales. It does not requantize weights or convert scales to E8M0. Activations use the existing 1x128 FP8 quantization path. The kernel uses FP32 accumulation and BF16 output. Validate model accuracy on your workload. Preserving the quantization contract does not guarantee bitwise equality across GEMM implementations.
- The backend requires Blackwell, CuTe-DSL with TVM-FFI support, BF16 outputs, and aligned local weight dimensions. Kernel variants compile during preparation before CUDA-graph capture. Unsupported selected linears fail instead of silently falling back. Faster GEMMs alone do not establish an end-to-end speedup.
Configure speculative decoding
Review the following cache, attention, and draft-checkpoint constraints when you add a DSpark or DFlash2 draft:
- Cache dtype: K3's target and DSpark draft MLA caches follow the shared
--kv-cache-dtypesetting, as with EAGLE3:fp8selects FP8;autoandbfloat16select BF16. - DSpark attention: DSpark proposal blocks use non-causal MLA draft attention. Both the
mlaandtrtllm_mladraft backends preserve every block row during eager execution and CUDA graph capture. When K3's 128-token logical cache pages feed the 64-token TRT-LLM MLA kernel, the backend expands each logical page into its two physical kernel pages before draft attention. - KV parallelism: K3 DSpark context injection supports KVP (
--kv-parallel-size > 1) by translating virtual slots into shard-local addresses and masking nonowner writes. The selected draft backend must support DCP decode and non-causal block attention on the device and cache dtype in use. - DFlash2 attention: A K3 DFlash2 draft declares
sliding_attentionlayers, so it needs a drafter backend that applies per-layer sliding windows:--drafter-attention-backend mla. Those layers dispatch to the CuteDSL windowed decode on Blackwell, which walks the KV from the window rather than from token zero, and fall back to the portable Triton kernel anywhere its shape gate does not hold. The draft's full-attention layer is unaffected either way. - Verify window: For Kimi K3, an eight-token verify window uses seven DSpark draft queries. The anchor query directly predicts the first draft through the Markov head. Do not pad it with an eighth, unused mask row.
- Target feature stream: The target model captures features from K3's completed-layer prefix stream before the model-level AttnRes mix and final norm, matching the DSpark checkpoint's vLLM training and inference contract. A draft trained instead against the pre-norm AttnRes mixture declares
"aux_hidden_stream": "attn_res"in its config, and TokenSpeed serves it that stream. Feeding a draft the other stream raises nothing and shows up only as a lower acceptance rate, so the server logs the choice next to the tap IDs at startup. - Feature normalization: A draft whose config sets
"fc_norm": truenormalizes each target tap on its own before it concatenates and projects the taps, and ships onefc_norm.N.weightper tap. Declaring it without the weights (or shipping the weights without declaring it) fails the load rather than serving an identity-weight norm. - Tensor parallelism: Under tensor parallelism, the TP ranks reduce the draft's final row-parallel MLP output before
final_normand shared target-head sampling.
Configure multimodal serving
- The vision encoder has 12 attention heads. For an 8-way text TP deployment, use
--mm-encoder-tp-mode dataso each rank runs the vision encoder at TP1 on a different whole image. - The pinned SMG frontend registers Kimi-K3's chat renderer and multimodal processor. Preserve the checkpoint's
media_proc_cfg.in_patch_limit=65536. Silently falling back to K2.5's 16384-patch default reduces OCR resolution.
Tune prefix-cache reuse
KDA recurrent-state pages register for prefix-cache reuse only when a prefill chunk ends exactly on a logical cache-page boundary. The engine floors --chunked-prefill-size to the plan's page grain automatically (logged as a warning when it adjusts). The page grain is budget-dependent (such as 1472 at 32k context, 1536 at 1M), so do not hand-tune the chunk size against a hard-coded page value. Prefix hits are page-granular.