Repository navigation
docs(cuda): record the MoE expert overlap and why no grouped kernel - #2796
Merged
Merged
Conversation
A kernel reading each selected expert once could cut Gemma 4 26B's gather reads by 30.4% at 8 clients with different prompts, and 12.5% at 4. Timing the live path over distinct experts bounds that at about 22% of a gather and about 13% aggregate at 8 clients, before a real kernel's cost for the other rows. That does not justify a variable-row kernel for one decode path, so none was built. `MLXCEL_PROFILE_MOE_INNER=1` now prints the distinct-expert count so this can be repeated. The fold record's 1.9 ms attention figure came from repeated prompts; with different prompts it is about 4.8 ms, and the record now says so. Closes #2784
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#2784 asked how much a kernel that reads each selected expert once could save, and to close with the number if it is small. The conclusion is not to build it. Record:
docs/benchmark_results/moe-distinct-experts-n1x-2026-10-31.md.Gemma 4 26B on an RTX Spark N1X, 8 different prompts, temperature 0:
Timing
gate_projover only distinct experts in the live path gives about 1.95 ms against about 2.5 ms for 64 pairs. Gathers are about 54% of a layer, so a perfect grouped kernel saves about 13% aggregate at 8 clients. That omits the kernel's cost for the other rows, and 4 clients, the default slot count, would gain about 5% by the same ratio. The times use forced evals, so only the ratios are used, and that timing patch is not in this PR.Corrections
scripts/bench_serving_concurrency.pysends one prompt to every client, so identical rows pick the same experts (87.5% read reduction here). The fold record now notes this. Shared-weight reads do not depend on prompt content.Behavior
MLXCEL_PROFILE_MOE_INNER=1also prints[MOE] name=distinct_experts tokens=T pairs=P distinct=D. It readsindicesback to the host only under that variable.Not measured
Other MoE models and GB10. gpt-oss 20B has E=32, so it can overlap more, but its mxfp4 gather takes a different kernel.
fmt, clippy on the lib with
--features cuda, and the env var docs check pass locally.Closes #2784