Repository navigation
Serve Kimi K3 LoRA adapters on MXFP4 Marlin experts - #97
Merged
micahtyong merged 3 commits intoNov 15, 2026
Merged
Conversation
Backports the serving part of sglang-miles "Kimi K3 LoRA" (sgl-project#37704): LoRA deltas for the shared-expert front GEMM and shared down projection, the gated MLA o_proj, latent routed-expert dims, num_shared_experts, and SiTU in the Marlin LoRA runner. The colocated IPC adapter streaming and in-place MXFP4 reload are left out. K3's fused attention all-reduce is off when LoRA is enabled, because the LoRA o_proj wrapper cannot write into its symmetric buffer. Routed-expert targets named w1/w2/w3 map to the MoE gate_up/down targets. Co-Authored-By: Claude Opus 5.5 <[email protected]>
The LoRA o_proj wrapper cannot write into the fusion's symmetric buffer, and with the fusion on the shared experts run LoRA kernels on a side stream next to the routed experts. Miles' Kimi K3 launcher already sets SGLANG_K3_AR_FUSION=0 with LoRA; make that the default. This replaces the narrower attention-only gate. Co-Authored-By: Claude Opus 5.5 <[email protected]>
micahtyong
force-pushed
the
spindle-sglang-v0.5.23-kimi-k3
branch
from
November 13, 2026 02:04
ed2b369 to
9acab08
Compare
micahtyong
marked this pull request as ready for review
November 15, 2026 22:40
Serving K3 with LoRA needs SGLANG_K3_AR_FUSION=0, as Miles' Kimi K3 launcher sets. Drop the LoRA auto-off and the triton_v2 fused-front guard. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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
Lets Kimi K3 (
moonshotai/Kimi-K3, the official MXFP4 release) serve LoRA adapters loaded by path. Routed experts stay MXFP4 on the Marlin MoE backend and adapters stay BF16. Adapters can target the MLAq_a_proj/kv_a_proj_with_mqa,o_projon both KDA and MLA layers, the dense MLP, the shared experts, and the routed experts (w1/w2/w3with shared outer factors).This backports the serving part of sgl-project#37704 (sglang-miles "Kimi K3 LoRA"):
gate_up_projinside one merged front GEMM and writes the shareddown_projinto a fused buffer. Both bypass the LoRA wrappers, so the model adds their LoRA deltas itself.o_proj.forward, which the LoRA wrapper skips. The wrapper now applies it throughlora_input_transform.routed_expert_hidden_size, and K3'snum_shared_expertssizes the shared-expert buffers.gemm1_alphato its SiTU beta. The Marlin LoRA runner now uses the same gated activation as the base Marlin path, so K3 gets SiTU and GPT-OSS keeps its SwiGLU. K3'sw1/w3are not interleaved, so FusedMoEWithLoRA also checksgate_up_interleaved.One addition: adapters name routed experts
block_sparse_moe.experts.*.w1/w2/w3. K3 maps those leaves to the MoEgate_up_proj/down_projtargets, so they load against the usual target list.Effects on other models:
gemm1_alpha, as the base Marlin path already does. Before, their LoRA path ran an unclamped SiLU. GPT-OSS is unchanged.num_shared_expertsinstead ofn_shared_expertsnow get shared-expert LoRA buffers sized for their shared experts.Left out of the backport: the streamed CUDA-IPC adapter install (
--lora-no-cpu-backup), the in-place MXFP4 reload, and fused shared-expert pool slots. Adapters here load from disk, the base weights never reload, and K3 does not fuse its BF16 shared experts into the MXFP4 MoE.Serve LoRA with
SGLANG_K3_AR_FUSION=0, as Miles' K3 launcher does. K3's fused all-reduce needso_projto write into a symmetric buffer, which the LoRA wrapper cannot do. List the targets explicitly.--lora-target-modules allalso picks the KDAf_a_proj, which has no LoRA support:E2E results
Setup: 8x B300, TP8,
lmsysorg/sglang:v0.5.23with this branch, rank-32 adapters loaded by path, context 8192,--mem-fraction-static 0.85, CUDA graphs and radix cache on. W&B: full model, trained adapter, full model, synthetic adapters, 4-layer LoRA, merged BF16 reference, BF16 base.Full model,
moonshotai/Kimi-K3@f831ab66:SGLANG_K3_AR_FUSION=0(run): the fusion stays off, the trained adapter loads in 1 s, and decode matches prefill within 0.022 nats without an adapter and 0.025 with it.LoRA math against a reference, on the 4-layer prune
Pinaster/Kimi-K3-4layer-64experts:The two paths differ by 0.021 nats mean without any adapter, and the same server re-scoring the same text differs by 0.010 to 0.013 nats. A zero adapter stays within that range.
Unit tests on B300:
test_kimi_k3_lora_unit.py(new),test_mxfp4_marlin_lora.py(now also SiTU),test_deepseek_v4_lora_unit.pyandtest_laguna_hidden_dim_unit.pypass.Known issue: synthetic random adapters with very large deltas (about 0.3 nats of effect per token) make rare decode tokens disagree with the prefill re-score by up to 15 nats, on 0.2 to 0.9% of tokens. The trained adapter and the base model do not show this, and the 4-layer prunes do not reproduce it in 4096 tokens.
🤖 Generated with Claude Code