Repository navigation
Kimi-K3 W4A16 LoRA for Spindle - #39
Merged
Merged
Conversation
A LoRA run that loads the compressed-tensors MXFP4 release keeps each routed expert as its packed codes and E8M0 scales, and dequantizes them exactly into BF16 inside the grouped GEMM. The experts take a quarter of their BF16 memory, and the trainer reads the official checkpoint without an offline BF16 or torch_dist conversion. Port of the Kimi K3 parts of radixark#4667 onto v0.2.0, without the K3.1 DSA indexer (radixark#4666) or the colocated weight-sync changes. Co-Authored-By: Jiajun Li <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Multi-LoRA slots cover dense projections only, so the native K3 layout must allow leaving every routed-expert projection frozen. The adapters then cover attention, the dense MLP and the shared experts. Co-Authored-By: Claude Opus 5.5 <[email protected]>
micahtyong
force-pushed
the
micah/kimi-k3-w4a16
branch
from
November 13, 2026 00:13
7cd1d67 to
f3d5b36
Compare
- Detect MXFP4 experts from --ref-load too, since a resume or peer recovery points --load elsewhere. - Refuse HF snapshot exports, which cannot write packed experts as HF weights. - Require w1 and w3 together: the routed-expert gate/up adapter always trains both. Co-Authored-By: Claude Opus 5.5 <[email protected]>
For every weight it loads, mbridge rebuilds the model's state dict and reopens the weight's shard, header included. With tens of thousands of expert weights per rank, these took most of the load's CPU time. Build the state dict once and keep each shard open for the load. Co-Authored-By: Claude Opus 5.5 <[email protected]>
micahtyong
force-pushed
the
micah/kimi-k3-w4a16
branch
from
November 13, 2026 01:08
f3d5b36 to
96d3f1c
Compare
frrad
force-pushed
the
spindle-miles-v0.2.0
branch
from
November 13, 2026 15:41
949b877 to
8e419cc
Compare
micahtyong
marked this pull request as ready for review
November 15, 2026 22:40
This was referenced Nov 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Train Kimi-K3 LoRA from Moonshot's MXFP4 release with no conversion step. A LoRA run that loads
moonshotai/Kimi-K3keeps each frozen routed expert as its MXFP4 bytes on the GPU. The bytes are turned back into BF16 inside the expert matmul, one layer at a time. The experts then take a quarter of their BF16 memory, so the trainer fits on far fewer GPUs and reads the release directly. You no longer need the offline BF16 andtorch_distcopies (about 5.6 TB).This is the Kimi-K3 part of radixark/miles#4667, ported onto v0.2.0. It leaves out the K3.1 indexer (radixark/miles#4666) and the weight-sync changes that only colocated runs use.
The K3 load also drops two per-weight costs. For every weight, mbridge rebuilt the model's state dict and reopened the weight's checkpoint shard. With tens of thousands of expert weights per GPU, these took most of the load's CPU time. The K3 bridge now builds the state dict once and keeps each shard open. On network storage the load is still bound by reads (see below).
Multi-LoRA can now train Kimi-K3. Multi-LoRA slots cover dense projections only, but the K3 adapter layout required routed-expert adapters. Routed experts are now optional. A multi-LoRA run trains attention, the dense MLP and the shared experts, and leaves the routed experts frozen.
The MXFP4 path also gets three guards. It finds the MXFP4 checkpoint through
--ref-loadwhen--loadpoints elsewhere, as it does on a resume. It refuses--save-hfand eval snapshots, which cannot write packed experts as HF weights. And a routed-expert adapter must selectw1andw3together, since it always trains both.The memory saving assumes full recomputation (
--recompute-granularity full), which the K3 recipes use. Without it, every MoE layer keeps its BF16 experts until backward.E2E results
All runs use the
radixark/miles:v0.2.0image and drive the trainer through a multi-LoRA Tinker runtime:load_slot,forward_backward(cross-entropy),optim_stepand a PEFT adapter export. Each run has rank-32 slots and lr 1e-4. The 4-layer runs use 8 rows of 1,024 tokens.4-layer prune (
Pinaster/Kimi-K3-4layer-64experts), 8×H200, TP8/EP8. The MXFP4 run reads the release format. The BF16 run reads the same weights aftertools/convert_mxfp4_to_bf16.py.The MXFP4 and BF16 runs differ by no more than two BF16 runs differ from each other. After training, per-token log-probs differ by 0.049 on average between MXFP4 and BF16, and by 0.052 between the two BF16 runs.
forward_backwardtakes 0.42 s (MXFP4) and 0.34 s (BF16) after the first call. The first call takes 262 s in both runs, which is kernel compilation. W&B: MXFP4, BF16, BF16 second run, MXFP4 with the load changes.Full model (
moonshotai/Kimi-K3, MXFP4 release), 8×B300 on one node, TP8/EP8, 8 rows of 2,048 tokens:forward_backwardEach GPU peaks at 216 GB allocated (232 GB reserved), so the whole trainer fits on one node. Startup takes 74 minutes, almost all of it the checkpoint load, which reads each expert's tensors from network storage one at a time.
optim_steptakes 0.04 s, and the adapter export (840 tensors) takes 1.1 s. W&B: full model.Tests: the new GPU test checks that the MXFP4 grouped linear matches a BF16 grouped linear bit for bit, forward and backward, with no weight gradient. 308 tests pass across the K3 native-LoRA, bridge, conversion and target suites.
🤖 Generated with Claude Code