Implement online nvfp4 quantization - #26083
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the per_token_nvfp4 online quantization method for MoE checkpoints on NVIDIA Blackwell GPUs, supporting BF16, FP16, and FP8 weights. Key changes include the implementation of ModelOptPerTokenNvFp4FusedMoEMethod for dynamic weight quantization during loading, the addition of the SGLANG_FP4_IGNORED_LAYERS environment variable for layer exclusion, and updates to the FlashInfer TRTLLM MoE runner. Feedback highlights a critical unpacking error in nvfp4_quantize that would cause a runtime crash, a potential overflow in the nvfp4_max scale calculation, memory efficiency concerns regarding unnecessary FP32 conversions during weight processing, and thread-safety issues when modifying environment variables.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces the per_token_nvfp4 online quantization method for NVIDIA Blackwell GPUs, enabling on-the-fly quantization of MoE expert weights from BF16, FP16, or FP8 checkpoints. Key additions include the ModelOptPerTokenNvFp4FusedMoEMethod class, the SGLANG_FP4_IGNORED_LAYERS environment variable, and integration with the FlashInfer TRTLLM backend. Reviewers identified a missing import and the use of an undefined function per_tensor_dequantize (recommending dequantize_fp8 instead), and suggested optimizing the _weight_scale_2_from_amax method by performing calculations in Python to avoid unnecessary GPU operations.
|
Testing fp8 requantization on DeepSeek V3.2:
Ran gsm8k 3 times: |
|
MTP drafter should follow the online NVFP4 path without extra handling in the current DeepSeek EAGLE setup. The relevant flow is:
So with |
b08dbc8 to
5e1c052
Compare
|
/gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
/gemini review |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
/tag-and-rerun-ci |
Use --quantization nvfp4_per_token_activation as the only public spelling for the online NVFP4 MoE path. Rename the quant config, internal marker, server validation, registered tests, and docs_new references to make clear that per-token applies to activations rather than weights. Validation: pre-commit run --all-files; remote TestNvFp4PerTokenActivationConfig registry unit test; remote TestFlashinferTrtllmGenMoeBackendOnlineNvFp4PerTokenActivation::test_gsm8k scored 0.960.
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
/rerun-failed-ci |
3 similar comments
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
all nv base ci passed |
Edwardf0t1
left a comment
There was a problem hiding this comment.
LGTM, left a minor comment.
| "modelopt_fp8": ["modelopt"], | ||
| "modelopt_fp4": ["modelopt"], | ||
| "modelopt_mixed": ["modelopt"], | ||
| "nvfp4_online": ["fp8"], |
There was a problem hiding this comment.
why nvfp4_online maps to fp8?
There was a problem hiding this comment.
This allows an FP8 checkpoint to be served with --quantization nvfp4_online. For eligible MoE expert weights, SGLang dequantizes the serialized FP8 weight to BF16 during loading, then requantizes it to NVFP4.
Motivation
@HumansAnd
Add online NVFP4 MoE weight quantization under the
--quantization nvfp4_onlineinterface.After #22918, FlashInfer TRTLLM MoE can use runtime per-token activation scaling, so SGLang no longer needs a calibrated static activation FP32 scale for this path. The
nvfp4_onlineinterface is explicitly a load-time conversion mode: weights still use static NVFP4 block scales plus static per-tensor FP32 scales, while activations use runtime per-token FP32 scales. This makes it possible to load BF16/FP16 or FP8 checkpoints and quantize eligible MoE expert weights to NVFP4 during weight loading, instead of requiring a pre-quantized NVFP4 checkpoint.The intended initial scope is narrow: Blackwell GPUs only, MoE only, no dense linear quantization, and only the FlashInfer TRTLLM MoE backends (
flashinfer_trtllmandflashinfer_trtllm_routed).Modifications
nvfp4_onlinequantization method for online NVFP4 MoE expert weight quantization.SGLANG_FP4_IGNORED_LAYERSso users can keep selected MoE layers or shared experts high precision.flashinfer_trtllmwhen--quantization nvfp4_onlineis used without an explicit backend, and error out for unsupported backend, hardware, or MoE TP configurations.Accuracy Tests
DeepSeek V3.2 fp8 requantization:
Also there is an added test
TestFlashinferTrtllmGenMoeBackendNvFp4Onlinethat partially requantizesQwen/Qwen3-Next-80B-A3B-Instruct-FP8with:Speed Tests and Profiling
Checklist
Review and Merge Process
/tag-and-rerun-ci,/tag-run-ci-label,/rerun-failed-ciCI States
Latest PR Test (Base): ✅ Run #27166586377
Latest PR Test (Extra): ❌ Run #27166586161