Skip to content

fix(relax/pytorch): honor alpha in add and sub - #20854

Open
tandede wants to merge 1 commit into
apache:mainfrom
tandede:fix/pytorch-alpha-20853
Open

tandede wants to merge 1 commit into
apache:mainfrom
tandede:fix/pytorch-alpha-20853

Conversation

@tandede

@tandede tandede commented Oct 30, 2026

Copy link
Copy Markdown
Contributor

Fixes #20853.

PyTorch defines add, sub, and rsub as applying alpha to the second operand before performing the binary operation. The exported program importer previously discarded this keyword argument, silently producing incorrect Relax IR whenever alpha != 1.

This change:

  • scales the appropriate operand before lowering add, sub, and rsub;
  • handles tensor and scalar operands;
  • adds support for sub_.Tensor, matching the existing add_.Tensor handling; and
  • adds structural regression coverage for functional and in-place forms.

Testing:

  • pytest tests/python/relax/test_frontend_from_exported_program.py -k "binary1 or binary_scalar or add_sub_alpha"
  • pre-commit run --files python/tvm/relax/frontend/torch/base_fx_graph_translator.py python/tvm/relax/frontend/torch/exported_program_translator.py tests/python/relax/test_frontend_from_exported_program.py

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.

[Bug][Relax][PyTorch] alpha of add / sub / rsub is silently ignored by from_exported_program

1 participant