PTQ-Level Efficiency, QAT-Level Accuracy | 训练后量化的效率,量化感知训练的精度
fix: handle router_logits tuple for compatibility with transformers >= 5.13.0 (#2046)
Xin He4b8468ac44f3
diff --git a/auto_round/modeling/unfused_moe/glm_moe.py b/auto_round/modeling/unfused_moe/glm_moe.pyindex e68ac9974..5ef9fcc2c 100644--- a/auto_round/modeling/unfused_moe/glm_moe.py+++ b/auto_round/modeling/unfused_moe/glm_moe.py@@ -98,7 +98,10 @@ class LinearGlm4MoeMoE(nn.Module):residuals = hidden_statesorig_shape = hidden_states.shaperouter_logits = self.gate(hidden_states)- topk_indices, topk_weights = self.route_tokens_to_experts(router_logits)+ if isinstance(router_logits, tuple): # transformers >= 5.13.0+ _, topk_weights, topk_indices = router_logits+ else:+ topk_indices, topk_weights = self.route_tokens_to_experts(router_logits)hidden_states = hidden_states.view(-1, hidden_states.shape[-1])hidden_states = self.experts_forward(hidden_states, topk_indices, topk_weights).view(*orig_shape)hidden_states = hidden_states + self.shared_experts(residuals)diff --git a/auto_round/modeling/unfused_moe/glm_moe_dsa.py b/auto_round/modeling/unfused_moe/glm_moe_dsa.pyindex 2fb34de0f..3a108a8cb 100644--- a/auto_round/modeling/unfused_moe/glm_moe_dsa.py+++ b/auto_round/modeling/unfused_moe/glm_moe_dsa.py@@ -88,7 +88,10 @@ class LinearGlmMoeDsaMoE(nn.Module):residuals = hidden_statesorig_shape = hidden_states.shaperouter_logits = self.gate(hidden_states)- topk_indices, topk_weights = self.route_tokens_to_experts(router_logits)+ if isinstance(router_logits, tuple): # transformers >= 5.13.0+ _, topk_weights, topk_indices = router_logits+ else:+ topk_indices, topk_weights = self.route_tokens_to_experts(router_logits)hidden_states = hidden_states.view(-1, hidden_states.shape[-1])hidden_states = self.experts_forward(hidden_states, topk_indices, topk_weights).view(*orig_shape)hidden_states = hidden_states + self.shared_experts(residuals)diff --git a/auto_round/modeling/unfused_moe/glm_moe_light.py b/auto_round/modeling/unfused_moe/glm_moe_light.pyindex c9506ecb4..03814650f 100644--- a/auto_round/modeling/unfused_moe/glm_moe_light.py+++ b/auto_round/modeling/unfused_moe/glm_moe_light.py@@ -100,7 +100,10 @@ class LinearGlm4MoeLiteMoE(nn.Module):residuals = hidden_statesorig_shape = hidden_states.shaperouter_logits = self.gate(hidden_states)- topk_indices, topk_weights = self.route_tokens_to_experts(router_logits)+ if isinstance(router_logits, tuple): # transformers >= 5.13.0+ _, topk_weights, topk_indices = router_logits+ else:+ topk_indices, topk_weights = self.route_tokens_to_experts(router_logits)hidden_states = hidden_states.view(-1, hidden_states.shape[-1])hidden_states = self.experts_forward(hidden_states, topk_indices, topk_weights).view(*orig_shape)hidden_states = hidden_states + self.shared_experts(residuals)