[Feature] Support eagle3 for qwen3-vl (#22230)

This commit is contained in:
Kurkur
2026-04-09 11:45:36 +08:00
committed by GitHub
parent ddc8ef1038
commit a69be2e866
+24
View File
@@ -1130,6 +1130,9 @@ class Qwen3VLForConditionalGeneration(nn.Module):
self.num_deepstack_embeddings = len(self.deepstack_visual_indexes)
self.use_deepstack = {Modality.IMAGE: True, Modality.VIDEO: True}
# For EAGLE3 support
self.capture_aux_hidden_states = False
def separate_deepstack_embeds(self, embedding):
assert (
embedding.shape[-1] % (1 + self.num_deepstack_embeddings) == 0
@@ -1246,6 +1249,10 @@ class Qwen3VLForConditionalGeneration(nn.Module):
pp_proxy_tensors=pp_proxy_tensors,
)
aux_hidden_states = None
if self.capture_aux_hidden_states:
hidden_states, aux_hidden_states = hidden_states
if self.pp_group.is_last_rank:
if not get_embedding:
return self.logits_processor(
@@ -1253,6 +1260,7 @@ class Qwen3VLForConditionalGeneration(nn.Module):
hidden_states,
self.lm_head,
forward_batch,
aux_hidden_states,
)
else:
return self.pooler(hidden_states, forward_batch)
@@ -1344,5 +1352,21 @@ class Qwen3VLForConditionalGeneration(nn.Module):
weight_loader = getattr(param, "weight_loader", default_weight_loader)
weight_loader(param, loaded_weight)
def get_embed_and_head(self):
return self.model.embed_tokens.weight, self.lm_head.weight
def set_eagle3_layers_to_capture(self, layer_ids: Optional[List[int]] = None):
self.capture_aux_hidden_states = True
self.model.capture_aux_hidden_states = True
if layer_ids is None:
num_layers = self.config.num_hidden_layers
self.model.layers_to_capture = [
2,
num_layers // 2,
num_layers - 3,
] # Specific layers for EAGLE3 support
else:
self.model.layers_to_capture = [val + 1 for val in layer_ids]
EntryClass = Qwen3VLForConditionalGeneration