Skip to content

Commit 04e4f1f

Browse files
authored
Fix moe_normalize_expert_weights when top_k=1 (#87)
* normalize router weights *before* squeezing dim on top-k=1 * keep top-1 optimisation * Update router.py
1 parent bcb4979 commit 04e4f1f

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

megablocks/layers/router.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ def jitter(self, x):
4545

4646
def _top_k(self, scores):
4747
if self.args.moe_top_k == 1:
48-
return scores.max(dim=-1)
48+
return scores.max(dim=-1,keepdim=True)
4949
return torch.topk(scores, self.args.moe_top_k, dim=-1)
5050

51-
5251
def forward(self, x):
5352
if self.training and self.args.moe_jitter_eps is not None:
5453
x = x * self.jitter(x)

0 commit comments

Comments
 (0)