mirror of
https://github.com/huggingface/transformers.git
synced 2026-10-29 01:06:24 +08:00
* Match a skip-list entry from the start only up to a module boundary
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>
* Shorten the should_convert_module docstring
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Restore the matching-rules comment of should_convert_module
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Move the should_convert_module test to a general quantizer utils test file
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Explain why the skip-list key is grouped
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Fit the skip-list comment within the noisy-comment limits
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
* Name the skip-list test's exclusion lists modules_to_not_convert
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
43 lines
2.3 KiB
Python
43 lines
2.3 KiB
Python
# Copyright 2026 The HuggingFace Inc. team. All rights reserved.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
import unittest
|
|
|
|
from transformers.quantizers.quantizers_utils import should_convert_module
|
|
|
|
|
|
class SkipListTest(unittest.TestCase):
|
|
def test_should_convert_module(self):
|
|
# Should convert by default
|
|
self.assertTrue(should_convert_module("model", None))
|
|
self.assertTrue(should_convert_module("model", []))
|
|
|
|
# Should not convert if in exclusion list
|
|
modules_to_not_convert = ["model.layers.*.self_attn", "lm_head"]
|
|
self.assertFalse(should_convert_module("lm_head", modules_to_not_convert))
|
|
self.assertTrue(should_convert_module("experts", modules_to_not_convert))
|
|
self.assertFalse(should_convert_module("model.layers.3.self_attn.q_proj", modules_to_not_convert))
|
|
|
|
# A match from the start ends at a module boundary
|
|
modules_to_not_convert = ["model.layers.1", "model.layers.0.mlp.gate", r"^model\.audio_tower(?:\.|$)"]
|
|
self.assertFalse(should_convert_module("model.layers.1.mlp.up_proj", modules_to_not_convert))
|
|
self.assertTrue(should_convert_module("model.layers.10.mlp.up_proj", modules_to_not_convert))
|
|
self.assertFalse(should_convert_module("model.layers.0.mlp.gate", modules_to_not_convert))
|
|
self.assertTrue(should_convert_module("model.layers.0.mlp.gate_proj", modules_to_not_convert))
|
|
# A user regex that brings its own anchor and boundary still works.
|
|
self.assertFalse(should_convert_module("model.audio_tower.layers.1.proj", modules_to_not_convert))
|
|
self.assertTrue(should_convert_module("model.audio_towers.proj", modules_to_not_convert))
|
|
|
|
# A name still covers the names ending in it, as Hub skip-lists rely on
|
|
self.assertFalse(should_convert_module("model.layers.0.mlp.shared_expert_gate", ["gate"]))
|