Skip to content

[Relax][ONNX] Support integer inputs in Pow operator - #21073

Draft
cchung100m wants to merge 4 commits into
apache:mainfrom
cchung100m:issue-21044
Draft

cchung100m wants to merge 4 commits into
apache:mainfrom
cchung100m:issue-21044

Conversation

@cchung100m

Copy link
Copy Markdown
Contributor

Hi Committers,

This PR fixes issue #21044. Any suggestions would be greatly appreciated.

Root Cause

The ONNX Pow converter lowered every non-constant case to relax.op.power, which legalizes to topi.power.That function only accepts floating-point operands, so integer Pow failed with "power only applies to float". Mixed-dtype inputs, such as an integer base with a float exponent, were not handled either.

Solution

For an integer base, a non-negative integer constant exponent is expanded into exact square-and-multiply multiplications. Other cases go through float64 and are cast back to the base dtype, which matches ONNX Runtime's truncation. For a float base, the exponent is cast to the base dtype, and all-constant inputs are folded with numpy. Tests cover integer, mixed-dtype, and constant-folding cases against ONNX Runtime.

This branch has not been deployed

No deployments
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