Repository navigation
[AMD][Quantization] Online MXFP4 quantization 2/N - FP8 to MXFP4 requantization on AMD GPUs - #18182
Conversation
Summary of ChangesHello @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 enhances the quantization capabilities by introducing online requantization from FP8 checkpoints to MXFP4 layers, primarily for AMD GPUs. The changes allow for greater flexibility in deploying models by converting them to a more memory-efficient format on-the-fly, addressing the growing need for efficient large language model inference on specialized hardware. The implementation involves a series of modifications across the quantization configuration, weight loading mechanisms, and the introduction of new dequantization and memory tracking utilities. Highlights
🧠 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. Changelog
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request introduces support for online requantization from FP8 to MXFP4 on AMD GPUs, which is a valuable feature for deploying models with FP8 checkpoints. The changes are well-structured, including a significant and logical refactoring of Fp8LinearMethod to improve modularity and enable code reuse for online quantization scenarios. New utilities for dequantization and online quantization tracking have been added, and the configuration handling has been updated to support these new quantization paths. The addition of comprehensive tests covering memory usage and accuracy for both dense and MoE models is also a great inclusion. I have a couple of suggestions for improvement, one related to a potential typo in the server arguments and another regarding a possible inefficiency in the weight loading logic.
|
|
||
| return online_mxfp4_weight_loader | ||
|
|
||
| def get_online_fp8_to_mxfp4_weight_loader( |
There was a problem hiding this comment.
I'm thinking about scalability, the design for this part needs discussion.
There was a problem hiding this comment.
I agree. The flow I thought about is:
- The weight initialization is abstracted in static methods in
LinearBaseMethodsubclasses, likeFp8LinearMethod.create_fp8_weight_and re-usable elsewhere as e.g. here increate_weightsin order to load FP8 weights
with torch.device("meta"):
Fp8LinearMethod.create_fp8_weight_(
layer=layer,
...
)- The weight loader is in charge of progressively materializing weights on device, loading the weights in the given checkpoint precision, and requantizing them. At the moment, this all happens in
online_fp8_to_mxfp4_weight_loader, but it could be further broken down in re-usable blocks.
There was a problem hiding this comment.
late response, but since main complexity here resides within quark, I think it's okay for a first version.
We will have a better understanding of what to abstract more when we add more support beyond fp8.
|
@amd-bot ci-status |
CI Status for PR #18182Merge verdict: ❌ Not ready. The two real failures ( Caution The new test that validates this PR's feature did not run. Changed files: 15 ( AMD: 1 real failure (0 related) + 2 cascades · Others: 1 real failure (0 related) + 2 cascades · Many NVIDIA/XPU/NPU jobs still pending (run NOT complete) AMD CI Failures
Other CI Failures
Details / what to do before merge
Generated by amd-bot using Claude Code CLI |
|
@amd-bot ci-status |
CI Status for PR #18182Warning A code path changed by this PR was not tested on AMD — re-run AMD CI before merging. A green / "Unlikely related" status below does not mean it's verified.
AMD: 0 failures · Others: 3 failures (0 likely related) AMD: 0 passed, 3 pending | Others: 7 passed Other CI Failures
Generated by amd-bot using Claude Code CLI |
|
Not sure why we get: |
|
@amd-bot ci-status |
CI Status for PR #18182Merge verdict: Not yet safe to merge. Zero failures are caused by this PR's code — every red job is repo-wide infra (AMD Caution This PR's core path ( Changed files: AMD: did not run (2 workflows AMD CI Failures
Other CI Failures
(Also: call-gate / pr-gate (Extra base) — same Details / what to do before merge
Generated by amd-bot using Claude Code CLI |
|
@fxmarty-amd please add CI test case in follow-up PR. |
| self.server_args.quantization is not None | ||
| and isinstance(quantized_layers, tuple) | ||
| and len(quantized_layers) == 2 | ||
| hasattr(self.model, "quant_config") | ||
| and hasattr(self.model.quant_config, "quantized_layers") | ||
| and self.server_args.quantization is not None |
There was a problem hiding this comment.
This removed the tuple check, so modelopt’s quantized_layers dict gets unpacked here and crashes
|
After inspection, all The failing @b8zhong @mmangkad @HaiShaw @BowenBao We should consider adding a unit smoke test for #28291 relands this PR removing online quantization logging logic from Beyond the code quality, I believe the CI could be improved in two ways:
|
…antization on AMD GPUs (sgl-project#18182) Co-authored-by: Bowen Bao <[email protected]> Co-authored-by: HAI <[email protected]>
Motivation
Popular recent language models have been released directly as FP8 checkpoints (e.g. https://huggingface.co/moonshotai/Kimi-K2-Instruct-0905 or https://huggingface.co/Qwen/Qwen3-32B-FP8). As part of proposed improvements (#18005) to MXFP4 quantization targeting Instinct MI350X and MI355X GPUs, this PR implements online quantization from FP8 checkpoint to MXFP4 layers.
This PR is a follow up to #18005 , which implemented online BF16 -> MXFP4 quantization.
Example usage:
python3 -m sglang.launch_server --model-path Qwen/Qwen3-30B-A3B-Instruct-2507-FP8 \ --tensor-parallel-size 1 \ --context-length 3000 \ --quantization quark_mxfp4This PR has been tested against
MiniMaxAI/MiniMax-M2.1,deepseek-ai/DeepSeek-V3.2andmoonshotai/Kimi-K2-Instruct-0905as seen in the unit test.Modifications
Allow a different
args.quantizationcompared to the serializedquant_methodin config.json.Accuracy Tests
See the unit test.
Left to do
QuarkW4A4MXFp4MoEMethoddeepseek-ai/DeepSeek-V3.2andmoonshotai/Kimi-K2-Instruct-0905--context-lengthis not specifiedexcludeCI States
Latest PR Test (Base): ❌ Run #27459884924
Latest PR Test (Extra): ❌ Run #27459884825