Skip to content

🚨 MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan - #49778

Draft
IlyasMoutawwakil wants to merge 15 commits into
fg-split/5-fp8from
fg-split/6-mxfp4
Draft

IlyasMoutawwakil wants to merge 15 commits into
fg-split/5-fp8from
fg-split/6-mxfp4

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What.

  • Mxfp4Config and Mxfp4HfQuantizer become a block-scaled format: W4A16 (the default, as GPT-OSS runs), W4A8 or
    W4A4. This moves MXFP4 onto the shared kernels and loaders that FP8 uses since FP8 on the fine-grained machinery (Fp8Config) #49777.
  • The quantizer reads GPT-OSS's _blocks/_scales layout (openai/gpt-oss-20b). Mxfp4Config keeps
    main's positional arguments. The frozen integrations/mxfp4 stays for main's behaviours.
  • read_fp8 builds DeepSeek-V4's plan when the FP8 checkpoint says expert_dtype="fp4": block FP8 over W4A4 MXFP4
    experts. V4.1 ships expert_dtype in its quantization config. V4 sets it on the model config, so
    DeepseekV4Config.__post_init__ moves it into the quantization config, with the "deepseek" layout. The Hub
    config (deepseek-ai/DeepSeek-V4-Flash) only says fp8, so only the model knows its scales are named scale.
  • Its conversion mapping names the checkpoint's own keys, so a save writes them back.

Behaviour changes.

  • DeepSeek-V4's FP4 experts on DeepGEMM need experts_implementation="deepgemm" at load. Switching to it after a
    Triton load raises, so the SM100 test sweeps leave it out. deepgemm_megamoe works as before.
  • Every MXFP4 format needs compute capability 8.9, because the kernels use Triton's FP8 type. On a CUDA GPU below
    8.9, such as an A100 or a T4, Mxfp4Config loads through main's MXFP4 quantizer, kept frozen as
    Mxfp4LegacyHfQuantizer.
  • A missing kernels package still dequantizes a checkpoint.
  • A serialized MXFP4 quantization_config holds more fields.
  • DeepSeek-V4 loads on the fine-grained path instead of the legacy one.

Breaking. 🚨 GPT-OSS MXFP4 with use_kernels=True now loads dequantized on CPU too.

  • use_kernels puts the megablocks layer on GptOssMLP, and that layer reads bf16 experts. So an MXFP4 model with
    use_kernels=True dequantizes its experts, on every device. Main did this on GPU only.
  • On CPU, main kept main's MXFP4 experts, which the megablocks CPU kernel reads. The fine-grained experts are not
    that class, so the CPU case follows the same rule as the GPU one.

Depends on. #49777. It needs FP8 for DeepSeek-V4.

How tested. tests/quantization/mxfp4, the DeepSeek-V4 plan tests in tests/quantization/finegrained, GPT-OSS
and DeepSeek-V4 model tests.

The comments and docstrings that say why each change exists are there for readability. Feel free to ask for any of
them to go if it's self-evident.

🤖 Generated with Claude Code

@HuggingFaceDocBuilderDev

Copy link
Copy Markdown

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@IlyasMoutawwakil
IlyasMoutawwakil removed this pull request from stack #49781 October 20, 2026 13:41
@IlyasMoutawwakil IlyasMoutawwakil changed the title MXFP4 on the fine-grained machinery, with DeepSeek-V4's FP8 + MXFP4 plan MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan Oct 20, 2026
@IlyasMoutawwakil
IlyasMoutawwakil force-pushed the fg-split/6-mxfp4 branch 2 times, most recently from 4991a3b to b6b3074 Compare October 20, 2026 16:04
@IlyasMoutawwakil
IlyasMoutawwakil removed this pull request from stack #49788 October 20, 2026 16:25
@IlyasMoutawwakil
IlyasMoutawwakil force-pushed the fg-split/6-mxfp4 branch 2 times, most recently from 3837fca to a1dd17d Compare October 20, 2026 17:34
@IlyasMoutawwakil IlyasMoutawwakil changed the title MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan 🚨 MXFP4 on the fine-grained machinery, and DeepSeek-V4's FP8 + MXFP4 plan Oct 21, 2026
@IlyasMoutawwakil
IlyasMoutawwakil force-pushed the fg-split/6-mxfp4 branch 2 times, most recently from 0eb9021 to 1aafb73 Compare October 22, 2026 07:00
@IlyasMoutawwakil
IlyasMoutawwakil force-pushed the fg-split/6-mxfp4 branch 2 times, most recently from 1aafb73 to ba15098 Compare October 22, 2026 07:18
IlyasMoutawwakil and others added 14 commits October 23, 2026 13:34
…plan

- Mxfp4Config / Mxfp4HfQuantizer become a block-scaled format: W4A16 (the
  default, how GPT-OSS runs), W4A8 or W4A4, GPT-OSS's blocks/scales layout
  and the modelopt one; integrations/mxfp4 is frozen.
- DeepSeek-V4: DeepseekV4Config.adapt_quantization_config reads
  expert_dtype="fp4" (model or quantization config) into FP8 linears over
  MXFP4 experts (Fp8Config.with_mxfp4_experts), in DeepSeek's own "deepseek"
  producer layout (block scales shipped as `scale`); its conversion mapping
  names the checkpoint's own keys so a save writes them back.
- Tests: the MXFP4 suite, the DeepSeek-V4 plan and the FP8 + MXFP4 mixed
  fixtures of the shared testers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The plan tests no longer expect a passed config to merge silently.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
On SM100 the experts hold the Triton layout, which DeepGEMM's grouped experts refuse. The FP8-Base sweep
keeps DeepGEMM off SM100, where block-FP8 gate|up stay stacked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pgemm_linear

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fine-grained kernels need Triton's FP8 type. GPT-OSS on a T4 or an A100 would otherwise dequantize, and
GPT-OSS-120B no longer fits an A100 80GB in bf16.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An fp8 checkpoint with expert_dtype fp4 reads as block FP8 with W4A4 MXFP4 experts, for V4 and V4.1 alike.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A passed Fp8Config quantizes every module to FP8. The fixture wants DeepSeek-V4's MXFP4 experts.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown
Contributor

[For maintainers] Suggested jobs to run (before merge)

run-slow: deepseek_v4, finegrained, fp8, mxfp4

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants