Skip to content

[Fix][Relax] Preserve Torch integral power semantics - #20135

Open
akaashrp wants to merge 3 commits into
apache:mainfrom
akaashrp:upstream/torch-integral-powers
Open

[Fix][Relax] Preserve Torch integral power semantics#20135
akaashrp wants to merge 3 commits into
apache:mainfrom
akaashrp:upstream/torch-integral-powers

Conversation

@akaashrp

@akaashrp akaashrp commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Preserve PyTorch dtype and negative-base behavior when importing tensor powers with nonnegative integral scalar exponents.

This PR:

  • Applies PyTorch’s scalar exponent conversion before lowering
  • Preserves dtype promotion for integer tensors raised to floating-point scalars
  • Lowers nonnegative integral exponents to multiplication using exponentiation by squaring only for integer tensor bases
  • Leaves fractional exponents on the general power path

@yongwww yongwww closed this Aug 17, 2026
@yongwww yongwww reopened this Aug 17, 2026
@akaashrp
akaashrp force-pushed the upstream/torch-integral-powers branch 2 times, most recently from a4717db to efe0d22 Compare August 22, 2026 06:17
@akaashrp
akaashrp requested a review from tlopex August 25, 2026 02:41
Comment thread python/tvm/relax/frontend/torch/base_fx_graph_translator.py Outdated
@akaashrp
akaashrp force-pushed the upstream/torch-integral-powers branch from efe0d22 to 7743462 Compare August 27, 2026 18:45
@tlopex

tlopex commented Aug 30, 2026

Copy link
Copy Markdown
Member

For a float32 base, rhs is converted to float64 above but then rounded back to float32 by relax.const(rhs, power_dtype). e.g. 2**24 + 1 becomes 2**24, which can change the magnitude for nontrivial inputs. Could we evaluate float32 power in float64 and cast back, and add a regression test that does not only use -1?

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.

3 participants