Skip to content

[Bugfix][ROCm] AMD-Quark mixed-precision DeepSeek-V4.1 support with Quark OCP MXFP8 - #57191

Closed
xiao-llm wants to merge 3 commits into
vllm-project:mainfrom
xiao-llm:xiaoyu/quark-ocp-mx-mxfp8
Closed

xiao-llm wants to merge 3 commits into
vllm-project:mainfrom
xiao-llm:xiaoyu/quark-ocp-mx-mxfp8

Conversation

@xiao-llm

@xiao-llm xiao-llm commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor

Purpose

Fix DeepSeek-V4.1-Flash-MXFP4 loading issue. It is a mixed-precision AMD-Quark export — MXFP4 experts, but 226 per-layer attention specs in MXFP8:

scheme
global_quant_config fp4 / per_group / group_size=32 / e8m0
layer_quant_config (226 entries) fp8_e4m3 / per_block / block_size=[32,32] / float8_e8m0fnu

Exsiting DeepSeek V4's require 128x128 block geometry, or the DeepSeek-native scale naming.

This PR fix the blockers and support MXFP8 by routing through the normal Quark matcher chain via QuarkOCP_MX, like MXFP4 and MXFP6. Changes (8 files, +300/−241):

- ocp_mx_utils.py — Add mxfp8_e4m3 to quant key maps; add ocp_mx_weight_dtype_and_rows() normalizer accepting both config dialects (canonical per-group and V4.1 per-block)
- quark.py — Rewrite _is_w_ocp_mx_a_x around the normalizer; delete the MXFP8 short-circuit; thread scale_block_rows through init_scheme
- quark_ocp_mx.py — Extend QuarkOCP_MX with unpacked MXFP8 path: 3-way packed_factor, create_weights with repeat_interleave scale loader, init_mxfp8_linear_kernel() branch, terminal else: raise
- quark_w8a8_mxfp8.py — Deleted
- config_utils.py — Fix KeyError for per-block configs missing group_size
- quark_moe.py — Explicit MXFP8 rejection message; else: raise in get_packed_dim
- test_quark.py — Shape A + Shape B dispatch tests; MoE rejection test; updated existing test to assert QuarkOCP_MX

End-to-end

DeepSeek-V4.1-Flash-MXFP4 (48 shards, 475 GB) on 4x MI355X at TP=4: all
shards load in 74.5 s, MXFP8 attention resolves to QuarkW8A8Mxfp8, and the
model is coherent.

Accuracy was measured rather than eyeballed — lm_eval gsm8k, full 1319
problems, 5-shot, greedy

Filter 5-shot accuracy
flexible-extract 91.58% ± 0.76
strict-match 91.66% ± 0.76

Test Result


Essential Elements of an Effective PR Description Checklist
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.

xiao-llm and others added 3 commits September 15, 2026 16:18
DeepSeek-V4.1-Flash-MXFP4 is a mixed-precision Quark export: MXFP4 for the
experts globally, plus 226 per-layer specs putting attention on 32x32
per-block FP8 with e8m0 scales. Four things stop it from loading, each of
which assumes DeepSeek V4's 128x128 geometry or the native scale naming.

DeepseekV4FP8Config.override_quantization_method claimed any Quark export
whose global scheme is MXFP4, but from_config rewrites the config into a
single global FP8 scheme, discarding the per-layer specs. Decline exports
that carry layer_quant_config so QuarkConfig handles them.

QuarkConfig then had no scheme for those layers: _is_fp8_w8a8 only accepts
128x128 per-block FP8 and the MX matchers only accept 1-D per-group weights,
so dispatch raised NotImplementedError. A 32x32 per-block e8m0 weight is
MXFP8 in a 2-D wrapper, which ModelOpt's MXFP8 linear method already reads,
so route it there.

The VL wrapper exposed neither packed_modules_mapping nor hf_to_vllm_mapper
on the class. configure_quant_config reads both off the class before
__init__ runs, so per-layer keys naming layers.N.attn.wq_a never matched the
runtime language_model.model.layers.N.attn.wq_a and silently fell back to
the global MXFP4 spec.

Finally, Quark spells the engram scale embed.weight_scale; the mapper's
\.scale$ rules only match a literal ".scale" suffix, so the tensor was never
routed.

Signed-off-by: Xiao Yu <xiao.yu.dc@outlook.com>
Route Quark's 32x32 per-block e8m0 FP8 weights through a Quark-native
QuarkW8A8Mxfp8 scheme rather than borrowing ModelOptLinearMethod, so the
ROCm/Quark path no longer reaches into the ModelOpt namespace for a
format Quark itself exports.

The scheme wraps the same shared init_mxfp8_linear_kernel() used by the
compressed-tensors and INC MXFP8 schemes. Quark spells the scale 2-D
(one e8m0 value per block_size[0] weight rows) where MXFP8 canonically
carries one per row, so the scale loader expands each row on load.

QuarkOCP_MX is deliberately not extended: it covers the sub-byte packed
MX formats and has no MXFP8 entry in _WEIGHT_QUANT_KEY_MAP, whereas
MXFP8 is unpacked.

Signed-off-by: Xiao Yu <xiao.yu.dc@outlook.com>
Make MXFP8 a first-class OCP MX dtype so it routes through the normal
Quark matcher chain like MXFP4 and MXFP6, eliminating the short-circuit
(`_mxfp8_block_linear_method`) that caused `get_quant_method` and
`get_quant_method_target` to diverge on MXFP8 layers.

Both MXFP8 config dialects are now accepted: canonical per-group
(qscheme=per_group, group_size=32, scale_format=e8m0) and V4.1's 2-D
per-block (qscheme=per_block, block_size=[R,32], scale_type=float8_e8m0fnu).

Signed-off-by: Xiao Yu <xiao.yu.dc@outlook.com>

Co-Authored-By: Claude Opus 4 <noreply@anthropic.com>

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

This pull request is from a fork — automated review is disabled. A repository maintainer can comment @claude review to run a one-time review.

@mergify mergify Bot added deepseek Related to DeepSeek models quantization DSv4.1 Related to DeepSeek-V4.1 models labels Sep 16, 2026
@xiao-llm xiao-llm changed the title Xiaoyu/quark ocp mx mxfp8 [Bugfix][ROCm] AMD-Quark mixed-precision DeepSeek-V4.1 support with Quark OCP MXFP8 Sep 16, 2026
@mergify mergify Bot added rocm Related to AMD ROCm bug Something isn't working labels Sep 16, 2026
@github-project-automation github-project-automation Bot moved this to Todo in AMD Sep 16, 2026
@mergify

mergify Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

⚠️ The sha of the head commit of this PR conflicts with #57071. Mergify cannot evaluate rules on this PR. Once #57071 is merged or closed, Mergify will resume processing this PR. ⚠️

@xiao-llm xiao-llm closed this Sep 17, 2026
@github-project-automation github-project-automation Bot moved this from Todo to Done in AMD Sep 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working deepseek Related to DeepSeek models DSv4.1 Related to DeepSeek-V4.1 models quantization rocm Related to AMD ROCm

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant