Repository navigation
[Frontend] grouped_mm runs one program per group with rows and reads its weight once - #489
Merged
Merged
Conversation
…its weight once The grouped kernel ran one program per BM-row block of a group, and each program read the group's whole weight tile (BK covers K, so its K loop ran once). Every block read the expert's weight again: Qwen3-30B-A3B's gmm_down reads 383 x 3 MB at T4096 (255 x at T2048), and the TOG was bound on HBM (MXU 21% busy), where v6e's grouped matmul reads each expert's weight about once. A program is now one group with rows: it walks the group's rows BM at a time, and when the B tile holds all of K (BK == KP) reads it once before the walk. Otherwise each row block walks K as before. At most A's rows groups have rows, so the grid is min(groups, rows) programs: program i takes the i-th group with rows from a table: the group whose running count of groups with rows is i + 1, with its first row and row count, all three zero for a program left over, which then reads nothing. The table the TOG reads is that group, first row and row count per program. test_grouped_mm pins the grid: one program per group with rows (8 for 8 groups with rows, 4 for 4 rows over 16 groups). Measured locally on the validation bundle's kernels against PTB main 940c671c (TOGSim 1f05af9, tpuv6e), TOGSim / v6e, main's CI (940c671c) -> this commit: gmm_down T1 0.875 -> 0.884, gmm_gate_up T1 0.933 -> 0.940; layer decode S4096 1.058 -> 1.062. At T >= 128 A has at least as many rows as there are groups, so the grid is one program per group, as it was before the table; measured with that earlier table: gmm_down T2048 1.059 -> 0.943, T4096 1.629 -> 0.909; gmm_gate_up T2048 1.042 -> 0.979, T4096 (CI timeout) -> 0.870; layer prefill S1024 1.111 -> 1.074, S2048 1.129 -> 1.088, S4096 (CI timeout) -> 0.980.
student-Jungmin
force-pushed
the
fe/gmm-weight-once
branch
from
October 27, 2026 22:13
7c0b9c1 to
22bb947
Compare
Merged
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.
The grouped kernel ran one program per BM-row block of a group, and every program read the group's whole weight tile (BK covers K, so its K loop ran once). Each block re-read the expert's weight: Qwen3-30B-A3B's gmm_down reads 383 x 3 MB at T4096 (255 x at T2048), so the TOG is bound on HBM (MXU 21% busy), where v6e's grouped matmul reads each expert's weight about once.
Change (
pytorchsim/frontend/dispatcher/grouped_mm.py)BK == KP) it is read once before the walk; otherwise each row block walks K as before.min(groups, rows)programs. Program i takes the i-th group with rows from a table (_groups): the group whose running count of groups with rows is i + 1, its first row and its row count, all three zero for a program left over, which then reads nothing. That table is what the TOG reads.tests/ops/gemm/test_grouped_mm.py:one_program_per_grouppins the grid (8 programs for 8 groups with rows);few_rowspins 4 programs for 4 rows over 16 groups. All 8 cases pass locally.Numbers (harness: PyTorchSim's validation bundle of
layer_layer_*andlayer_op_gmm_*, simulated with PTBvalidation/layer/simulate_shapes.py; PTB main 940c671c, TOGSim 1f05af9, tpuv6e; before = main's CI on 940c671c)T >= 128 has A rows at least the group count, so its grid is one program per group as before the table; those rows were measured with the earlier table. T1 and decode S4096 are this commit's kernel.
Open: gmm_gate_up T4096 (0.870) and both T1 ops are on the fast side. Layer prefill S4096 0.980 includes combine (fast) and dispatch gather (slow) partly cancelling.
PTB #389 carries this PR's kernels into
validation/pytorchsim; its bundle is rebuilt from this head.