Repository navigation
[Frontend] transformers' grouped_mm_fallback takes aten._grouped_mm's npu kernel; the dense rewrite goes - #458
Closed
student-Jungmin wants to merge 1 commit into
Closed
student-Jungmin wants to merge 1 commit into
student-Jungmin wants to merge 1 commit into
Conversation
… 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_grouped_mm, _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.
This was referenced Oct 24, 2026
Collaborator
Author
|
Folded into the refactor's part 1, #449, which now starts from pytorchsim-triton-backend and carries these commits' changes; closing. |
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.
Supersedes #440, rebased onto
pytorchsim-triton-backenddd80d8c (#443, kernel object format 8). Same commit and author; only the base moved.The one conflict:
rewrite_fx_graph.py. The commit was made while topk still lived there, and #439 has since moved it out. The resolution keeps upstream's file and removes only what this commit removes: the densegrouped_mm_fallbackrewrite and its install line.primsgoes too, now that nothing uses it.Run on this branch at PTB 522042a (the pin): test_add 5/5, test_matmul 11/11, test_grouped_mm 6/6, test_topk, test_eager, test_patch_scope 8/8, test_cache_identity pass.
Original description (#440):
Split out of #433 by @student-Jungmin (commit 6886059), author kept. In #433 it sat after the snake-case rename and the topk commit; here it applies to the current base alone, in the pre-refactor layout:
rewrite_grouped_mm(its old name) and its helpers are removed,. Thegrouped_mm.pydocstring keeps the base's wording from #418 ("reads as runtime attributes").What
transformers 5.x calls
torch.ops.transformers.grouped_mm_fallbackinstead ofaten._grouped_mmunder torch.compile when the weight is not bf16.rewrite_fx_graphrewrote it into a dense form: every expert's mm over every row, masked and summed, E times the work.grouped_mm.installnow registers the same entry (_aten_grouped_mm: same triton_op, kernel, gate and math route) at AutogradPrivateUse1 and PrivateUse1 oftransformers::grouped_mm_fallbacktoo. It outranks transformers' Autograd and CompositeExplicitAutograd kernels on the npu only; the CPU keeps transformers' kernel.Tests
tests/ops/gemm/test_grouped_mm.pycasefallbackruns the fallback op at f32 compiled and asks for one grouped-kernel launch and no extern call. Run on this branch (functional mode, timing off, 128 s): routed, few_rows, eager, grad, fallback PASS.Split of #433
#433 (@student-Jungmin, branch
refactor/post-grad-pass) is split into four PRs. #433 itself is left as it is.split/433-complex-scalarpytorchsim-triton-backendsplit/433-npu-topkpytorchsim-triton-backendsplit/433-grouped-mm-fallbackgrouped_mm_fallbacktakesaten._grouped_mm's npu kernel (6886059)pytorchsim-triton-backendsplit/433-post-grad-passpytorchsim-triton-backendThe three feature PRs each apply to the current base on their own, in the pre-refactor file layout (
rewrite_fx_graph.py). #439 and #440 both remove a rewrite fromrewrite_fx_graph.pynext to each other, so whichever merges second needs a trivial rebase; #441 already holds that resolution. Applying #438 → #439 → #440 → #441 gives exactly the tree of #433's head 9ff24d3 rebased onto the current base (git diffempty).🤖 Generated with Claude Code
https://claude.ai/code/session_011cGNfHFySFsi7feZKKvq7e