Skip to content

Kimi-K3 lora RL day-0 support - #1825

Open
yueming-yuan wants to merge 3 commits into
yueming/cp-layout-utils-to-pluginsfrom
kimi-k3
Open

Kimi-K3 lora RL day-0 support#1825
yueming-yuan wants to merge 3 commits into
yueming/cp-layout-utils-to-pluginsfrom
kimi-k3

Conversation

@yueming-yuan

@yueming-yuan yueming-yuan commented Jul 27, 2026

Copy link
Copy Markdown
Collaborator

Blog

check details and experiment results in:
https://www.lmsys.org/blog/2026-07-27-kimi-k3-day0-support

Usage

sglang branch: https://github.com/sgl-project/sglang/tree/sglang-miles-k3
Docker image: docker.io/radixark/miles:kimi-k3 (multi-arch amd64/arm64; on Hopper set SGLANG_K3_ATTN_RES_MODE=jit)

About

Megatron training backend for Kimi K3 plus the colocated SGLang rollout path
it needs for RL. KDA and MLA attention per layer, the attention-residual
snapshot bank, and native LoRA adapters under TP/EP/PP/CP — with shared-A /
per-expert-B factors for the 896-expert MoE, exported to the rollout engines
as HF-named chunks over CUDA IPC.

Reproduce

The image ships miles (/root/miles, editable) and sglang
(/sgl-workspace/sglang, editable) at the validated pins, flashinfer
0.6.15.post1, and a small shm_unlink shim preloaded via
/etc/ld.so.preload (tolerates a benign PyTorch CUDA-IPC unlink race that
otherwise aborts colocated weight sync at scale).

Prepare (once). Only external asset: the Kimi K3 MXFP4 HF checkpoint.
Everything else derives in-repo (run from /root/miles, Megatron on
PYTHONPATH):

python scripts/run_kimi_k3_lora.py prepare-data --task dapo-math --data-dir <datasets>

python tools/convert_mxfp4_to_bf16.py --model-dir <native-mxfp4> --save-dir <bf16-hf>

source scripts/models/kimi-k3.sh   # defines MODEL_ARGS
torchrun --nnodes=8 --nproc-per-node=4 ... \
    tools/convert_hf_to_torch_dist.py "${MODEL_ARGS[@]}" \
    --hf-checkpoint <bf16-hf> --save <torch-dist-dcp> \
    --bf16 --tensor-model-parallel-size 32 --sequence-parallel \
    --pipeline-model-parallel-size 1 --context-parallel-size 1 \
    --expert-model-parallel-size 32 --expert-tensor-parallel-size 1 \
    --megatron-to-hf-mode raw   # 32 ranks; the torch_dist output re-shards at load

Run (validated on 16 nodes x 4 GPUs). One container per node, bring up a
ray cluster across the nodes, export MILES_SCRIPT_EXTERNAL_RAY=1, then:

python scripts/run_kimi_k3_lora.py train \
  --mode normal --model-variant full --task dapo-math --reward-model deepscaler \
  --num-nodes 16 --num-gpus-per-node 4 \
  --pipeline-parallel-size 8 --context-parallel-size 2 \
  --rollout-tp-size 16 --rollout-max-concurrency 8 \
  --lora-rank 32 --lora-alpha 64 \
  --num-rollout 1000 --rollout-batch-size 8 --n-samples-per-prompt 8 \
  --rollout-max-response-len 4096 --sglang-max-total-tokens 65536 \
  --global-batch-size 64 --lr 1e-05 --eval-interval 10 \
  --distributed-timeout-minutes 60 \
  --hf-checkpoint <native-mxfp4> --ref-load <torch-dist-dcp> \
  --sglang-path /sgl-workspace/sglang/python \
  --data-dir <datasets> --enable-wandb

(--rollout-max-concurrency 8 explicitly: the field default is 64, the
validated runs pin 8.)

Expected. Resolved config at startup shows expert_model_parallel_size 8,
max_tokens_per_gpu 8192, colocate_memory_peak_device gpu,
lora_base_cpu_backup True. On our GB300 validation runs: ~11-13 min per
rollout cycle; trainer allocated returns to ~91 GB after every weight sync;
rollout/raw_reward 0.5-0.75 from rollout 0; eval/aime 0.37-0.43 at eval@0
(temp-0 nondeterminism band), rising >= +0.06 by eval@9 (we measured
0.367 -> 0.467).

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Megatron training backend for Kimi K3 plus the colocated SGLang rollout path
it needs for RL.

Model: KDA (delta-rule) and MLA attention per layer, the attention-residual
snapshot bank, and situ activation, under TP/EP/PP/CP. Native LoRA adapters
are applied in-model, with shared-A/per-expert-B factors for the 896-expert
MoE, and exported to the rollout engines as HF-named chunks over CUDA IPC.

Also included: mbridge and megatron_bridge plugins, megatron->HF conversion,
MXFP4 pack/unpack plus an MXFP4->BF16 checkpoint tool, and the launchers.
…lts, EP derivation; disable sglang NUMA membind by default; drop manual CUDA-IPC collection from the LoRA push
@yushengsu-thu yushengsu-thu self-assigned this Jul 29, 2026
Zhichenzzz added a commit that referenced this pull request Aug 11, 2026
…nkling

Kimi-K3 now has a page. It documents the day-0 LoRA RL recipe from #1825: the
MXFP4 to BF16 upcast, the 32-rank torch_dist conversion, and the validated
16-node launch, with the LoRA target modules and what a healthy run looks like
on the GB300 validation cluster. A line at the top says the branch it comes
from, since none of it is on main yet.

The page leans on two things worth calling out. LoRA is not a nicety here, it
is what makes the recipe fit: the base stays frozen and only the adapters carry
gradients, with one shared A factor and per-expert B factors across the 896
experts. And the memory figure in "what a healthy run looks like" is the one to
watch, because an adapter export that leaks shows up as allocated memory not
returning to baseline after a weight sync, long before the run dies.

Inkling still said its implementation "is open at" #1683. That merged on
2026-08-03 and the code is on main, so the line is gone; the page is the
documentation now.

Both tables link Kimi-K3 at the page instead of the pull request. MiMo and
GPT-OSS move below JoyAI so the families the home page lists appear in the same
order in both, with the two it does not carry after them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants