[feat] Support EAGLE3 for Qwen (#7745)

Co-authored-by: 纬杭 <ximing.wxm@antgroup.com>
Co-authored-by: zyksir <zyksir@outlook.com>
This commit is contained in:
Ximingwang-09
2025-07-04 19:50:28 -07:00
committed by GitHub
co-authored by 纬杭 zyksir
parent af5647748a
commit 1964c325de
4 changed files with 81 additions and 6 deletions
+15 -1
View File
@@ -440,6 +440,9 @@ class Qwen2MoeModel(nn.Module):
else:
self.norm = PPMissingLayer(return_tuple=True)
# For EAGLE3 support
self.layers_to_capture = []
def forward(
self,
input_ids: torch.Tensor,
@@ -459,6 +462,7 @@ class Qwen2MoeModel(nn.Module):
hidden_states = pp_proxy_tensors["hidden_states"]
residual = pp_proxy_tensors["residual"]
aux_hidden_states = []
if forward_batch.can_run_tbo:
hidden_states, residual = model_forward_maybe_tbo(
layers=self.layers,
@@ -471,6 +475,12 @@ class Qwen2MoeModel(nn.Module):
)
else:
for i in range(self.start_layer, self.end_layer):
if i in self.layers_to_capture:
aux_hidden_states.append(
hidden_states + residual
if residual is not None
else hidden_states
)
with get_global_expert_distribution_recorder().with_current_layer(i):
layer = self.layers[i]
hidden_states, residual = layer(
@@ -489,7 +499,11 @@ class Qwen2MoeModel(nn.Module):
hidden_states = self.norm(hidden_states)
else:
hidden_states, _ = self.norm(hidden_states, residual)
return hidden_states
if len(aux_hidden_states) == 0:
return hidden_states
return hidden_states, aux_hidden_states
class Qwen2MoeForCausalLM(nn.Module):