mirror of
https://github.com/kvcache-ai/sglang.git
synced 2026-11-05 01:07:39 +00:00
[PR #101] [CLOSED] [feat](kt): load STOCK ModelOpt MIXED_PRECISION NVFP4 checkpoints #102
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
kvcache-ai/sglang#102
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/kvcache-ai/sglang/pull/101
Author: @BlivionIaG
Created: 10/6/2026
Status: ❌ Closed
Base:
main← Head:feat/kt-native-mixed-precision-nvfp4📝 Commits (5)
a700676mixed precision config5be27f8per prefix dispatch1fb14a7nvfp4 lm heade360687sharded scalar scales66642cfkt expert counts📊 Changes
7 files changed (+313 additions, -14 deletions)
View changed files
📝
python/sglang/srt/layers/linear.py(+5 -0)📝
python/sglang/srt/layers/logits_processor.py(+64 -0)📝
python/sglang/srt/layers/moe/kt_ep_wrapper.py(+17 -3)📝
python/sglang/srt/layers/parameter.py(+26 -0)📝
python/sglang/srt/layers/quantization/modelopt_quant.py(+159 -4)📝
python/sglang/srt/layers/vocab_parallel_embedding.py(+6 -1)📝
python/sglang/srt/models/qwen3_5.py(+36 -6)📄 Description
What does this PR do?
Teaches the ModelOpt config to load a
MIXED_PRECISIONcheckpoint, and adds thedispatch needed to run one: per-prefix FP8/NVFP4 routing, a quantised
lm_head, andscalar per-tensor scales on sharded parameters.
MIXED_PRECISIONis what nvidia'sQwen3.6-35B-A3B-NVFP4release declares. Itshf_quant_config.jsonmaps per layer — 130 prefixes FP8, 161 NVFP4, andlm_headamong the NVFP4 ones — so the top-level
quant_algoalone cannot express whichmethod any given layer needs. Today such a checkpoint is rejected outright:
None of this requires editing the model files; the checkpoint is loaded as shipped.
The five commits
Each is independently reviewable and revertable.
MIXED_PRECISION; keep the checkpoint'sper-prefix scheme map instead of discarding it; derive
group_sizeand theexclusion list from the flat
config.jsonshape, wheregroup_sizelives pergroup inside
config_groupsand exclusions live underignore.LinearBaseto the method the checkpointdeclares for it. Two non-obvious cases: a fused module name (
qkv_proj,gate_up_proj) matches no key because the checkpoint declares the unfusedleaves, so it is resolved through them; and a prefix absent from the enumeration
means the producer left it at full precision, so it must stay unquantised
rather than take this config's NVFP4 default.
ParallelLMHeadis not aLinearBase, so it never reacheddispatch and was allocated at full width, which a nibble-packed weight cannot
fill. It now takes the NVFP4 method, and its projection runs on a dense CPU NVFP4
GEMM (companion ktransformers PR).
sharded parameter holds one entry per shard, so the strict shape assert rejects a
copy that is a valid broadcast. One helper replaces four duplicated call sites.
num_local_expertsmust describe the GPU-resident subsetbecause ModelOpt's
create_weightssizes its tensors from that attribute; andthe GPU MoE post-load is skipped when no expert is GPU-resident, since those
scales are allocated but only the CPU path ever fills them.
How was this tested?
On the stock checkpoint, unmodified (
config.json/hf_quant_config.jsonkeeptheir original mtimes):
not found in params_dictentries, where the same checkpointpreviously left
lm_head.input_scaleunreferenced;The capital of France is→ "…situated on the RiverSeine, in the region of Île de France", and
17 + 25 =→42;three of its scale tensors load as stored.
The change is +313/−14 across 7 files and applies cleanly to
main.Notes
_kt_-prefixed helpers follow the naming already used in these files (26 suchnames exist upstream, including module-level functions like
_kt_ep_predicate), so the additions match their surroundings.MIXED_PRECISIONpath is the general case; a homogeneous FP8 or NVFP4checkpoint is unaffected, since the scheme map is empty for those and dispatch
falls back to today's behaviour.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.