Skip to main content

1. Model Introduction

Kimi-K2 is a state-of-the-art MoE language model from Moonshot AI with 32 B activated parameters and 1 T total parameters. Key highlights:
  • Trillion-parameter MoE: 1 T total / 32 B active per token, 61 layers (1 dense + the rest MoE), MLA attention shaped like DeepSeek-V3.
  • Instruct and Thinking variants: Instruct is the general-purpose chat / agentic post-train; Thinking adds step-by-step reasoning with a 256 K context and ships in native INT4.
  • DeepSeek-V3-shaped architecture: miles loads it through the DeepSeek-V3 path (one sed away), reusing the conversion + parallelism plumbing.
  • INT4 QAT target: Kimi-K2-Thinking is the canonical reference recipe for INT4 QAT in miles.

2. Supported Variants

3. Environment Setup

3.1 Required env vars

MASTER_ADDR reaches the ray workers as the torch-distributed rendezvous address; MILES_SCRIPT_EXTERNAL_RAY=1 tells the launcher the cluster is already up (see §4.2). Paths are Typer flags: --model-dir (default /root/models), --data-dir (default /root/datasets), --output-dir (default /root/shared_data) — all three on a shared FS reachable from every node.

3.2 Download model + datasets

3.3 HF → Megatron torch_dist conversion

Convert across 4 nodes (mirror the DeepSeek-V3 procedure):

4. Launch

4.1 Quick start

Both variants are one launcher selected by --model-name. With MILES_SCRIPT_EXTERNAL_RAY=1 it skips ray start and submits to an already-running Ray cluster (ray job submit ...).

4.2 Multi-node fan-out

Bring up Ray on every node before launching:

5. Recipe Configuration

5.1 Parallelism

Identical for both Instruct and Thinking: Both variants pass --actor-num-nodes 32 --actor-num-gpus-per-node 8 --colocate --update-weight-buffer-size 2147483648 to train.py; --num-nodes overrides the node count.

5.2 Algorithm

Both use --use-kl-loss --kl-loss-coef 0.00 --kl-loss-type low_var_kl --entropy-coef 0.00. Rollout shape (both):
DAPO-style dynamic sampling is on by default for both variants.

5.3 Rollout & SGLang

Identical for both:
SGLang DeepEP (--sglang-moe-a2a-backend deepep, --sglang-deepep-mode) is not enabled for either variant. Megatron-side --moe-enable-deepep and --moe-token-dispatcher-type flex are on for Kimi-K2-Instruct and off for Kimi-K2-Thinking.

5.4 Optimizer

CPU Adam is enabled in both:

5.5 Notable quirks

  • Instruct loads the BF16 HF release, Thinking the FP8 one (Kimi-K2-Thinking-fp8). Their torch_dist reference directories differ too — Kimi-K2_torch_dist vs Kimi-K2-Thinking_torch_dist.
  • Neither variant passes --global-batch-size; the batch is driven by --rollout-batch-size and --num-steps-per-rollout.

6. Pairs Well With