[AMD] [GLM-5.3-Flash Day 0] Honor fused and per-expert names in quark exclude (#39317)

Co-authored-by: Yikai Zhang <ykzhang12@gmail.com>
Co-authored-by: Thomas Wang <thomawan@amd.com>
Co-authored-by: Kevin Mi <45493463+kevin-mii@users.noreply.github.com>
Co-authored-by: Kevin Mi <mikevin920@yahoo.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Raiden Makoto
2026-09-21 21:26:42 -07:00
committed by GitHub
co-authored by Yikai Zhang Thomas Wang Kevin Mi Kevin Mi Claude Fable 5.1
parent 018b73c7a0
commit e1daf68304
2 changed files with 56 additions and 5 deletions
@@ -55,6 +55,19 @@ def should_ignore_layer(
# proj_name = qkv_proj # proj_name = qkv_proj
proj_name = layer_name.split(".")[-1] proj_name = layer_name.split(".")[-1]
# a fused module can be excluded under its fused name, so match it before expanding
if check_equal_or_regex_match(layer_name=layer_name, targets=ignore):
return True
# excludes may name experts individually, so an excluded expert excludes the module
if layer_name.endswith(".experts"):
expert_prefix = layer_name + "."
if any(
isinstance(target, str) and target.startswith(expert_prefix)
for target in ignore
):
return True
# Fused layers like gate_up_proj or qkv_proj will not be fused # Fused layers like gate_up_proj or qkv_proj will not be fused
# in the safetensors checkpoint. So, we convert the name # in the safetensors checkpoint. So, we convert the name
# from the fused version to unfused + check to make sure that # from the fused version to unfused + check to make sure that
@@ -87,12 +100,9 @@ def should_ignore_layer(
"requires all to use the same scheme." "requires all to use the same scheme."
) )
# Unfused layers like down_proj and o_proj will match # an unfused name was already tried by the direct check above
# the safetensors checkpoint already.
else: else:
should_ignore_layer = check_equal_or_regex_match( should_ignore_layer = False
layer_name=layer_name, targets=ignore
)
assert should_ignore_layer is not None assert should_ignore_layer is not None
@@ -115,5 +115,46 @@ class TestE8M0ToF32(CustomTestCase):
self.assertTrue(torch.isnan(out[2]).item()) self.assertTrue(torch.isnan(out[2]).item())
QKV_MAPPING = {"qkv_proj": ["q_proj", "k_proj", "v_proj"]}
class TestShouldIgnoreLayerFusedNames(CustomTestCase):
"""An `exclude` entry naming an already-fused module, or naming experts
individually, must exclude the fused module SGLang builds; otherwise an
MXFP4-packed parameter is allocated for a BF16 tensor and loading aborts."""
# ---- Bug-catchers: must FAIL on unfixed code ---------------------------
def test_directly_excluded_fused_qkv_is_ignored(self):
name = "visual.blocks.0.attn.qkv_proj"
self.assertTrue(
should_ignore_layer(name, ignore=[name], fused_mapping=QKV_MAPPING)
)
def test_per_expert_excludes_ignore_the_fused_moe_module(self):
layer = "model.layers.6.mlp.experts"
ignore = [
f"{layer}.{i}.{proj}"
for i in range(3)
for proj in ("down_proj", "gate_proj", "up_proj")
]
self.assertTrue(
should_ignore_layer(layer, ignore=ignore, fused_mapping=QKV_MAPPING)
)
# ---- Guards: behavior that must NOT change -----------------------------
def test_unrelated_moe_layer_is_not_ignored(self):
# a prefix match must not bleed into a neighboring layer index
ignore = ["model.layers.6.mlp.experts.0.down_proj"]
self.assertFalse(
should_ignore_layer(
"model.layers.7.mlp.experts",
ignore=ignore,
fused_mapping=QKV_MAPPING,
)
)
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()