mirror of
https://github.com/kvcache-ai/sglang.git
synced 2026-11-05 01:07:39 +00:00
[PR #103] [perf] KT: the shard loaders do not read the CPU experts' checkpoint tensors #101
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#101
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/103
Author: @05yuki
Created: 10/13/2026
Status: 🔄 Open
Base:
main← Head:launch-skip-cpu-experts📝 Commits (1)
503c270[perf] KT: the shard loaders do not read the CPU experts' checkpoint tensors📊 Changes
2 files changed (+44 additions, -1 deletions)
View changed files
📝
python/sglang/srt/layers/moe/kt_ep_wrapper.py(+16 -0)📝
python/sglang/srt/model_loader/weight_utils.py(+28 -1)📄 Description
With a KT EP wrapper the GPU MoE
weight_loaderdrops a routed expert's tensors unread when the GPU-experts masks place that expert on the CPU (fused_moe_triton/layer.py). The shard loaders had already materialised them:multi_thread_safetensors_weights_iteratorand the buffered one build{k: f.get_tensor(k) for k in f.keys()}per shard, and the single-thread iteratorget_tensors every key, so the whole expert set goes through RAM once per rank for nothing. Qwen3.8-Flash-Next NVFP4 (512 experts a layer, 32 on the GPU): 158 GB read per TP rank, 107 s of a 293 s weight load. DeepSeek V4.1: 60 GB, the shard phase 102 → 18 s.The loaders now ask before
get_tensor.kt_ep_wrapper.checkpoint_expert_is_cpu(layer_idx, expert_id)answers from the same masks theweight_loaderuses; it isFalsewhenever the wrapper is disabled (a draft model's load) or no masks exist, so nothing changes for those. The key pattern (KT_LOAD_SKIP_CPU_EXPERTS_RE, default[model.]layers.<L>.<...>.experts.<E>.) coversmlp/ffn/block_sparse_moecontainers with or without amodel.prefix; shared experts and packed expert tensors do not match it.KT_LOAD_SKIP_CPU_EXPERTS=0restores the full read.Prompt NLL on three fixed texts (teacher-forced input logprobs) is identical to four decimals with and without the skip on Flash-Next NVFP4, DeepSeek V4.1, V4-Flash-Vision and MiMo-V2.6-Flash.
🤖 Generated with Claude Code
https://claude.ai/code/session_01C2UBZdnrDZSBh8yQz8rc9g
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.