Skip to content

[Frontend] One module for our FX graph rewrites: rewrite_fx_graph.py - #323

Merged
student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
rewrite-fx-graph
Oct 9, 2026
Merged

student-Jungmin merged 1 commit into
pytorchsim-triton-backendfrom
rewrite-fx-graph

Conversation

@student-Jungmin

Copy link
Copy Markdown
Collaborator

Merges extension_decomposition.py (histc, polar), extension_topk.py, extension_grouped_mm.py, extension_complex_to_real.py and the extension_fx.py chain they share into one module, PyTorchSimFrontend/rewrite_fx_graph.py, with a single install() called from torch_openreg.

All five did the same job: rewrite ops with no npu kernel into aten ops the backend lowers, so the work stays on the device instead of falling back to the CPU. They were installed three different ways (on import, by an explicit install(), by decorator). The rewrites themselves are unchanged; the post-grad chain keeps its order (grouped_mm, topk, complex) and its keys, so Inductor cache keys do not move. Comments are cut to the repo's docstring rule.

CLAUDE.md now points at the new module and says where work goes: a branch on PSAL-POSTECH/PyTorchSim and a PR into pytorchsim-triton-backend.

Verified (cleared cache, functional mode)

  • test_complex_to_real, test_polar, test_histc, test_expert_mask, test_topk, test_add pass
  • the generated wrappers' only extern call is aten.histc on a float input, which the decomposition leaves to the CPU by design
  • Qwen2-MoE --preset 2-moe fails in the compiler's TTGIR lowering of a sort kernel -- the same failure at the same point on 6ba6e62 without this change

Timing mode was not run: the branch head's TOGSim is at producer ABI 14 while PTB main still emits ABI 13 (see #321).

extension_decomposition (histc, polar), extension_topk,
extension_grouped_mm, extension_complex_to_real and the extension_fx chain
they share all did one thing -- rewrite ops with no npu kernel into aten ops
the backend lowers, so the work stays in the graph -- and were installed three
different ways. They are now one module with one install(), called once from
torch_openreg. The rewrites are unchanged; the chain keeps its order
(grouped_mm, topk, complex) and its keys, so Inductor cache keys do not move.
Comments are cut to the docstring rule.

CLAUDE.md points at the new module and says where work goes now: a branch on
PSAL-POSTECH/PyTorchSim and a PR into pytorchsim-triton-backend.

Verified on a cleared cache: test_complex_to_real, test_polar, test_histc,
test_expert_mask, test_topk, test_add pass; the only extern left is histc on
a float input, which the decomposition leaves to the CPU by design. Qwen2-MoE
(--preset 2-moe) fails in the compiler's TTGIR lowering of a sort kernel, the
same failure at the same point on 6ba6e62 without this change.
@student-Jungmin
student-Jungmin merged commit 1c5dde5 into pytorchsim-triton-backend Oct 9, 2026
@student-Jungmin
student-Jungmin deleted the rewrite-fx-graph branch October 9, 2026 05:26
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