Repository navigation
[Frontend] aten._grouped_mm on the npu is one Triton kernel whose blocks read their expert from launch data - #412
Merged
Conversation
…cks read their expert from launch data torch.nn.functional.grouped_mm (Qwen3-30B-A3B's MoE experts) reached the npu as aten._grouped_mm and ran on the host: the simulator priced it at zero. Its npu kernel is now registered through torch.library at AutogradPrivateUse1 and PrivateUse1, as attention's is, and calls torchsim::grouped_mm, a triton_op in vLLM's fused_moe form: a program is a block of at most BM rows of one group, its group, first row and row count read from a table; a block without rows runs its K loop zero times. The grid is the most blocks any offs needs, and no more than the row count. BM is the lanes, BN and BK the largest tile of the machine's mm rule. A call the kernel does not take (bias, out_dtype, other ranks, a gradient) and every eager call run group by group with matmul; the first are logged with why. timing.py appends each argument the TOG reads as data (tile_types' data_args) to the launch's shape_args. Needs the compiler's TOG data args (PTB, local: eec250c, d9f390c, a0a47b3). tests/ops/gemm/test_grouped_mm.py pins the route (one launch, nothing left to aten), few rows, eager and gradients.
YWHyuk
marked this pull request as ready for review
October 23, 2026 03:00
YWHyuk
added a commit
that referenced
this pull request
Oct 23, 2026
…me attributes replace them a5d1fbd (#412) appended the elements of every argument tile_types.json lists as data_args to the launch's shape_args (timing.data_values), so the TOG could read the grouped GEMM's group, start and row tables from the launch. That is the compiler side of PTB #282 (torchsim.data), which was rejected and is closed; no compiler the pin can reach writes data_args. PTB #315's runtime attributes replace it: the functional run records each value the TOG reads from data under runtime/runtime_attribute/, and TOGSim reads those records (the commit before this one), so the values never travel through shape_args. data_values and _write_extents' data argument are removed and shape_args is the grid again, as before #412. The grouped_mm frontend, its registration and tests/ops/gemm/test_grouped_mm.py stay; the frontend's docstring now says the TOG reads the table as runtime attributes.
YWHyuk
added a commit
that referenced
this pull request
Oct 23, 2026
…me attributes replace them a5d1fbd (#412) appended the elements of every argument tile_types.json lists as data_args to the launch's shape_args (timing.data_values), so the TOG could read the grouped GEMM's group, start and row tables from the launch. That is the compiler side of PTB #282 (torchsim.data), which was rejected and is closed; no compiler the pin can reach writes data_args. PTB #315's runtime attributes replace it: the functional run records each value the TOG reads from data under runtime/runtime_attribute/, and TOGSim reads those records (the commit before this one), so the values never travel through shape_args. data_values and _write_extents' data argument are removed and shape_args is the grid again, as before #412. The grouped_mm frontend, its registration and tests/ops/gemm/test_grouped_mm.py stay; the frontend's docstring now says the TOG reads the table as runtime attributes.
YWHyuk
added a commit
that referenced
this pull request
Oct 23, 2026
…me attributes replace them a5d1fbd (#412) appended the elements of every argument tile_types.json lists as data_args to the launch's shape_args (timing.data_values), so the TOG could read the grouped GEMM's group, start and row tables from the launch. That is the compiler side of PTB #282 (torchsim.data), which was rejected and is closed; no compiler the pin can reach writes data_args. PTB #315's runtime attributes replace it: the functional run records each value the TOG reads from data under runtime/runtime_attribute/, and TOGSim reads those records (the commit before this one), so the values never travel through shape_args. data_values and _write_extents' data argument are removed and shape_args is the grid again, as before #412. The grouped_mm frontend, its registration and tests/ops/gemm/test_grouped_mm.py stay; the frontend's docstring now says the TOG reads the table as runtime attributes.
YWHyuk
pushed a commit
that referenced
this pull request
Oct 23, 2026
… npu kernel; the dense rewrite goes transformers 5.x calls torch.ops.transformers.grouped_mm_fallback instead of aten._grouped_mm under torch.compile when the weight is not bf16 (integrations/moe.py _can_use_grouped_mm). rewrite_fx_graph rewrote it into a dense form: every expert's mm over every row, masked and summed, E times the work, which TOGSim then priced. grouped_mm.install now registers the same entry (_aten_grouped_mm, so the same triton_op and kernel, gate and math route) at AutogradPrivateUse1 and PrivateUse1 of transformers::grouped_mm_fallback too. The registration precedes transformers' own definition of the op and outranks its Autograd and CompositeExplicitAutograd kernels on the npu only; the CPU keeps transformers' kernel. rewrite_transformers_grouped_mm_fallback, _grouped_mm_target and _emit_dense_grouped_mm are removed. Needs aten._grouped_mm's npu kernel (PyTorchSim #412, on pytorchsim-triton-backend as a5d1fbd) and, for timing, the compiler's TOG data args (PyTorchSim-Triton-Backend #282, not yet in the pinned PTB). tests/ops/gemm/test_grouped_mm.py: case fallback runs the fallback op at f32 compiled and asks for one grouped-kernel launch and no extern call.
YWHyuk
added a commit
that referenced
this pull request
Oct 23, 2026
…me attributes replace them a5d1fbd (#412) appended the elements of every argument tile_types.json lists as data_args to the launch's shape_args (timing.data_values), so the TOG could read the grouped GEMM's group, start and row tables from the launch. That is the compiler side of PTB #282 (torchsim.data), which was rejected and is closed; no compiler the pin can reach writes data_args. PTB #315's runtime attributes replace it: the functional run records each value the TOG reads from data under runtime/runtime_attribute/, and TOGSim reads those records (the commit before this one), so the values never travel through shape_args. data_values and _write_extents' data argument are removed and shape_args is the grid again, as before #412. The grouped_mm frontend, its registration and tests/ops/gemm/test_grouped_mm.py stay; the frontend's docstring now says the TOG reads the table as runtime attributes.
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.
torch.nn.functional.grouped_mm(Qwen3-30B-A3B's MoE experts) reaches the npu asaten._grouped_mmand runs on the host: the simulator prices it at zero and the layer suite marks every layer row incomplete.Change
pytorchsim/frontend/grouped_mm.py: the op's npu kernel is registered throughtorch.libraryat AutogradPrivateUse1 and PrivateUse1, as attention's is, and callstorchsim::grouped_mm, atriton_opin vLLM's fused_moe form.offsneeds ((s + g·(BM−1)) // BM), and no more than the row counts.tiling.gemm_tile_candidates).pytorchsim/simulator/timing.py: each argument the TOG reads as data (tile_types.json'sdata_args) is appended to the launch'sshape_args.Depends on PSAL-POSTECH/PyTorchSim-Triton-Backend#282 (the TOG takes the table as data) and a compiler pin past it; draft until then. Without it the compile stops at tog.
Tests:
tests/ops/gemm/test_grouped_mm.py(in the allowlist and the workflow matrix): routed (uneven groups, empty ones, one past BM: one launch, nothing left to aten), few rows, eager, gradients. All four pass locally on this branch with PSAL-POSTECH/PyTorchSim-Triton-Backend#282's compiler (functional mode on).Numbers: local only until the pin moves; see PSAL-POSTECH/PyTorchSim-Triton-Backend#282.