Skip to content

fix qwen4exp-fp8 ple embedding - #48368

Merged
ArthurZucker merged 6 commits into
huggingface:mainfrom
JJJYmmm:fix_qwen4exp_fp8
Sep 1, 2026
Merged

ArthurZucker merged 6 commits into
huggingface:mainfrom
JJJYmmm:fix_qwen4exp_fp8

Conversation

@JJJYmmm

@JJJYmmm JJJYmmm commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

CPU CI GPU run-slow

What does this PR do?

fixes https://huggingface.co/Qwen/Qwen3.8-Flash-Next-FP8/discussions/2

add a new class FP8Embedding (nn.Embedding with per-tensor weight scale), also add a private attr _quantizable_embeddings to determine the embedding which may be quantized

Code Agent Policy

3.8max

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • [ x] Did you read the contributor guideline and the
    Pull Request checks?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes according to the guidelines?
  • Did you write any new necessary tests?

Who can review?

@ArthurZucker @Cyrilvallez @vasqu @zucchini-nlp

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ty! its a great addition, let's make sur it follows our standard API! Happy to do it myself

Comment on lines +1266 to +1269
"ple.ple_embedding.ngram_embedding.weight_scale",
]
# FP8 releases ship this table quantized with one per-tensor scale.
_quantizable_embeddings = ["ple.ple_embedding.ngram_embedding"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

the modeling should never have anything related to quantization. We can update the FP8 quantizer tho.

Also for quantizing the embeddings, this should be classic with modules_to_convert in the quantization_config

@JJJYmmm JJJYmmm Aug 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

got it, let's use explicit modules_to_convert🫡 it requires updating the hub ckpt's config, I'll do it asap done

Comment thread src/transformers/conversion_mapping.py Outdated
WeightConverter(
source_patterns="ngram_embedding.shard_*.weight",
target_patterns="ngram_embedding.weight",
target_patterns="ngram_embedding.weight$",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The other models do not require this. Might cause issues when saving

@JJJYmmm JJJYmmm Aug 30, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

we need $ when saving fp8 ckpt. without $, ngram_embedding.weight_scale also matches the target_patterns and would be saved as ngram_embedding.shard_*.weight_scale, which is not expected.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, but: https://github.com/huggingface/transformers/blob/add-h4/src/transformers/quantizers/quantizer_finegrained_fp8.py#L266-L268 ! It should "automatically" happen here as the equivalent is done for linear case

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done! the quantizer now anchors target patterns ending in .weight here. this should not affect other checkpoints, as weights and their corresponding scales are always handled separately.

@ArthurZucker ArthurZucker added for patch Tag issues / labels that should be included in the next patch and removed for patch Tag issues / labels that should be included in the next patch labels Sep 1, 2026

@ArthurZucker ArthurZucker left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

GG great PR 😉
One nit !

Comment on lines +1705 to 1707
modules_to_convert (`list`, *optional*):
A list of additional module names, such as embedding tables, that should be converted during quantization.
scale_fmt (`str`, *optional*, defaults to `"float"`):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

We really needed this granularity, indeed! ty for that.
cc @SunMarc it allows 0 changes to other quantization config!

Comment thread src/transformers/conversion_mapping.py Outdated
WeightConverter(
source_patterns="ngram_embedding.shard_*.weight",
target_patterns="ngram_embedding.weight",
target_patterns="ngram_embedding.weight$",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yes, but: https://github.com/huggingface/transformers/blob/add-h4/src/transformers/quantizers/quantizer_finegrained_fp8.py#L266-L268 ! It should "automatically" happen here as the equivalent is done for linear case

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

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

run-slow: qwen4_exp, finegrained_fp8

@github-actions

github-actions Bot commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

CI recap

Dashboard: View test results in Grafana
Latest run: 33377231173:2
Result: success | Jobs: 16 | Tests: 184,321 | Failures: 0 | Duration: 14h 53m

@ArthurZucker
ArthurZucker added this pull request to the merge queue Sep 1, 2026
@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.

Merged via the queue into huggingface:main with commit 2686521 Sep 1, 2026
115 checks passed
sbucaille pushed a commit to sbucaille/transformers that referenced this pull request Sep 16, 2026
* fix qwen4exp-fp8 ple embedding

* fix weight_scale resave

* add modules_to_convert

* unnecessary dtype

* lets use super

* automatically anchor weight targets
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.

3 participants