Skip to content

Commit

Permalink
Fix moe_normalize_expert_weights when top_k=1 (#87)
Browse files Browse the repository at this point in the history
* normalize router weights *before* squeezing dim on top-k=1

* keep top-1 optimisation

* Update router.py
  • Loading branch information
152334H authored Jan 10, 2024
1 parent bcb4979 commit 04e4f1f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions megablocks/layers/router.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ def jitter(self, x):

def _top_k(self, scores):
if self.args.moe_top_k == 1:
return scores.max(dim=-1)
return scores.max(dim=-1,keepdim=True)
return torch.topk(scores, self.args.moe_top_k, dim=-1)


def forward(self, x):
if self.training and self.args.moe_jitter_eps is not None:
x = x * self.jitter(x)
Expand Down

0 comments on commit 04e4f1f

Please sign in to comment.