Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/transformers/models/llama4/modeling_llama4.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ def forward(
output_hidden_states: bool | None = None,
return_dict: bool | None = None,
**kwargs,
) -> BaseModelOutput | tuple[torch.Tensor, ...]:
) -> BaseModelOutputWithPooling | tuple[torch.Tensor, ...]:
r"""

Example:
Expand Down Expand Up @@ -1166,7 +1166,7 @@ def forward(
if not return_dict:
return tuple(v for v in [hidden_state, hidden_states, attentions] if v is not None)

return BaseModelOutput(
return BaseModelOutputWithPooling(
last_hidden_state=hidden_state,
hidden_states=hidden_states,
Comment on lines -1169 to 1171
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the last hidden state is the one after layernorm_post, and pooler state is after adapter. Though it'll be a breaking change...
Fine with leaving it as is, thanks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right :/ Damn, I wish I spotted that before v5, as it's indeed breaking if we improve it. I did make roughly this change for a few other architectures pre-v5.

attentions=attentions,
Expand Down Expand Up @@ -1321,7 +1321,7 @@ def forward(
pixel_values=pixel_values,
vision_feature_select_strategy=vision_feature_select_strategy,
return_dict=True,
).pooler_output
).last_hidden_state

vision_flat = image_features.view(-1, image_features.size(-1))
projected_vision_flat = self.multi_modal_projector(vision_flat).to(
Expand Down