Skip to content

[Frontend] grouped_mm runs one program per group with rows and reads its weight once - #489

Merged
student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
fe/gmm-weight-once
Oct 28, 2026
Merged

student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
fe/gmm-weight-once

Conversation

@student-Jungmin

@student-Jungmin student-Jungmin commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

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)

  • A program is one group with rows: it walks the group's rows BM at a time. When the B tile holds all of K (BK == KP) it is read 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 (_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.
  • Without that, a decode step (8 rows over 128 experts) ran a program per expert and read all 128 weights: layer decode S4096 timed 849.7 us against v6e's 114.1 us.
  • tests/ops/gemm/test_grouped_mm.py: one_program_per_group pins the grid (8 programs for 8 groups with rows); few_rows pins 4 programs for 4 rows over 16 groups. All 8 cases pass locally.

Numbers (harness: PyTorchSim's validation bundle of layer_layer_* and layer_op_gmm_*, simulated with PTB validation/layer/simulate_shapes.py; PTB main 940c671c, TOGSim 1f05af9, tpuv6e; before = main's CI on 940c671c)

workload TOGSim / v6e, main CI this PR
gmm_down T1 0.875 0.884
gmm_down T2048 1.059 0.943
gmm_down T4096 1.629 0.909
gmm_gate_up T1 0.933 0.940
gmm_gate_up T2048 1.042 0.979
gmm_gate_up T4096 (CI timeout) 0.870
layer prefill S1024 1.111 1.074
layer prefill S2048 1.129 1.088
layer prefill S4096 (CI timeout) 0.980
layer decode S4096 1.058 1.062

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.

…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 student-Jungmin changed the title [Frontend] grouped_mm runs one program per group and reads a group's weight once [Frontend] grouped_mm runs one program per group with rows and reads its weight once Oct 27, 2026
@student-Jungmin
student-Jungmin merged commit 6ab1ba0 into pytorchsim-triton-backend Oct 28, 2026
6 checks passed
@YWHyuk
YWHyuk deleted the fe/gmm-weight-once branch October 28, 2026 00:55
@YunseonShin YunseonShin mentioned this pull request Oct 28, 2026
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.

1 participant