Skip to content

[Refactor 1/9] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass - #449

Merged
student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
refactor/r441-1-layout
Oct 24, 2026
Merged

student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
refactor/r441-1-layout

Conversation

@student-Jungmin

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

Copy link
Copy Markdown
Collaborator

Draft: waiting for verification (CI and the validation reports) before review.

Part 1 of 9 of the frontend refactor. It is one commit (fb09d09) of this part's final state, so each part reviews on its own. Based on pytorchsim-triton-backend (dd80d8c, #443).

What

This part also carries what #440 and #441 (split from #433; rebased as #458 and #459, now closed) did, so the refactor starts from pytorchsim-triton-backend itself:

  • transformers' grouped_mm_fallback takes aten._grouped_mm's npu kernel. It is registered at AutogradPrivateUse1 and PrivateUse1 of transformers::grouped_mm_fallback, and the dense rewrite goes. This is a behavior change, pinned by test_grouped_mm's fallback case.
  • rewrite_fx_graph is post_grad_pass, the npu's device_custom_pass. It judges complex values per component, counts histc on the device, makes its nodes through FX's tracer and keeps its complex ops in one table, _REAL_PAIR.

Moves and renames only, no behavior change. inductor_patches.py splits by kind into
frontend/inductor/ (choices, selection, npu as a Triton GPU); topk, grouped_mm and attention go
to frontend/dispatcher/; each layer's install() applies what npu plugs into it. driver/ is
backend/: what compiles and launches a kernel after the frontend. scripts/op_coverage.py goes,
and tests/_pytorchsim_utils.py is tests/result_check.py with check_result.

Behavior change

grouped_mm_fallback's route (above). Everything else here is a move or a rename.

Checked locally

At this PR's tip, with PTB 522042a (this branch's pin) and TOGSim b9c9519, everything passes: test_add 5/5, test_matmul 11/11, test_histc, test_eager, test_patch_scope 8/8.

No cycle numbers here: nothing in this part is meant to change a kernel's cycles. The CI validation report is the check.

Comments and docstrings in the files these parts change are at most three lines, none inside a function body. What they no longer say is in the commit message. Test files whose only change here is an import rename (test_result -> check_result) and scripts/ keep their comments, as this change did not touch that code.

@student-Jungmin student-Jungmin changed the title [Refactor 1/8] frontend/ is one package per torch.compile layer, driver/ is backend/ [Refactor 1/5] frontend/ is one package per torch.compile layer, driver/ is backend/ Oct 24, 2026
…is backend/, and rewrite_fx_graph is post_grad_pass

Moves and renames only, no behavior change. inductor_patches.py splits by kind into
frontend/inductor/ (choices, selection, npu as a Triton GPU); topk, grouped_mm and attention go
to frontend/dispatcher/; each layer's install() applies what npu plugs into it. driver/ is
backend/: what compiles and launches a kernel after the frontend. scripts/op_coverage.py goes,
and tests/_pytorchsim_utils.py is tests/result_check.py with check_result.

Comments and docstrings in the files this part changes are at most three lines, none inside a function body. What they no longer say:

backend/compiler_bridge.py: run_pipeline stops at the ELF since spike and verify want tensors and a per-kernel reference this route has no graph-level answer for.



This part also carries what #440 and #441 (split from #433, last as #458 and #459) did, so the refactor starts from pytorchsim-triton-backend itself: transformers' grouped_mm_fallback takes aten._grouped_mm's npu kernel (registered at AutogradPrivateUse1 and PrivateUse1 of transformers::grouped_mm_fallback; the dense rewrite goes), and rewrite_fx_graph is post_grad_pass, the npu's device_custom_pass, judging complex values per component, counting histc on the device, making its nodes through FX's tracer and keeping its complex ops in one table, _REAL_PAIR. test_grouped_mm's fallback case pins the first.
@student-Jungmin student-Jungmin changed the title [Refactor 1/5] frontend/ is one package per torch.compile layer, driver/ is backend/ [Refactor 1/5] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass Oct 24, 2026
@student-Jungmin
student-Jungmin changed the base branch from split/433-post-grad-pass to pytorchsim-triton-backend October 24, 2026 11:16
@student-Jungmin student-Jungmin changed the title [Refactor 1/5] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass [Refactor 1/6] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 1/6] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass [Refactor 1/7] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 1/7] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass [Refactor 1/8] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass Oct 24, 2026
@student-Jungmin student-Jungmin changed the title [Refactor 1/8] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass [Refactor 1/9] frontend/ is one package per torch.compile layer, driver/ is backend/, rewrite_fx_graph is post_grad_pass Oct 24, 2026
@student-Jungmin
student-Jungmin marked this pull request as ready for review October 24, 2026 13:59
@student-Jungmin
student-Jungmin merged commit 2903d95 into pytorchsim-triton-backend Oct 24, 2026
@YWHyuk
YWHyuk deleted the refactor/r441-1-layout branch October 27, 2026 07:46
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