This repository (sglang_quant_eval) researches and implements MXFP8 / MXFP4 quantization adaptation for SGLang on Huawei Ascend NPU hardware — covering both the LLM serving side (srt) and the Diffusion side (multimodal_gen), across Dense and MoE layers, in online and offline modes.
- Target: Adapt SGLang's quantization system for Huawei Ascend NPU using microscaling FP formats (MXFP8, MXFP4), spanning W8A8 / W4A8 / W4A4 schemes.
- Models: LLMs (e.g. Qwen3, Qwen3.5) via
srt, and Diffusion models (e.g. Wan2.2) via themultimodal_gensubsystem. - Quant modes: Online (quantize FP16/BF16 at load time) and Offline (load
msmodelslimpre-quantized weights). - Related Issues: sgl-project/sglang#14424 (Diffusion), sgl-project/sglang#21584 (LLM Qwen3).
- Fork: https://github.com/TallMessiWu/sglang
sglang/— Local, gitignoredgit worktreecontainer for the SGLang fork.qwen3.5_dense_w8a8/is the main clone that owns the shared.git; the other active PR branches are sibling worktrees. Every SGLang branch that will be modified must have its own worktree directly under this directory. Seedocs/branches.mdfor the live mapping.MindIE-SD/— Huawei's MindIE-SD source (submodule, tracksdev); primary reference for Ascend NPU MXFP8/FP8 operations on the Diffusion side.msmodelslim/— Huawei's msmodelslim source (submodule, tracksmaster); reference for the offline MXFP4/MXFP8 weight export format.vllm-ascend/— vLLM Ascend backend (submodule, tracksmain); primary reference for LLM-side MXFP adaptation.sgl-kernel-npu/— NPU kernel submodule. Its developmentoriginisTallMessiWu/sgl-kernel-npu, whileupstreamissgl-project/sgl-kernel-npu; it supplies stable NPU APIs used by SGLang.diffusion/&llm/— Run scripts, quant-description JSONs, and PR notes for Diffusion (Wan2.2) and LLM (Qwen3/3.5) inference & quantization.docs/— Project docs:branches.md(live PR/worktree/remotes),quantization-overview.md(capability matrix and code paths),known-pitfalls.md,sgl-kernel-npu-build.md,npu-api/, andagents/.AGENTS.md— Concise AI-assistant operating rules and links (CLAUDE.mdis a symlink to it); volatile status lives indocs/branches.md..agents/skills/— Custom agent skills (.claude/skillsis a symlink to this directory).README.md/README_zh.md— Project guide in English and Chinese.
Two orthogonal quantization paths, both leveraging torch_npu NPU kernels:
- Online quantization: Load FP16/BF16 weights and quantize on the fly inside
process_weights_after_loading. Triggered by--quantization mxfp8/mxfp4/mxfp_w4a8. - Offline quantization (msmodelslim): Load pre-quantized weights produced by Huawei's
msmodelslimtool. Triggered by--quantization modelslim; the scheme is auto-detected fromquant_model_description.json.
Core torch_npu APIs used include npu_dynamic_mx_quant + npu_quant_matmul (MXFP8 / W4A8) and npu_dynamic_dual_level_mx_quant + npu_dual_level_quant_matmul (dual-level MXFP4 / W4A4). See docs/quantization-overview.md for the implementation-status matrix.
- Hardware: Huawei Ascend NPU. Exact support is path-specific: dual-level MXFP4 and the current MXFP MoE grouped-matmul paths require Ascend 950 (A5), while several dense MXFP paths also support A2/A3. Verify the target operator instead of inferring support from the format name alone.
- Software: CANN ≥ 8.0.RC3 (required for
npu_dynamic_mx_quant/ MXFP8); MXFP4 needs a recenttorch_npu(e.g.2.10.0.postX). - Dependencies:
torch,torch_npu, and the usual SGLang dependencies.
Custom skills live in .agents/skills/ (with .claude/skills symlinked to it). Highlights:
sglang-quant-lookup,trace-quant-path— find / trace SGLang quantization implementations.mxfp4-impl-ref,mxfp8-impl-ref— full MXFP4/MXFP8 implementation references (API signatures, shapes, gotchas).npu-api-check,compare-impl— analyzetorch_npuAPI usage; compare against MindIE-SD & vllm-ascend.sgl-kernel-npu-dev— inspect remotes/submodule state and build or validate 910/950 target-specific kernel wheels.check-issue— check the status of SGLang issues/PRs related to this work.gitmoji-commit— generate Gitmoji-compliant commit messages.- Plus engineering/workflow skills (
diagnose,tdd,triage,handoff, …). Browse.agents/skills/for the full set.