fix: implement Mxfp4Dequantize.reverse_op for save_pretrained support#44983
Open
Hyungkeun-Park-Nota wants to merge 1 commit intohuggingface:mainfrom
Open
fix: implement Mxfp4Dequantize.reverse_op for save_pretrained support#44983Hyungkeun-Park-Nota wants to merge 1 commit intohuggingface:mainfrom
Hyungkeun-Park-Nota wants to merge 1 commit intohuggingface:mainfrom
Conversation
1742755 to
9c59dda
Compare
Member
|
cc @SunMarc for quantization maybe? |
Member
hmmm, this shouldn't trigger a reverse ops when we dequantized the model. I think the right behavior here would be to just save the model in its dequantized form. |
9c59dda to
b676da0
Compare
Author
|
@SunMarc Thanks for the review! Updated the PR based on your feedback:
|
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: mxfp4 |
When a GPT-OSS model is loaded with Mxfp4Config(dequantize=True), save_pretrained() fails with NotImplementedError because Mxfp4Dequantize.reverse_op is not implemented. Since dequantized models are regular bf16 models, the correct behavior is to save them as-is rather than re-quantize to MXFP4: - Add Mxfp4IdentityOp as Mxfp4Dequantize.reverse_op to pass through bf16 weights unchanged during save - Remove quantization_config from model config after dequantize so the saved model loads as a regular bf16 model without triggering MXFP4 loading path
cd2c8fe to
13f9355
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What does this PR do?
Fixes
save_pretrained()failure for GPT-OSS models loaded withMxfp4Config(dequantize=True).When Triton/kernels are unavailable, transformers automatically falls back to
dequantize=True, converting MXFP4 weights to bf16. However,save_pretrained()then fails becauseMxfp4Dequantize.reverse_opraisesNotImplementedError.Since dequantized models are regular bf16 models, the correct behavior is to save them as-is rather than re-quantize to MXFP4.
Changes
src/transformers/integrations/mxfp4.py:Mxfp4IdentityOpasMxfp4Dequantize.reverse_op— passes through bf16 weights unchanged during savesrc/transformers/quantizers/quantizer_mxfp4.py:quantization_configfrom model config in_process_model_after_weight_loadingwhendequantize=True, so the savedconfig.jsondoes not containquant_method: mxfp4. Without this, reloading the saved bf16 model would attempt the MXFP4 loading path and fail because_blocks/_scaleskeys don't exist.Reproduction