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

[ENHANCEMENT] add options how to choose topk devices for device_limited_topk #1378

Open
bzantium opened this issue Feb 6, 2025 · 0 comments · May be fixed by #1381
Open

[ENHANCEMENT] add options how to choose topk devices for device_limited_topk #1378

bzantium opened this issue Feb 6, 2025 · 0 comments · May be fixed by #1381

Comments

@bzantium
Copy link

bzantium commented Feb 6, 2025

Is your feature request related to a problem? Please describe.
Based on the original implementation for deepseek-v3, they use top-2 and sum instead of max to choose topk groups.

if self.topk_method == "noaux_tc":
    scores_for_choice = scores.view(bsz * seq_len, -1) + self.e_score_correction_bias.unsqueeze(0)
    group_scores = (
    scores_for_choice.view(bsz * seq_len, self.n_group, -1).topk(2, dim=-1)[0].sum(dim = -1)

but in Megatron-LM, it only uses max like:

    num_group = (
        parallel_state.get_expert_model_parallel_world_size()
    )  # num_group equals to expert parallel size
    group_scores = scores.view(num_tokens, num_group, -1).max(dim=-1).values
    group_idx = torch.topk(group_scores, k=moe_router_topk_limited_devices, dim=-1, sorted=False)[1]

However, DeepSeek-V2 technical report and implementation suggest to use max so giving options (between two) would be the solution.

@bzantium bzantium changed the title [ENHANCEMENT] use sum instead of max for device_limited_topk [ENHANCEMENT] add options how to choose topk devices for device_limited_topk Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant