Skip to content

[Frontend] A complex scalar times a complex value is a complex product in the real pairs - #438

Merged
YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
split/433-complex-scalar
Oct 23, 2026
Merged

YWHyuk merged 1 commit into
pytorchsim-triton-backendfrom
split/433-complex-scalar

Conversation

@YWHyuk

@YWHyuk YWHyuk commented Oct 23, 2026 •

Copy link
Copy Markdown
Collaborator

Split out of #433 by @student-Jungmin (commit 31747c8), author kept. Applies to the current pytorchsim-triton-backend unchanged.

What

ComplexToRealPairs multiplied the [..., 2] pair of a complex value by the other operand whenever that operand was not a complex node. Post-grad, z * (1+2j) is aten.mul.Tensor(z, (1+2j)), so the pair was multiplied by the Python complex itself: the result came out complex64 with wrong values and no warning. A Python complex operand now takes the same (ar*br - ai*bi, ar*bi + ai*br) form as two complex nodes; a real scalar or tensor still scales the pair. The pass uuid moves to -3 so Inductor's FX cache does not replay a graph the old pass rewrote. torch 2.14 still does not lower complex mul, so the pass stays.

Tests

tests/ops/misc/test_complex_to_real.py test_complex_scalar_multiply puts a complex scalar on each side; it fails on the old pass (three aten.mul.Tensor left complex). Run on this branch (functional mode, timing off): rewritten graph, complex scalar and RoPE-on-device pass.

Split of #433

#433 (@student-Jungmin, branch refactor/post-grad-pass) is split into four PRs. #433 itself is left as it is.

PR branch content base
#438 split/433-complex-scalar complex scalar × complex value (31747c8) pytorchsim-triton-backend
#439 split/433-npu-topk topk on the npu is one Triton kernel (1c43abc) pytorchsim-triton-backend
#440 split/433-grouped-mm-fallback transformers' grouped_mm_fallback takes aten._grouped_mm's npu kernel (6886059) pytorchsim-triton-backend
#441 split/433-post-grad-pass the 9 refactor commits squashed into 3, on top of #438 + #439 + #440 pytorchsim-triton-backend

The 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 from rewrite_fx_graph.py next 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 diff empty).

🤖 Generated with Claude Code

https://claude.ai/code/session_011cGNfHFySFsi7feZKKvq7e

…t in the real pairs

ComplexToRealPairs multiplied the [..., 2] pair of a complex value by the
other operand whenever that operand was not a complex node. Post-grad,
z * (1+2j) is aten.mul.Tensor(z, (1+2j)), so the pair was multiplied by
the Python complex itself: the result came out complex64 with the wrong
values and no warning. A Python complex operand now takes the same
(ar*br - ai*bi, ar*bi + ai*br) form as two complex nodes; a real scalar or
tensor still scales the pair. The pass uuid moves to -3 so Inductor's FX
cache does not replay a graph the old pass rewrote.

torch 2.14 still does not lower complex mul (lowering.py warns and falls
back; only complex add is decomposed), so the pass stays.

tests/ops/misc/test_complex_to_real.py: test_complex_scalar_multiply puts
a complex scalar on each side; it fails on the old pass (three
aten.mul.Tensor left complex) and passes now.
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.

2 participants