[Draft] feat: flag-gated upstream complex decomposition adapter #4430
Draft
apbose wants to merge 1 commit into
Draft
[Draft] feat: flag-gated upstream complex decomposition adapter #4430apbose wants to merge 1 commit into
apbose wants to merge 1 commit into
Conversation
Adds an alternative complex-numerics lowering path that delegates the interior complex->real expansion to PyTorch's upstream decomposition (decompose_complex_in_graph, pytorch/pytorch#169832) instead of the hand-maintained per-op rewriter in complex_graph_rewrite.py. The new complex_decomposition_adapter pass: - captures the complex I/O signature (reusing the existing helpers) so the post-partition _insert_complex_io_adapters boundary code works unchanged; - calls decompose_complex_in_graph on the exported graph, feeding it the placeholders' fake tensors to preserve the export ShapeEnv/SymInts; - normalizes the SoA aten.complex/real/imag seams it leaves behind into the interleaved [...,2] layout the rest of the TRT flow expects. Wiring: - use_complex_decomposition setting (default False) selects new vs legacy pass via complex_lowering_pass in _aten_lowering_pass; - torch-version capability gate has_complex_decomposition() in _features (torch>=2.14.dev), with graceful fallback to complex_graph_detection. Tests: - test_complex_ops.py parametrized [legacy]/[decomp] via an autouse fixture so the existing suite runs on both paths (decomp auto-skips on torch<2.14); - new GPU-free test_complex_decomposition_adapter.py covering the SoA->[...,2] normalization and the fallback gate. Default off; legacy path unchanged. Boundary normalization assumptions (exact upstream op set, dynamic-shape survival through make_fx) still to be confirmed by a spike; see TODO(spike) in the adapter.
apbose
marked this pull request as draft
July 23, 2026 21:37
There was a problem hiding this comment.
There are some changes that do not conform to Python style guidelines:
--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/passes/_aten_lowering_pass.py 2026-07-23 21:36:54.866947+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/lowering/passes/_aten_lowering_pass.py 2026-07-23 21:37:15.722131+00:00
@@ -42,10 +42,11 @@
otherwise the legacy hand-rolled rewriter runs.
"""
if getattr(settings, "use_complex_decomposition", False):
return complex_decomposition_adapter(gm, settings)
return complex_graph_detection(gm, settings)
+
post_lowering_pass_list = [
replace_fused_rms_norm,
remove_input_alias_fixing_clones,
constant_fold,
--- /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/lowering/test_complex_decomposition_adapter.py 2026-07-23 21:36:54.908527+00:00
+++ /home/runner/work/TensorRT/TensorRT/tests/py/dynamo/lowering/test_complex_decomposition_adapter.py 2026-07-23 21:37:19.335969+00:00
@@ -69,13 +69,11 @@
assert aten.complex.default not in targets
assert aten.cat.default in targets
assert aten.unsqueeze.default in targets
# the packed cat node must carry the complex-layout tag
- cat_nodes = [
- n for n in gm.graph.nodes if n.target == aten.cat.default
- ]
+ cat_nodes = [n for n in gm.graph.nodes if n.target == aten.cat.default]
assert cat_nodes and cat_nodes[0].meta.get("is_complex_layout") is True
# numerically: output is the [...,2] interleaved layout of re/im
out = gm(re, im)
assert out.shape == (3, 2)
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.
Adds an alternative complex-numerics lowering path that delegates the interior complex->real expansion to PyTorch's upstream decomposition (decompose_complex_in_graph, pytorch/pytorch#169832) instead of the hand-maintained per-op rewriter in complex_graph_rewrite.py.
The new complex_decomposition_adapter pass:
Wiring:
Tests:
Default off; legacy path unchanged. Boundary normalization assumptions (exact upstream op set, dynamic-shape survival through make_fx) still to be confirmed by a spike; see TODO(spike) in the adapter.
#4390