Skip to content

Quantize on load from the checkpoint tensor, not its cast to the quantized dtype - #50301

Open
qgallouedec wants to merge 5 commits into
mainfrom
mxfp4-quantize-on-load
Open

qgallouedec wants to merge 5 commits into
mainfrom
mxfp4-quantize-on-load

Conversation

@qgallouedec

@qgallouedec qgallouedec commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

What does this PR do?

Fixes #50300

Mxfp4Quantize quantized the gpt-oss experts along the output features, so a model quantized on load saved blocks and scales unlike a pre-quantized checkpoint's. It now quantizes along the input features and swizzles like a pre-quantized checkpoint. Its config now saves modules_to_not_convert as a list, not null, which the Hub flags as invalid. The loader half of this PR landed in #49773.

  • On main, a bfloat16 gpt-oss quantized on load saves gate_up_proj_blocks as (4, 128, 8, 16) instead of (4, 256, 4, 16). With this PR, gpt-oss-20b quantized on load saves the same blocks and scales as quantize_to_mxfp4, and its logits match the pre-quantized checkpoint's.

Who can review?

@SunMarc @MekkCyber

…tized dtype

A param quantized on load holds its quantized dtype (uint8 for MXFP4, float8
for FP8), and the loader cast the checkpoint tensor to it before quantizing:
MXFP4 got integer garbage, FP8 lost precision. Also quantize the MXFP4
experts along their input features and load them like a pre-quantized
checkpoint.
@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.

…on load

The config saved `modules_to_not_convert: null`, which the Hub flags as invalid.
@Cyrilvallez

Copy link
Copy Markdown
Member

Very similar to #49773, only the quantizer changes are new - the linked PR will be merged first @qgallouedec if you can adapt this one please! 🙏

@vasqu

vasqu commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator

There is a series of fixes from Arthur so not sure how much the quantizers in general change maybe wait a bit first?

# Conflicts:
#	src/transformers/core_model_loading.py
@qgallouedec

Copy link
Copy Markdown
Member Author

Done: with main merged the loader change is #49773's, so this PR keeps only the MXFP4 quantizer changes. They are still needed: on main, a bfloat16 gpt-oss quantized on load saves gate_up_proj_blocks as (4, 128, 8, 16) instead of (4, 256, 4, 16).

@vasqu

vasqu commented Nov 10, 2026

Copy link
Copy Markdown
Collaborator

Talking about #50245 so I'd rather wait for that to land first. If things are still broken, we can revisit this PR if you dont mind

@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: 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.

Quantizing gpt-oss on load with Mxfp4Config() crashes its forward and saves noise

4 participants