Skip to content

[Torch] Add aten.xlogy.Tensor decomposition - #4659

Merged
sahas3 merged 1 commit into
llvm:mainfrom
josephbak:josephbak/decompose-xlogy
Aug 11, 2026
Merged

[Torch] Add aten.xlogy.Tensor decomposition#4659
sahas3 merged 1 commit into
llvm:mainfrom
josephbak:josephbak/decompose-xlogy

Conversation

@josephbak

Copy link
Copy Markdown
Contributor

aten.xlogy.Tensor had no lowering on any backend. It also blocked the torchdynamo config of the KlDivLoss e2e tests, since PyTorch's kl_div decomposition emits xlogy (see #4204, which added kl_div and recorded the gap).

This decomposes xlogy into log, mul, eq.Scalar, isnan and where, so all backend configs are handled at once. Shape and dtype functions are added as well; integer inputs promote to float32 since log forces a float.

This builds on the abandoned #2486 with its review feedback applied. I also fixed the type derivation, which was wrong under broadcasting: eq.Scalar, log and isnan are shape-preserving, so their result types have to come from their operands, not the broadcast result. This is the same issue that #4509 fixed for logaddexp. A [3,1] x [1,5] e2e test covers it.

The broadcast test uses static shapes because TorchToLinalg's elementwise lowering only emits broadcast maps when size-1 dims are statically known; with dynamic sizes it emits equality assertions instead. This is pre-existing and general (add.Tensor / mul.Tensor behave the same way).

Testing

  • Lit test for the decomposition.
  • e2e tests pass on linalg, fx_importer, fx_importer_stablehlo, and fx_importer_tosa (built StableHLO locally to verify that config).
  • Xfailed on the onnx config: PyTorch's ONNX exporter doesn't support aten::xlogy (UnsupportedOperatorError).
  • The 5 KlDivLoss tests are removed from TORCHDYNAMO_CRASHING_SET; they were skipped entirely before and now run and pass under --config=torchdynamo.

@josephbak

Copy link
Copy Markdown
Contributor Author

Hi @zjgarvey — could you (or another maintainer) approve the CI workflows here? This picks up the abandoned #2486 and unblocks the KlDivLoss torchdynamo tests recorded in TORCHDYNAMO_CRASHING_SET by #4204, which you reviewed and merged. Happy to take a review from whoever has time.

@josephbak
josephbak force-pushed the josephbak/decompose-xlogy branch from 0fc20a2 to 84503cc Compare July 21, 2026 02:44
@josephbak

Copy link
Copy Markdown
Contributor Author

Friendly ping — this has been green for several days (checks passing, no conflicts). @zjgarvey @sahas3 — would either of you have a moment to review, or point me to whoever's handling torch decompositions these days? This builds on #4204 and unblocks its KlDivLoss torchdynamo tests.

Happy to address changes. Thanks!

Comment thread lib/Dialect/Torch/Transforms/DecomposeComplexOps.cpp Outdated
aten.xlogy.Tensor had no lowering in torch-mlir. Rather than add a C++
decomposition, register aten.xlogy in DEFAULT_DECOMPOSITIONS so the fx
importer applies PyTorch's existing decomposition, which lowers to
log/mul/eq/isnan/where. This avoids reimplementing and maintaining the
same logic in torch-mlir.

Adds e2e tests (basic, int-to-float promotion, zero/NaN conventions, and
a broadcast case), passing on fx_importer, fx_importer_stablehlo, and
fx_importer_tosa. The broadcast and zero/NaN tests are xfailed on onnx,
where the lowering produces incorrect results for inputs whose result
contains NaN.

Assisted-by: Claude (Anthropic)
@josephbak
josephbak force-pushed the josephbak/decompose-xlogy branch from 84503cc to bf20deb Compare August 6, 2026 15:47
@josephbak

Copy link
Copy Markdown
Contributor Author

@sahas3 the nightly run failed at "Setup workspace and python" with a transient "Service Unavailable" fetching an action, before any build or test ran (stable was auto-cancelled). Looks like CI infra, not the change. Could you re-run when you get a chance? Thanks!

@sahas3 sahas3 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM.

@sahas3
sahas3 merged commit df3b957 into llvm:main Aug 11, 2026
3 of 5 checks passed
@josephbak

Copy link
Copy Markdown
Contributor Author

Thanks for the review and guidance on the approach, @sahas3!

@josephbak
josephbak deleted the josephbak/decompose-xlogy branch August 11, 2026 15:45
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