Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dont save moe lb-loss tensors if args.moe_loss_weight=0 #119

Merged
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
5 changes: 4 additions & 1 deletion megablocks/layers/moe.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ def clear_load_balancing_loss():


def batched_load_balancing_loss(args : Arguments):
if args.moe_loss_weight == 0:
return 0.0

# tokens_per_expert[i].shape = (num_experts)
# expert_scores[i].shape = (tokens, num_experts)
tokens_per_expert, expert_scores = zip(*get_load_balancing_loss())
Expand Down Expand Up @@ -424,7 +427,7 @@ def forward(self, x, scores, expert_weights, top_experts):
# Compute the experts.
x, tokens_per_expert = self.forward_fn(
x, expert_weights, top_experts)
if self.training:
if self.training and self.args.moe_loss_weight > 0:
save_load_balancing_loss((tokens_per_expert, scores))
x = x.view(in_shape)
if self.bias is not None:
Expand Down