roofline: emit per-expert routing histogram (tokens_per_expert) for MoE launches - #53
Merged
Merged
Conversation
…oE launches count_active_experts already reads the MUL_MAT_ID ids tensor back to host once per invocation to count distinct routed experts; the same pass now also fills a per-expert token-count array. begin_op stores it per invocation and write_report emits it as "tokens_per_expert" (length n_experts, index e = routings to expert e, Σ = n_tokens*top_k) alongside experts_used. No new device work or sync — the ids read-back already happens for experts_used. The consumer renders it as the MoE routing-load distribution under --show-histograms.
roberteg16
requested review from
Annieren,
jimw567,
liangliangchang and
mgehre-amd
July 16, 2026 10:45
roberteg16
marked this pull request as ready for review
July 16, 2026 10:45
mgehre-amd
approved these changes
Jul 17, 2026
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.
Summary
count_active_expertscopies theMUL_MAT_IDidstensor to host once per invocation to count the distinct routed experts. The same pass now also fills a per-expert token-count array.begin_opstores it per invocation andwrite_reportemits it astokens_per_expert(lengthn_experts, index e = routings to expert e, Σ =n_tokens*top_k) next toexperts_used.idsread-back already happens forexperts_used; this replaces theseen[]bitmap with acounts[]array and adds one JSON field.idswere read back; non-MoE rows are unchanged, and consumers that don't know the field ignore it.Test plan
ggml-cuda-roofline.cppcompiles clean with the project's exact build flags (host-only TU).GGML_ROOFLINE_OUT=... llama-bench -m granite-3.0-1b-a400m-Q4_K_M.gguf -p 64 -ngl 99→ all 71MUL_MAT_IDrows carrytokens_per_expert, withlen == n_experts,Σ == M*top_k, andnonzero == experts_usedon every row.