Skip to content

add converter for aten.linalg_cross (torch.cross / torc… - #4485

Open
apbose wants to merge 1 commit into
mainfrom
abose/linalg_cross_converter
Open

add converter for aten.linalg_cross (torch.cross / torc…#4485
apbose wants to merge 1 commit into
mainfrom
abose/linalg_cross_converter

Conversation

@apbose

@apbose apbose commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Addresses #3724

@meta-cla meta-cla Bot added the cla signed label Aug 13, 2026
@github-actions github-actions Bot added component: tests Issues re: Tests component: conversion Issues re: Conversion stage component: core Issues re: The core compiler component: converters Issues re: Specific op converters component: api [Python] Issues re: Python API component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths labels Aug 13, 2026
@github-actions
github-actions Bot requested a review from narendasan August 13, 2026 20:17

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are some changes that do not conform to Python style guidelines:

--- /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/linalg.py	2026-08-13 20:17:38.528572+00:00
+++ /home/runner/work/TensorRT/TensorRT/py/torch_tensorrt/dynamo/conversion/impl/linalg.py	2026-08-13 20:17:59.647057+00:00
@@ -29,18 +29,14 @@

    a0, a1, a2 = (component(input, i, "a") for i in range(3))
    b0, b1, b2 = (component(other, i, "b") for i in range(3))

    def mul(lhs: TRTTensor, rhs: TRTTensor, label: str) -> TRTTensor:
-        return impl.elementwise.mul(
-            ctx, target, source_ir, f"{name}_{label}", lhs, rhs
-        )
+        return impl.elementwise.mul(ctx, target, source_ir, f"{name}_{label}", lhs, rhs)

    def sub(lhs: TRTTensor, rhs: TRTTensor, label: str) -> TRTTensor:
-        return impl.elementwise.sub(
-            ctx, target, source_ir, f"{name}_{label}", lhs, rhs
-        )
+        return impl.elementwise.sub(ctx, target, source_ir, f"{name}_{label}", lhs, rhs)

    r0 = sub(mul(a1, b2, "a1b2"), mul(a2, b1, "a2b1"), "r0")
    r1 = sub(mul(a2, b0, "a2b0"), mul(a0, b2, "a0b2"), "r1")
    r2 = sub(mul(a0, b1, "a0b1"), mul(a1, b0, "a1b0"), "r2")

…h.linalg.cross)

torch.cross resolves its optional dim and delegates to aten.linalg_cross
under decomposition, so a single converter for aten.linalg_cross.default
covers both public APIs. Neither had a converter, so models using either
op fell back to PyTorch or errored depending on partitioning settings.

impl.linalg.cross splits each operand into its 3 components along dim via
ISelect (gather), computes the cross product with elementwise mul/sub, and
concatenates the 3 result components back along dim. A capability_validator
rejects the case where dim's size isn't statically known to be 3, since the
converter relies on that precondition.

Fixes #3724
@apbose
apbose force-pushed the abose/linalg_cross_converter branch from 635f7f3 to 0b3770e Compare August 13, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla signed component: api [Python] Issues re: Python API component: conversion Issues re: Conversion stage component: converters Issues re: Specific op converters component: core Issues re: The core compiler component: dynamo Issues relating to the `torch.compile` or `torch._dynamo.export` paths component: tests Issues re: Tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant