-
Notifications
You must be signed in to change notification settings - Fork 734
[Cherry-Pick] Fix moe topk select bug in cudagraph(#7069) #7070
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -185,16 +185,17 @@ def moe_topk_select( | |
| probs_for_choice.reshape([seq_length, n_group, -1]).topk(2, axis=-1)[0].sum(axis=-1) | ||
| ) # [seq_len, n_group] | ||
| group_idx = paddle.topk(group_scores, k=topk_group, axis=-1, sorted=True)[1] # [seq_len, topk_group] | ||
| group_mask = paddle.zeros_like(group_scores).put_along_axis( | ||
| group_idx, paddle.to_tensor(1.0, dtype=group_scores.dtype), axis=-1 | ||
| group_mask = paddle.sum( | ||
| paddle.nn.functional.one_hot(group_idx, num_classes=n_group).cast(group_scores.dtype), | ||
| axis=1, # Sum over topk_group dimension -> [seq_len, n_group] | ||
| ) | ||
|
Comment on lines
+189
to
191
|
||
| score_mask = ( | ||
| group_mask.unsqueeze(-1).expand([seq_length, n_group, n_experts // n_group]).reshape([seq_length, -1]) | ||
| ) # [seq_len, n_experts] | ||
| probs_for_choice = probs_for_choice.masked_fill(~score_mask.astype(paddle.bool), float("-inf")) | ||
|
|
||
| _, topk_ids = paddle.topk(probs_for_choice, top_k, axis=-1) | ||
| topk_weights = paddle.take_along_axis(gate_probs, topk_ids, axis=-1) | ||
| topk_weights = paddle.index_sample(gate_probs, topk_ids) | ||
|
Comment on lines
197
to
+198
|
||
|
|
||
| # normalize combine weights | ||
| if renormalize: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
当前 PR 标题不符合仓库 Cherry-Pick 约定:需要在
[Cherry-Pick]后包含至少一个标签(如[BugFix]),并在标题末尾追加原 develop PR 号(此处应为(#7069)),否则可能触发 CI 的 Cherry-Pick 校验失败。建议按模板格式调整标题。