Fix the bug that the layout kernel crashed when the num of experts is no less than 384#383
Fix the bug that the layout kernel crashed when the num of experts is no less than 384#383Yael-X merged 2 commits intosgl-project:mainfrom
Conversation
… no less than 384
Summary of ChangesHello @luanyundu, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request resolves a layout kernel crash that occurred with a high number of experts. The solution involves a comprehensive refactoring of the expert dispatching mechanism, primarily by correcting how data sizes and indices are calculated and managed within the Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request addresses a crash in the layout kernel when dealing with a large number of experts. The core of the fix involves correcting buffer size calculations and indexing logic, replacing num_experts with the more appropriate num_topk in several key areas. This change is propagated through the C++ kernels and the corresponding Python tests.
While the primary fix appears correct, my review has identified several critical issues where the refactoring has removed necessary bounds checks, potentially leading to new out-of-bounds memory access bugs when handling invalid expert indices. I have provided suggestions to reintroduce these checks. Additionally, I've noted that a relevant test case has been disabled and recommended re-enabling it to serve as a regression test.
…-npu into sgl-cmake2 * 'sgl-cmake2' of https://github.com/1329009851/sgl-kernel-npu: Fix the bug that the layout kernel crashed when the num of experts is no less than 384 (sgl-project#383) adapt sglang (sgl-project#357) GLM5 optimize (sgl-project#382) Update layernorm_gated.py (sgl-project#378) support qwen3.5 (sgl-project#377)
… no less than 384 (sgl-project#383) * Fix the bug that the layout kernel crashed when the num of experts is no less than 384 * Modify review suggestions
--num-experts=256
Server 0
[tuning] Dispatch (BF16) 36.19 GB/s (HCCS), 9.06 GB/s (RDMA), avg_t: 12916.85 us, notify_t: 3747.06 us
[tuning] Combine 53.96 GB/s (HCCS), 13.51 GB/s (RDMA), avg_t: 8662.11 us
Server 1
[tuning] Dispatch (BF16) 35.43 GB/s (HCCS), 8.81 GB/s (RDMA), avg_t: 13284.70 us, notify_t: 3209.65 us
[tuning] Combine 54.56 GB/s (HCCS), 13.56 GB/s (RDMA), avg_t: 8628.18 us
--num-experts=384
Server 0
[tuning] Dispatch (BF16) 33.80 GB/s (HCCS), 8.44 GB/s (RDMA), avg_t: 13857.38 us, notify_t: 3880.77 us
[tuning] Combine 52.96 GB/s (HCCS), 13.23 GB/s (RDMA), avg_t: 8844.66 us
Server 1
[tuning] Dispatch (BF16) 34.40 GB/s (HCCS), 8.52 GB/s (RDMA), avg_t: 13735.61 us, notify_t: 4084.84 us
[tuning] Combine 53.49 GB/s (HCCS), 13.25 GB/s (RDMA), avg_t: 8832.54 us
--num-experts=512
Server 0
[tuning] Dispatch (BF16) 37.66 GB/s (HCCS), 9.42 GB/s (RDMA), avg_t: 12425.59 us, notify_t: 3593.53 us
[tuning] Combine 52.35 GB/s (HCCS), 13.10 GB/s (RDMA), avg_t: 8938.52 us
Server 1
[tuning] Dispatch (BF16) 42.45 GB/s (HCCS), 10.68 GB/s (RDMA), avg_t: 10955.64 us, notify_t: 5023.46 us
[tuning] Combine 51.75 GB/s (HCCS), 13.02 GB/s (RDMA), avg_t: 8986.22 us
In all cases , the average duration of layout kernel is less than 0.35ms.