Skip to content

Commit

Permalink
[Mixtral] Fixes attention masking in the loss (huggingface#29363)
Browse files Browse the repository at this point in the history
Fix mixtral load balancing loss

Co-authored-by: dingkunbo <[email protected]>
  • Loading branch information
2 people authored and damithsenanayake committed Mar 7, 2024
1 parent 3893b62 commit 887ce95
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/transformers/models/mixtral/modeling_mixtral.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def load_balancing_loss_func(
# Compute the mask that masks all padding tokens as 0 with the same shape of expert_mask
expert_attention_mask = (
attention_mask[None, :, :, None, None]
.expand((num_hidden_layers, batch_size, sequence_length, 2, num_experts))
.reshape(-1, 2, num_experts)
.expand((num_hidden_layers, batch_size, sequence_length, top_k, num_experts))
.reshape(-1, top_k, num_experts)
.to(compute_device)
)

Expand Down

0 comments on commit 887ce95

Please sign in to comment.