Skip to content

[AMD][MXFP4] Online MXFP4 quantization 1/N - dense and MOE models w. original BF16 weight - #18005

Merged
HaiShaw merged 42 commits into
sgl-project:mainfrom
fxmarty-amd:online-quark-mxfp4
Jun 3, 2026
Merged

HaiShaw merged 42 commits into
sgl-project:mainfrom
fxmarty-amd:online-quark-mxfp4

Conversation

@fxmarty-amd

@fxmarty-amd fxmarty-amd commented Jan 30, 2026 •

Copy link
Copy Markdown
Contributor

As per title. This PR implements online MXFP4 quantization (targeting Instinct MI350X/MI355X).

For both dense and MOE layers, online MXFP4 quantization is run in weight loaders by wrapping the original weight_loader with the online quantization step, before eventually calling it.

Example:

sglang serve --model-path Qwen/Qwen3.5-397B-A17B \
	--tensor-parallel-size 4 --trust-remote-code \
	--mem-fraction-static 0.85 --attention-backend aiter \
	--model-loader-extra-config '{"enable_multithread_load": true}' --quantization quark_mxfp4

Eval:

lm_eval --model local-completions \
	--model_args '{"model":"Qwen/Qwen3.5-397B-A17B","base_url":"[http://127.0.0.1:30000/v1/completions","num_concurrent":256}'](http://127.0.0.1:30000/v1/completions%22,%22num_concurrent%22:256%7D') \
    --tasks gsm8k \
    --gen_kwargs max_gen_toks=2048 \
    --num_fewshot 5

and

image

Reference BF16:
image

With online mxfp4 with --quantization quark_mxfp4:
image

image

Left to do:

  • Memory test
  • online MXFP4 MOE
  • Clean up server_args.py to allow only params that truly support online quantization through the arg --quantization
  • Test online MXFP4 MOE with TP>1
  • Investigate OOM issue in case --context-length is not specified
  • Update remaining test TODOs

Test Plan

pytest test/registered/quant/test_quark_mxfp4.py -s -vvvvv

CI States

Latest PR Test (Base): ✅ Run #26847060150
Latest PR Test (Extra): ❌ Run #26847059993

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @fxmarty-amd, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly extends the quantization capabilities by introducing online MXFP4 quantization, primarily aimed at AMD Instinct MI350X/MI355X. This feature enables the system to quantize model weights on-the-fly from standard higher-precision checkpoints, eliminating the need for pre-quantized models. The changes involve updating core configuration and weight loading logic to dynamically apply MXFP4 quantization, ensuring compatibility and proper handling of biases in the quantized operations.

Highlights

  • Online MXFP4 Quantization: Introduced support for online MXFP4 quantization, allowing models to be quantized dynamically from higher precision checkpoints, specifically targeting AMD Instinct MI350X/MI355X.
  • QuarkConfig Integration: Enhanced QuarkConfig to manage online quantization, including a new _create_online_mxfp4_config method for synthetic configuration generation and passing an is_prequantized flag.
  • Dynamic Weight Loading: Implemented a mechanism to perform dynamic MXFP4 quantization during the weight loading process by wrapping the original weight loader, converting loaded weights to MXFP4 on-the-fly.
  • Bias Support in MXFP4 GEMM: Modified the MXFP4 GEMM operation to correctly apply bias after the matrix multiplication, ensuring proper functionality for models with biases.
  • New Test Case: Added a dedicated test file (test_quark_mxfp4.py) to validate the functionality and accuracy of online MXFP4 quantization using a Qwen3-32B model on the GSM8K benchmark.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

Comment thread python/sglang/srt/server_args.py Resolved
"1",
"--log-level",
"debug",
"--disable-cuda-graph", # See https://github.com/sgl-project/sglang/issues/18002

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check if can be removed

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for online MXFP4 quantization, primarily targeting AMD Instinct hardware. The implementation correctly integrates the new quantization method by creating a synthetic configuration for online schemes and wrapping the weight loader to perform quantization on-the-fly. The addition of bias support in the apply_weights function is a good enhancement. I have identified a couple of areas for improvement regarding code clarity and maintainability, which I've detailed in the review comments. Overall, the changes are well-structured, and the inclusion of new tests is a great addition.

Comment thread python/sglang/srt/server_args.py Resolved
@github-actions github-actions Bot added the quant LLM Quantization label Feb 2, 2026
@fxmarty-amd
fxmarty-amd marked this pull request as ready for review February 2, 2026 14:54
Comment thread python/sglang/srt/server_args.py Resolved
@hubertlu-tw hubertlu-tw added the amd label Feb 3, 2026
Comment thread python/sglang/srt/server_args.py Resolved
@fxmarty-amd fxmarty-amd changed the title [MXFP4] Support online MXFP4 quantization in quark_w4a4_mxfp4.py [AMD][MXFP4] Support online MXFP4 quantization in quark_w4a4_mxfp4.py Feb 4, 2026
@ColinZ22

Copy link
Copy Markdown
Contributor

@amd-bot ci-status

@amd-bot

amd-bot commented May 26, 2026

Copy link
Copy Markdown

@ColinZ22

CI Status for PR #18005

PR: [AMD][MXFP4] Support online MXFP4 quantization of dense and MOE models, from original BF16 models
Changed files: python/sglang/srt/layers/quantization/quark/quark.py (+103/-3), quark/schemes/quark_w4a4_mxfp4.py (+68/-6), quark/schemes/quark_w4a4_mxfp4_moe.py (+77/-10), model_executor/model_runner.py (+14/-0), model_loader/loader.py (+24/-0), model_loader/weight_utils.py (+6/-0), configs/model_config.py (+2/-0), constants.py (+2/-0), quantization/__init__.py (+1/-0), server_args.py (+11/-6), test/registered/quant/test_quark_mxfp4.py (+188/-0), plus docs.

AMD: 1 failure (0 likely related) | Others: 12 failures (0 related)

AMD CI Failures

Job Test File Test Function Error Related? Explanation Log
stage-a-test-1-gpu-small-amd (linux-mi300-1gpu-sglang) test/registered/core/test_basic_sanity_eagle3.py (full file) TIMEOUT after 1200s (exit 255) 🟢 Unlikely EAGLE3 speculative-decoding sanity test; PR does not touch speculative or attention code, only quark MXFP4 quantization paths Log

Other CI Failures

Job Test File Test Function Error Related? Explanation Log
base-b-test-2-gpu-large (3) test/registered/hicache/test_hicache_storage_file_backend.py TestHiCacheStorageAccuracy.test_eval_accuracy AssertionError: 0.0 not greater than 0.6 : Initial accuracy should be reasonable 🟢 Unlikely HiCache storage backend accuracy test, unrelated to MXFP4 quantization Log
stage-b-test-1-npu-a2 (0) test/registered/ascend/.../test_npu_piecewise_graph_prefill.py TestPiecewiseGraphPrefillCorrectness.setUpClass Server process exited with code -9 (preceded by RuntimeError: No backend type associated with device type npu) 🟢 Unlikely NPU runtime / scheduler backend registration failure; PR is AMD/ROCm-only and doesn't touch NPU code Log
stage-b-test-1-npu-a2 (1) test/registered/ascend/.../test_npu_graph_tp1_bf16.py TestAscendGraphTp1Bf16.test_a_gsm8k RuntimeError: No backend type associated with device type npu 🟢 Unlikely NPU backend registration issue, unrelated to MXFP4 Log
stage-b-test-2-npu-a2 (0) test/registered/ascend/.../test_npu_tp2_bf16.py test_a_gsm8k RuntimeError: No backend type associated with device type npu 🟢 Unlikely Same NPU backend issue Log
stage-b-test-4-npu-a3 test/registered/ascend/.../test_npu_w4a4_quantization.py (+ HiCache MLA) various RuntimeError: No backend type associated with device type npu 🟢 Unlikely NPU backend registration issue; test_npu_w4a4_quantization is NPU-specific (Ascend) and unrelated to AMD MXFP4 Log
multimodal-gen-test-1-npu-a3 N/A (import error) N/A ImportError: torch_npu/lib/libnpu_profiler.so: undefined symbol: _ZNK3c1010TensorImpl15decref_pyobjectEv 🟢 Unlikely torch_npu / torch ABI mismatch in NPU container — infrastructure Log
multimodal-gen-test-2-npu-a3 N/A N/A same torch_npu ImportError 🟢 Unlikely Same NPU container ABI issue Log
multimodal-gen-test-8-npu-a3 N/A N/A same torch_npu ImportError 🟢 Unlikely Same NPU container ABI issue Log
Rollup jobs (pr-test-finish, pr-test-amd-finish, pr-test-npu-finish, pr-test-extra-finish, call-gate / pr-gate, wait-for-base-b, wait-for-stage-a-amd) — — downstream "needs" failures 🟢 Unlikely Aggregator/gate jobs marked failed solely because the underlying test jobs above failed —

Details

Verdict: No failures are likely caused by this PR. The PR adds AMD/ROCm-only online MXFP4 quantization (Quark + MOE/dense weight conversion paths) and a new test (test/registered/quant/test_quark_mxfp4.py). None of the failing shards in this run exercised test_quark_mxfp4.py, and the failure surfaces are in unrelated subsystems:

  • NPU jobs (8 failures): dominated by two infrastructure problems on the Ascend runners — (a) torch_npu C++ ABI mismatch (undefined symbol: _ZNK3c1010TensorImpl15decref_pyobjectEv), and (b) RuntimeError: No backend type associated with device type npu in the scheduler. These reproduce across multiple unrelated NPU tests (bf16 TP, HiCache MLA, sampling backends, w4a4 NPU quant, multimodal). The PR does not modify any NPU/Ascend code paths.
  • AMD MI300 stage-a-test-1-gpu-small-amd: a single timeout in test_basic_sanity_eagle3.py (EAGLE3 speculative-decoding sanity). The PR does not touch speculative decoding or attention; MXFP4 paths are dead code unless --quantization quark is set.
  • NVIDIA base-b-test-2-gpu-large (3): test_hicache_storage_file_backend.py accuracy collapse (0.0 vs 0.6 threshold) — HiCache file-storage subsystem, unrelated to quantization.

Recommendation: safe to ignore these for PR-correlation purposes; retry once for the AMD eagle3 timeout and the HiCache accuracy test in case they're flakes. The NPU breakage is a runner-wide infrastructure issue and needs to be fixed in CI environment, not in this PR.

Generated by amd-bot using Claude Code CLI

@ColinZ22

ColinZ22 commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

@amd-bot ci-status

@amd-bot

amd-bot commented Jun 2, 2026

Copy link
Copy Markdown

@ColinZ22

CI Status for PR #18005

PR: [AMD][MXFP4] Support online MXFP4 quantization of dense and MOE models, from original BF16 models
Head: 6ee12819 by fxmarty-amd
Changed files (12): python/sglang/srt/layers/quantization/quark/{quark.py,schemes/quark_w4a4_mxfp4.py,schemes/quark_w4a4_mxfp4_moe.py}, python/sglang/srt/{model_executor/model_runner.py,model_loader/loader.py,model_loader/weight_utils.py,configs/model_config.py,constants.py,server_args.py,layers/quantization/__init__.py}, test/registered/quant/test_quark_mxfp4.py, docs_new/docs/advanced_features/quantization.mdx

AMD: 4 failures (0 likely related) | Others: 4 failures (0 likely related)

AMD CI Failures

Job Test File Test Function Error Related? Explanation Log
stage-b-test-1-gpu-small-amd (7) test/registered/perf/test_vlm_perf_5090.py TestVLMPerf5090.test_vlm_offline_throughput perf threshold failure 🟢 Unlikely VLM perf test on a 5090; unrelated to MXFP4/Quark code paths Log
stage-b-test-1-gpu-small-amd (8) test/registered/scheduler/test_priority_scheduling.py TestPrioritySchedulingMultipleRunningRequests.test_priority_scheduling_preemption_token_offset_calculation scheduler test error 🟢 Unlikely Priority scheduling test, no overlap with quantization changes Log
stage-b-test-1-gpu-small-amd-nondeterministic test/registered/models/test_vlm_models.py N/A (timeout after 1800s) timeout 🟢 Unlikely VLM models suite timed out; PR adds gated MXFP4 logic only Log
stage-b-test-1-gpu-large-amd (1) test/registered/perf/test_bench_serving_1gpu_part2.py N/A (timeout after 2700s) timeout 🟢 Unlikely Serving perf benchmark; PR's loader/model_runner additions are gated on quantization == "quark_mxfp4" or only emit DEBUG logs Log

Other CI Failures

Job Test File Test Function Error Related? Explanation Log
base-b-test-2-gpu-large (3) test/registered/hicache/test_hicache_storage_file_backend.py TestHiCacheStorageAccuracy.test_eval_accuracy ERROR 🟢 Unlikely HiCache storage backend; unrelated to quark/MXFP4 Log
multimodal-gen-test-1-npu-a3 sglang/multimodal_gen/test/server/ascend/test_server_1_npu.py TestDiffusionServerOneNpu.test_diffusion_generation[wan2_1_t2v_1.3b_1_npu] Performance validation failed 🟢 Unlikely NPU diffusion perf test, separate code paths Log
multimodal-gen-test-2-npu-a3 sglang/multimodal_gen/test/server/ascend/test_server_2_npu.py TestDiffusionServerTwoNpu.test_diffusion_generation[qwen_image_t2i_2npu] Performance validation failed 🟢 Unlikely NPU diffusion perf test, separate code paths Log
multimodal-gen-test-8-npu-a3 sglang/multimodal_gen/test/server/ascend/test_server_8_npu.py TestDiffusionServerEightNpu.test_diffusion_generation[wan2_2_t2v_14b_w8a8_8npu] Performance validation failed 🟢 Unlikely NPU diffusion perf test, separate code paths Log

Details

None of the failures touch code paths exercised by this PR:

  • PR scope is narrow: the new model_runner.py block is guarded by hasattr(self.model, "quant_config") and ... and self.server_args.quantization is not None; the weight_utils.py branch only fires for quantization == "quark_mxfp4"; model_config.py/server_args.py only add "quark_mxfp4" to existing lists; new scheme files only execute when that quant method is selected.
  • The only always-on additions are DEBUG-level memory logging in model_loader/loader.py::load_weights_and_postprocess (calls torch.cuda.max_memory_allocated() and get_available_gpu_memory() under is_cuda_alike()). These do not affect functional correctness and would not produce the observed timeouts, perf-threshold misses, or unrelated assertion errors in VLM/scheduler/HiCache/NPU-diffusion tests.
  • Failure patterns observed (perf timeouts, VLM perf thresholds, NPU diffusion perf validation, HiCache storage accuracy, priority-scheduling preemption) match known unrelated CI noise categories on AMD/NPU.

Recommendation: these failures appear to be pre-existing/infra/flake issues on AMD + NPU runners. A rerun is reasonable; no PR code changes appear required to address them. If a maintainer wants high confidence, the CI Monitor task can bisect the AMD perf/VLM timeouts against main.

Generated by amd-bot using Claude Code CLI

@ColinZ22

ColinZ22 commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

@amd-bot ci-status

@amd-bot

amd-bot commented Jun 3, 2026

Copy link
Copy Markdown

@ColinZ22

CI Status for PR #18005

PR: [AMD][MXFP4] Support online MXFP4 quantization of dense and MOE models, from original BF16 models
Changed files: quark/quark.py (+103/-3), quark/schemes/quark_w4a4_mxfp4.py (+68/-6), quark/schemes/quark_w4a4_mxfp4_moe.py (+77/-10), model_runner.py (+14/-0), loader.py (+24/-0), weight_utils.py (+6/-0), server_args.py (+11/-6), model_config.py (+2/-0), constants.py (+2/-0), quantization/__init__.py (+1/-0), test/registered/quant/test_quark_mxfp4.py (+188/-0, new), docs/quantization.mdx (+13/-1)

AMD: 3 failures (0 likely related) | Others: 8 failures (0 related — all cascade-skips from 1 infra failure)

AMD CI Failures

Job Test File Test Function Error Related? Explanation Log
stage-c-test-large-8-gpu-amd (mi325, 2) test/registered/amd/test_kimi_k2_instruct.py test_a_gsm8k KeyError: 'answer' after 52-min gsm8k run, then server died → ConnectionRefusedError on /flush_cache 🟢 Unlikely Kimi K2 BF16 e2e gsm8k test; does not load Quark/MXFP4 quantization paths added by this PR. Server crashed mid-run (independent of code under test). log
stage-b-test-1-gpu-small-amd-nondeterministic test/registered/models/test_vlm_models.py VLM MMMU runner (MiniCPM-V-2_6) FileNotFoundError: No JSON result files found in /tmp/test_vlm_mmmu_openbmb_MiniCPM-V-2_6_* + IndexError: list index out of range 🟢 Unlikely MiniCPM-V VLM MMMU eval; missing artifact dir is an infra/runner issue, not related to MXFP4 changes. log
stage-b-test-large-8-gpu-mi35x-disaggregation-amd test/registered/amd/disaggregation/test_mori_transfer_engine_e2e.py test_generate_smoke_hybrid_mamba AssertionError: 500 != 200 : Internal Server Error on /generate via mini_lb; backend 127.0.0.1:11120 refused connections 🟢 Unlikely Mori disaggregation hybrid-mamba smoke test; exercises PD-disagg/Mamba path, not Quark MXFP4. log

Other CI Failures

Job Test File Test Function Error Related? Explanation Log
base-c-test-8-gpu-h200 (0) N/A N/A RuntimeError: CUDA driver initialization failed, you might not have a CUDA gpu (host-level, before any test ran) 🟢 Unlikely H200 runner CUDA driver init failure — pure infrastructure. Triggered fast-fail cascade across the 7 other base-c jobs below. log
base-c-test-8-gpu-h200 (1) N/A N/A Fast-fail: skipping — root cause job(s): base-c-test-8-gpu-h200 (0) 🟢 Unlikely Cascade-skip from h200 (0). log
base-c-test-8-gpu-h200 (2) N/A N/A Cascade-skip 🟢 Unlikely Cascade-skip from h200 (0). log
base-c-test-4-gpu-b200 (1) N/A N/A Cascade-skip 🟢 Unlikely Cascade-skip from h200 (0). log
base-c-test-4-gpu-b200 (2) N/A N/A Cascade-skip 🟢 Unlikely Cascade-skip from h200 (0). log
base-c-test-4-gpu-b200 (3) N/A N/A Cascade-skip 🟢 Unlikely Cascade-skip from h200 (0). log
base-c-test-4-gpu-h100 (1) N/A N/A Cascade-skip 🟢 Unlikely Cascade-skip from h200 (0). log
base-c-test-4-gpu-h100 (2) N/A N/A Cascade-skip 🟢 Unlikely Cascade-skip from h200 (0). log

Aggregator jobs pr-test-finish, pr-test-npu-finish, finish are red only because they roll up the above failures — no independent signal.

Details

None of the failures touch code paths added by this PR (quark/quark.py, the two quark_w4a4_mxfp4*.py schemes, the Quark online-quant glue in loader.py / model_runner.py / weight_utils.py, or the new --quantization quark_mxfp4 server arg). The failing tests load BF16 Kimi-K2, MiniCPM-V VLM eval, and a Mamba PD-disagg smoke test — none invokes the Quark MXFP4 path.

  • All 8 NVIDIA base-c failures trace back to a single H200 runner where torch.cuda failed to initialize before any sglang code ran (base-c-test-8-gpu-h200 (0)). The fast-fail logic then cascade-skipped the other 7 base-c jobs. Pure infrastructure — request a re-run.
  • AMD 8-GPU Kimi K2 gsm8k: ran to 100% (1319/1319, ~52 min), then a parsed answer was missing (KeyError: 'answer') and the retry attempt hit a dead server (Connection refused on /flush_cache port 11000). Smells like a server OOM/crash at end of run on the BF16 Kimi K2 model, unrelated to MXFP4. Re-run recommended; if it recurs without this PR, file separately.
  • AMD 1-GPU VLM MMMU (MiniCPM-V-2_6): the per-model subprocess produced no JSON output dir; harness then raises FileNotFoundError / IndexError. Looks like an infra/runner artifact issue on this nondeterministic shard.
  • AMD 8-GPU mi35x disaggregation (Mori hybrid-mamba): prefill/decode backend at 127.0.0.1:11120 never came up; mini_lb proxied a 500. Hybrid-mamba PD-disagg path, no overlap with this PR.

Verdict: safe to retry the failing jobs. None of the red signals appear to be caused by changes in this PR.

Generated by amd-bot using Claude Code CLI

@HaiShaw HaiShaw left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HaiShaw HaiShaw changed the title [AMD][MXFP4] Support online MXFP4 quantization of dense and MOE models, from original BF16 models [AMD][MXFP4] Online MXFP4 quantization 1/N - dense and MOE models w. original BF16 weight Jun 3, 2026
@HaiShaw
HaiShaw merged commit 293816a into sgl-project:main Jun 3, 2026
180 of 204 checks passed
Chronostasys pushed a commit to MindLab-Research/sglang that referenced this pull request Aug 24, 2026
…original BF16 weight (sgl-project#18005)

Co-authored-by: Bowen Bao <[email protected]>
Co-authored-by: Colin Zeng <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

amd documentation Improvements or additions to documentation quant LLM Quantization run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants