Skip to content

Match a skip-list entry from the start only up to a module boundary - #49771

Merged
IlyasMoutawwakil merged 7 commits into
mainfrom
fg-split/fix-skip-list-index
Oct 23, 2026
Merged

IlyasMoutawwakil merged 7 commits into
mainfrom
fg-split/fix-skip-list-index

Conversation

@IlyasMoutawwakil

@IlyasMoutawwakil IlyasMoutawwakil commented Oct 20, 2026 •

Copy link
Copy Markdown
Member

🤗 Transformers CI

What. should_convert_module matched a skip-list entry with a bare re.match, so "model.layers.1" also skipped
layers 10 to 19. A match from the start now ends at a module boundary. An entry still covers its sub-tree, a regex
with its own boundary still works, and a name still covers the names ending in it ("gate" covers
shared_expert_gate).

Why we need it. Loading real FP8 checkpoints with the fine-grained FP8 support (#49777) blocked on it.
Qwen3.8-27B-FP8 lists its routers as mlp.gate, which also skipped the quantized mlp.gate_proj. Its FP8 weight
then reached a bf16 linear. Every quantizer that takes modules_to_not_convert uses this function, so main has the
same bug, and any skip-list naming a layer by index hits it too. The key is wrapped in a group so the boundary applies
to every alternative of a key with |.

Supersedes #47990, which anchors with $ and so stops matching regex entries that carry their own boundary, such as
^model\.audio_tower(?:\.|$).

Behaviour change. A skip-list entry no longer covers longer siblings (model.layers.1 vs model.layers.10,
mlp.gate vs mlp.gate_proj).

Depends on. main. First PR of the fine-grained stack.

How tested. tests/quantization/test_quantizers_utils.py, a new general test file. test_should_convert_module
moves there from the MXFP4 suite, with the new cases.

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.

Comment on lines -27 to -36
"""Return False if an entry of `patterns` covers `full_name`, True otherwise.

An entry covers the names it matches from the start up to a module boundary, and the names ending with it.
So `"model.layers.1"` covers `model.layers.1.mlp` but not `model.layers.10`.
"""
if patterns is None:
return True

# We should avoid converting in the following situations:
# 1. The pattern appears as a prefix followed by a dot in `full_name`
# (e.g., "model.decoder.layer.11." matches "model.decoder.layer.11.attn.weight").
# 2. The pattern matches `full_name` exactly or via regex
# (e.g., "lm_head" matches "lm_head"; "model.decoder.layer.*" matches "model.decoder.layer.11.attn.weight").
# 3. `full_name` ends with the pattern
# (e.g., "fc1" matches "model.decoder.layers.23.fc1").

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.

why a new docstring, shouldnt we just adjust the existing cases instead?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

fair, restored the original comment block and adjusted the cases for the boundary rule, docstring's gone

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.

why is the test in mxfp4? do we not have a general utils test file?

@IlyasMoutawwakil IlyasMoutawwakil Oct 20, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

weirdly that's the test checking it, and no quantization utils test file, i can create one

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

moved it to a new tests/quantization/test_quantizers_utils.py with main's cases + the new ones, out of mxfp4

@IlyasMoutawwakil
IlyasMoutawwakil removed this pull request from stack #49788 October 20, 2026 16:25
@IlyasMoutawwakil
IlyasMoutawwakil marked this pull request as ready for review October 21, 2026 07:27
@IlyasMoutawwakil
IlyasMoutawwakil removed this pull request from stack #49798 October 21, 2026 08:59

@SunMarc SunMarc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot !

@IlyasMoutawwakil
IlyasMoutawwakil enabled stacked auto-merge October 22, 2026 16:04
IlyasMoutawwakil and others added 7 commits October 23, 2026 15:03
should_convert_module matched an entry from the start of the module name with
no boundary after it, so "model.layers.1" also skipped model.layers.10 to 19,
and Qwen3.8-27B-FP8's router entry "mlp.gate" also skipped the quantized
mlp.gate_proj (its FP8 weight then reached a bf16 linear). A match from the
start now has to end on a "." it consumed, or right before a "." or the end
of the name, which keeps regex entries that carry their own boundary such as
"^model\.audio_tower(?:\.|$)". The endswith clause Hub skip-lists rely on
("gate" covering shared_expert_gate) is unchanged.

Supersedes #47990, which anchors with "$" and so stops matching such regex
entries.

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>
… file

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>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@IlyasMoutawwakil
IlyasMoutawwakil force-pushed the fg-split/fix-skip-list-index branch from 446dc5d to 18d5d46 Compare October 23, 2026 13:03
@github-actions

Copy link
Copy Markdown
Contributor

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

run-slow: mxfp4

@IlyasMoutawwakil
IlyasMoutawwakil added this pull request to the merge queue Oct 23, 2026
Merged via the queue into main with commit 944e22e Oct 23, 2026
113 checks passed
@IlyasMoutawwakil
IlyasMoutawwakil deleted the fg-split/fix-skip-list-index branch October 23, 2026 13:34
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.

4 participants