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

[WIP] Working Grouped gemm with group ID #48

Draft
wants to merge 27 commits into
base: main
Choose a base branch
from

Conversation

ElizaWszola
Copy link

@ElizaWszola ElizaWszola commented Dec 17, 2024

No description provided.

ElizaWszola and others added 5 commits December 6, 2024 14:36
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Co-authored-by: Lucas Wilkinson <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Copy link

👋 Hi! Thank you for contributing to the vLLM project.
Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run fastcheck CI which starts running only a small and essential subset of CI tests to quickly catch errors. You can run other CI tests on top of those by going to your fastcheck build on Buildkite UI (linked in the PR checks section) and unblock them. If you do not have permission to unblock, ping simon-mo or khluu to add you in our Buildkite org.

Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging.

To run CI, PR reviewers can do one of these:

  • Add ready label to the PR
  • Enable auto-merge.

🚀

Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
Signed-off-by: ElizaWszola <[email protected]>
expert_offsets[:-1], problem_sizes2,
ab_strides2, ab_strides2, c_strides2)

return (c2[a_map.argsort()].view(m, topk, k) *

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a_map = topk_ids.flatten().argsort()
...
a_map.argsort()

is there a way we can potentially compute these in fused way? (since the second argsort is computing the inverse of the first?) I feel like argsort can sometimes be nightmarishly slow

const torch::Tensor& topk_ids, torch::Tensor& expert_offsets,
torch::Tensor& problem_sizes1, torch::Tensor& problem_sizes2,
torch::Tensor& arg_sort, torch::Tensor& arg_sort_prim,
const int64_t num_experts, const int64_t n, const int64_t k) {
get_a_expert_offsets<<<1, num_experts>>>(
Copy link

@LucasWilkinson LucasWilkinson Feb 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should try to parallelize this across SMs, this will probably involve efficiently using atomicAdd, for the sorting portion I think we should be to do something like this:
https://github.com/vllm-project/vllm/blob/38094584566b89210a6f72a408eba1fae43c3d81/csrc/moe/moe_align_sum_kernels.cu#L260-L291

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For counting occurrences, it might make sense allocate k threads per expert (assert this is less than warpSize), and 256 / k experts (4 warps) per SM (~4-8 warps per SM probably makes sense, since each SM has 4 warp schedulers and on
an H100 we have 132 SMs so even with a low count of 4 experts per-SM we can pretty easily cover all models). Then this loop can be parallerized across the threads allocated to an expert:

  for (int i = 0; i < topk_length; ++i) {
    occurrences += (topk_ids[i] == expert_id);
  }

and we can do an intra-warp reduction right at the end

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 this pull request may close these issues.

2 participants