Repository navigation
[AMD] Fix Load and Inference of MLA models with Quark PTPC FP8 attention on ROCm #28734
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
HaiShaw
merged 27 commits into
sgl-project:main
from
ColinZ22:glm52-mxfp4-ptpcfp8-attn-fixes
Sep 29, 2026
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
35103d5
fix: load and run GlmMoeDsaForCausalLM with quark mxfp4+ptpcfp8-attn …
ColinZ22 f4585de
defensive check and style
ColinZ22 051bae4
avoid unnecessarily quantizing to group-128 FP8 for quark FP8 path
ColinZ22 8ad495b
merge main
ColinZ22 8395177
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 d1fa68b
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 e763e2b
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 f137031
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 f078a89
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 09c730a
fix merge typo
ColinZ22 1f228ad
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 9d16fe7
review fixes
ColinZ22 36d8c2e
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 bdc4db3
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 7d06bc4
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 da302c9
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 e08143c
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 aa23525
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 7645794
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 f078967
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 2a6eaf9
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 651c3a8
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 1fc359e
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 0b73fb9
removed unused function
ColinZ22 4608fa9
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 fa66091
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 5803d11
Merge branch 'main' into glm52-mxfp4-ptpcfp8-attn-fixes
ColinZ22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
test/registered/unit/layers/quantization/test_quark_w8a8_fp8_ptpc.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """CPU-only regression tests for the Quark PTPC-FP8 (W8A8 FP8) MLA attention fix. | ||
|
|
||
| These guard the hardware-independent pieces of the fix that enables loading and | ||
| running MLA models (e.g. GlmMoeDsaForCausalLM) with Quark-quantized PTPC FP8 | ||
| attention on ROCm/gfx95. | ||
| """ | ||
|
|
||
| from sglang.test.ci.ci_register import register_cpu_ci | ||
|
|
||
| register_cpu_ci(est_time=6, suite="base-a-test-cpu") | ||
|
|
||
| import unittest | ||
|
|
||
| import torch | ||
|
|
||
| from sglang.srt.layers.quantization.fp8_utils import channel_quant_to_tensor_quant | ||
| from sglang.test.test_utils import CustomTestCase | ||
|
|
||
|
|
||
| class TestChannelQuantToTensorQuantBroadcast(CustomTestCase): | ||
| """Regression for the 1D per-channel scale failing to broadcast against a 2D | ||
| weight. | ||
| """ | ||
|
|
||
| def test_2d_weight_1d_scale_broadcasts_per_output_channel(self): | ||
| n, k = 8, 4 | ||
| weight = torch.ones(n, k, dtype=torch.float8_e4m3fn) | ||
| # Distinct per-channel scales so a wrong-axis broadcast would be visible. | ||
| scale = torch.arange(1, n + 1, dtype=torch.float32) | ||
|
|
||
| q_tensor, tensor_scale = channel_quant_to_tensor_quant(weight, scale) | ||
|
|
||
| # Round-trip: dequantized tensor must equal weight * per-row scale. The | ||
| # requant to a single tensor-wide FP8 scale is lossy, so tolerance is | ||
| # loose — a wrong-axis broadcast would be off by whole factors (>>10%). | ||
| dq = q_tensor.to(torch.float32) * tensor_scale | ||
| expected = torch.ones(n, k, dtype=torch.float32) * scale.unsqueeze(-1) | ||
| torch.testing.assert_close(dq, expected, rtol=0.1, atol=0.5) | ||
|
|
||
| def test_mismatched_n_k_would_fail_without_unsqueeze(self): | ||
| # N != K: the pre-fix ``weight * scale`` raises; the fix must not. | ||
| n, k = 6, 3 | ||
| weight = torch.ones(n, k, dtype=torch.float8_e4m3fn) | ||
| scale = torch.arange(1, n + 1, dtype=torch.float32) | ||
|
|
||
| q_tensor, tensor_scale = channel_quant_to_tensor_quant(weight, scale) | ||
|
|
||
| self.assertEqual(q_tensor.shape, torch.Size([n, k])) | ||
|
|
||
| def test_scale_already_matching_rank_is_unchanged(self): | ||
| # A [N, 1] scale must not be unsqueezed further (guards the while-loop | ||
| # condition from over-reshaping). | ||
| n, k = 5, 4 | ||
| weight = torch.ones(n, k, dtype=torch.float8_e4m3fn) | ||
| scale = torch.arange(1, n + 1, dtype=torch.float32).unsqueeze(-1) | ||
|
|
||
| q_tensor, tensor_scale = channel_quant_to_tensor_quant(weight, scale) | ||
|
|
||
| dq = q_tensor.to(torch.float32) * tensor_scale | ||
| expected = torch.ones(n, k, dtype=torch.float32) * scale | ||
| torch.testing.assert_close(dq, expected, rtol=0.1, atol=0.5) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.