[AMD][Quantization] Online MXFP4 quantization 4/N - NVFP4 to MXFP4 Online Requantization on AMD GPUs - #29328
Conversation
…gic to match vLLM
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
|
Main PR checks workflow is completed with success; All PR changes verified and passed tests ( All other test failures shown are unrelated (only 2 NPU related tests fail due to infra timeout issues), and all code paths used in PR are verified locally with Pending/in-progress AMD stage-c jobs add additional AMD coverage, but are unrelated to and do not block this change, and completed tests in that suite are already passing (e.g. stage-c-test-large-8-gpu-amd part 0). All PR changes are validated and ready for merge. |
BowenBao
left a comment
There was a problem hiding this comment.
LGTM, and thanks for checking CI and testing locally.
|
let's try a few smoke tests on h100 / h200, make sure no regressions there. @ColinZ22 |
Ran the following smoke tests using H100 to verify modified shared files: Nvidia CI
|
HaiShaw
left a comment
There was a problem hiding this comment.
Define a static and hidden REQUANTIZATION_METHODS = ["quark_mxfp4"] seems to be fragile and not generic, consider an explicit knob maybe?
| "scale_format": "e8m0", | ||
| }, | ||
| "output_tensors": None, | ||
| "bias": None, |
There was a problem hiding this comment.
In the MXFP4 and FP8 quant specs here, None means that the tensor category is not quantized. Currently both Quark linear and MoE does not support output tensor and bias quantization, so the specs have to specify None for both.
| "is_dynamic": is_dynamic_input, | ||
| }, | ||
| "output_tensors": None, | ||
| "bias": None, |
There was a problem hiding this comment.
In the MXFP4 and FP8 quant specs here, None means that the tensor category is not quantized. Currently both Quark linear and MoE does not support output tensor and bias quantization, so the specs have to specify None for both.
| hidden_size=hidden_size, | ||
| intermediate_size_per_partition=intermediate_size_per_partition, | ||
| original_weight_loader=original_weight_loader, | ||
| extra_weight_attrs=extra_weight_attrs, |
There was a problem hiding this comment.
Are we certain that no with_bias in this path?
There was a problem hiding this comment.
Yes, this is consistent with the ModelOpt NVFP4 MoE loader, which also registers no bias params.
|
/rerun-failed-ci |
1 similar comment
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
/rerun-failed-ci |
|
All CI failures are all unrelated to PR changes:
All PR code paths passing checks (test_quark_config.py and test_quark_mxfp4.py on MI35x), all other base tests passing. |
Summary
Adds support in SGLang for loading and inference for ModelOpt (and Quark) NVFP4 checkpoints by dequantizing the supplied NVFP4 weights and requantizing them to MXFP4 at load time to allow efficient inference using supported AMD hardware (e.g. AMD MI355x).
Enabled via
--quantization quark_mxfp4. Weights dequantized then requantized to MXFP4 during loading, so the resulting model occupies MXFP4 memory without ever holding a full-precision copy. Also includes the config-routing and shared-expert-fusion fixes needed to load ModelOpt exports across various architectures using the existing SGLang AMD Quark integration.Modifications
Online Requantization Path
layers/quantization/quark/quark.py:_detect_nvfp4_sourcedetects ModelOpt and AMD Quark NVFP4 layouts;_parse_nvfp4_excludesextracts producer exclude lists;from_configrouting gated onrequantization_method._maybe_disable_shared_experts_fusiondelegates to the existingcan_fuse_shared_expert()to correctly handleshared_expert_gateandmtp.exclusions.layers/quantization/quark/schemes/quark_w4a4_mxfp4.py: NVFP4 linear scheme:_create_weights_from_nvfp4allocates NVFP4 staging buffers directly on device, loads all source shards, then dequant-requant to MXFP4 once all bytes are present. Registers (and discards) the NVFP4 per-tensorinput_scaleslot since MXFP4 uses dynamic activation quantization.layers/quantization/quark/schemes/quark_w4a4_mxfp4_moe.py: NVFP4 fused-MoE scheme: per-expert weight/scale registration, online expert-wise dequant-requant, no-opinput_scaleslots for w13/w2.layers/quantization/dequantization.py,layers/quantization/online_quantization.py,layers/quantization/quark/utils.py:Nvfp4SourceConfig+ dequant helpers andCopyNumelCounterto track progressive shard loadingFixes required to load ModelOpt exports
model_loader/weight_utils.py): Some ModelOpt NVFP4 checkpoints store quant metadata only inhf_quant_config.json; others duplicate it inconfig.json.get_quant_confignow readshf_quant_config.jsonpreferentially when present and FP4-typed, routing throughfrom_config.layers/quantization/quark/quark.py): Some NVFP4 checkpoints keep shared experts in BF16 while routed experts are FP4. Shared-expert fusion remapsmlp.shared_expertsinto the quantizedFusedMoE, causing a shape mismatch.QuarkConfig.__init__now calls_maybe_disable_shared_experts_fusionwhich delegates tocan_fuse_shared_expert()(which is the same detection path introduced in [AMD] Qwen3.5 MXFP4 breaks after shared expert fusion is enabled #22948 and scoped to Quark in [AMD] move shared expert check function to quark #27057) and setsdisable_shared_experts_fusionglobally before model construction.Tests
test/registered/quant/test_quark_mxfp4.py: AddedTestNVFP4ToMXFP4MOETP1testing NVFP4→MXFP4 MoE requantization accuracy onnvidia/Qwen3-30B-A3B-NVFP4.Docs
docs_new/docs/advanced_features/quantization.mdx: documents the NVFP4-MXFP4 requant path (supported checkpoint layouts, and example command.Accuracy Tests
All numbers below are obtained using lm_eval using SGLang backend with
--quantization quark_mxfp4on AMD MI355X GPUs. (max_gen_toks=32768)GSM8k (lm_eval, flexible-extract)
CI States
Latest PR Test (Base): ✅ Run #31758298579
Latest PR Test (Extra): ❌ Run #31758298347