Skip to content

PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度

[BUG] update moe check logic and make .gate ignore general (#1517)

Xin He2eaa3b1405e1
diff --git a/auto_round/special_model_handler.py b/auto_round/special_model_handler.py
index a4573a3e8..9ea12caa4 100644
--- a/auto_round/special_model_handler.py
+++ b/auto_round/special_model_handler.py
@@ -256,15 +256,6 @@ register_ignore_layers(
)
-# minimax_m2
-register_ignore_layers(
- matchers=[
- ModelTypeMatcher(r"minimax_m2", mode="full"),
- ],
- ignore_layers=["block_sparse_moe.gate"],
-)
-
-
def get_predefined_ignore_layers(model: torch.nn.Module) -> list[str]:
layers = []
for rule in _PRE_DEFINED_IGNORE_LAYERS:
@@ -281,6 +272,9 @@ def get_predefined_ignore_layers(model: torch.nn.Module) -> list[str]:
break
config = getattr(model, "config", None)
if not layers and is_moe_model_via_config(config):
- layers.append("mlp.gate")
+ for name, _ in model.named_modules():
+ if name.endswith(".gate"):
+ print(name)
+ layers.append(name)
return list(dict.fromkeys(layers))
diff --git a/auto_round/utils/model.py b/auto_round/utils/model.py
index 3a04005e8..c5a305222 100644
--- a/auto_round/utils/model.py
+++ b/auto_round/utils/model.py
@@ -1143,10 +1143,9 @@ def is_moe_model(model: torch.nn.Module) -> bool:
def is_moe_model_via_config(config) -> bool:
- if hasattr(config, "to_dict"):
- for key in config.to_dict().keys():
- if "moe" in key or "expert" in key:
- return True
+ config_str = str(config).lower()
+ if "moe" in config_str or "expert" in config_str:
+ return True
return False