Skip to content

Commit

Permalink
Optimize memory usage of mllama encoder (#34930)
Browse files Browse the repository at this point in the history
mllama encoder memory optimization
  • Loading branch information
milesial authored Dec 2, 2024
1 parent 9ab8c5b commit c24c79e
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions src/transformers/models/mllama/modeling_mllama.py
Original file line number Diff line number Diff line change
Expand Up @@ -1608,9 +1608,8 @@ def forward(
hidden_state = hidden_state.reshape(batch_size, num_concurrent_media, num_tiles, num_patches, dim)

# Collect intermediate layer outputs from encoder output
all_intermediate_hidden_states = output[1]
all_intermediate_hidden_states = [output[1][i] for i in self.intermediate_layers_indices]
intermediate_hidden_states = torch.stack(all_intermediate_hidden_states, dim=-1)
intermediate_hidden_states = intermediate_hidden_states[..., self.intermediate_layers_indices]

# Remove padding from intermediate hidden states
intermediate_hidden_states = intermediate_hidden_states.reshape(
Expand Down

0 comments on commit c24c79e

Please sign in to comment.