Skip to content

Move positional alpha to kwargs in ReplaceScalarWithTensorArgPass (#24176) - #24176

Merged
meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
aliafzal:export-D127746753
Oct 29, 2026
Merged

meta-codesync[bot] merged 1 commit into
pytorch:mainfrom
aliafzal:export-D127746753

Conversation

@aliafzal

@aliafzal aliafzal commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

add.Scalar(Tensor self, Scalar other, Scalar alpha=1) takes alpha positionally, but add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1) takes it as keyword-only, and the same holds for sub. When alpha was the third positional argument, get_replacement passed it through *args[2:], and building the .Tensor node raised RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given. The 3-argument path now binds the call by name with torch.fx.operator_schemas.normalize_function (the part of get_arg that doesn't need a Node; call_operator gets no node), passes self (input after normalization) and other positionally, and alpha as a kwarg. get_replacement always gets 2 args and no longer forwards extra ones. The Arm ReplaceScalarWithTensorByProfilePass subclass routes through the same base call_operator, so it gets the fix too for edge add/sub.Scalar. torch.ops.aten.add/sub.Scalar with a positional alpha still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Authored with Claude Code.

Reviewed By: DrJessop

Differential Revision: D127746753

@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/24176

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 9e147d7 with merge base bf9bef3 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 27, 2026
@meta-codesync

meta-codesync Bot commented Oct 27, 2026

Copy link
Copy Markdown
Contributor

@aliafzal has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127746753.

@github-actions

Copy link
Copy Markdown

This PR needs a release notes: label

If your change should be included in the release notes (i.e. would users of this library care about this change?), please use a label starting with release notes:. This helps us keep track and include your important work in the next release notes.

To add a label, you can comment to pytorchbot, for example
@pytorchbot label "release notes: none"

For more information, see
https://github.com/pytorch/pytorch/wiki/PyTorch-AutoLabel-Bot#why-categorize-for-release-notes-and-how-does-it-work.

aliafzal added a commit to aliafzal/executorch that referenced this pull request Oct 28, 2026
…torch#24176)

Summary:

`add.Scalar(Tensor self, Scalar other, Scalar alpha=1)` takes `alpha` positionally, but `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)` takes it as keyword-only, and the same holds for `sub`. When `alpha` was the third positional argument, `get_replacement` passed it through `*args[2:]`, and building the `.Tensor` node raised `RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given`. The 3-argument path now passes `args[:2]` and moves `alpha` into `kwargs`, so `get_replacement` always gets 2 args and no longer forwards extra ones. The Arm `ReplaceScalarWithTensorByProfilePass` subclass routes through the same base `call_operator`, so it gets the fix too for edge `add/sub.Scalar`. `torch.ops.aten.add/sub.Scalar` with a positional `alpha` still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Found by the Jarvis nightly operator tests: `test_aten_add_scalar_out` fails 13 of 24 FACTO cases (every case with an explicit `alpha`) on nxp, DLA and Artemis v3/v4.

]

Reviewed By: DrJessop

Differential Revision: D127746753
aliafzal added a commit to aliafzal/executorch that referenced this pull request Oct 28, 2026
…torch#24176)

Summary:

`add.Scalar(Tensor self, Scalar other, Scalar alpha=1)` takes `alpha` positionally, but `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)` takes it as keyword-only, and the same holds for `sub`. When `alpha` was the third positional argument, `get_replacement` passed it through `*args[2:]`, and building the `.Tensor` node raised `RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given`. The 3-argument path now passes `args[:2]` and moves `alpha` into `kwargs`, so `get_replacement` always gets 2 args and no longer forwards extra ones. The Arm `ReplaceScalarWithTensorByProfilePass` subclass routes through the same base `call_operator`, so it gets the fix too for edge `add/sub.Scalar`. `torch.ops.aten.add/sub.Scalar` with a positional `alpha` still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Found by the Jarvis nightly operator tests: `test_aten_add_scalar_out` fails 13 of 24 FACTO cases (every case with an explicit `alpha`) on nxp, DLA and Artemis v3/v4.

]

Reviewed By: DrJessop

Differential Revision: D127746753
aliafzal added a commit to aliafzal/executorch that referenced this pull request Oct 28, 2026
…torch#24176)

Summary:

`add.Scalar(Tensor self, Scalar other, Scalar alpha=1)` takes `alpha` positionally, but `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)` takes it as keyword-only, and the same holds for `sub`. When `alpha` was the third positional argument, `get_replacement` passed it through `*args[2:]`, and building the `.Tensor` node raised `RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given`. The 3-argument path now passes `args[:2]` and moves `alpha` into `kwargs`, so `get_replacement` always gets 2 args and no longer forwards extra ones. The Arm `ReplaceScalarWithTensorByProfilePass` subclass routes through the same base `call_operator`, so it gets the fix too for edge `add/sub.Scalar`. `torch.ops.aten.add/sub.Scalar` with a positional `alpha` still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Found by the Jarvis nightly operator tests: `test_aten_add_scalar_out` fails 13 of 24 FACTO cases (every case with an explicit `alpha`) on nxp, DLA and Artemis v3/v4.

]

Reviewed By: DrJessop

Differential Revision: D127746753
aliafzal added a commit to aliafzal/executorch that referenced this pull request Oct 28, 2026
…torch#24176)

Summary:

`add.Scalar(Tensor self, Scalar other, Scalar alpha=1)` takes `alpha` positionally, but `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)` takes it as keyword-only, and the same holds for `sub`. When `alpha` was the third positional argument, `get_replacement` passed it through `*args[2:]`, and building the `.Tensor` node raised `RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given`. The 3-argument path now binds the call by name with `torch.fx.operator_schemas.normalize_function` (the part of `get_arg` that doesn't need a `Node`; `call_operator` gets no node), passes `self` (`input` after normalization) and `other` positionally, and `alpha` as a kwarg. `get_replacement` always gets 2 args and no longer forwards extra ones. The Arm `ReplaceScalarWithTensorByProfilePass` subclass routes through the same base `call_operator`, so it gets the fix too for edge `add/sub.Scalar`. `torch.ops.aten.add/sub.Scalar` with a positional `alpha` still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Authored with Claude Code.

Reviewed By: DrJessop

Differential Revision: D127746753
aliafzal added a commit to aliafzal/executorch that referenced this pull request Oct 28, 2026
…torch#24176)

Summary:

`add.Scalar(Tensor self, Scalar other, Scalar alpha=1)` takes `alpha` positionally, but `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)` takes it as keyword-only, and the same holds for `sub`. When `alpha` was the third positional argument, `get_replacement` passed it through `*args[2:]`, and building the `.Tensor` node raised `RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given`. The 3-argument path now binds the call by name with `torch.fx.operator_schemas.normalize_function` (the part of `get_arg` that doesn't need a `Node`; `call_operator` gets no node), passes `self` (`input` after normalization) and `other` positionally, and `alpha` as a kwarg. `get_replacement` always gets 2 args and no longer forwards extra ones. The Arm `ReplaceScalarWithTensorByProfilePass` subclass routes through the same base `call_operator`, so it gets the fix too for edge `add/sub.Scalar`. `torch.ops.aten.add/sub.Scalar` with a positional `alpha` still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Authored with Claude Code.

Reviewed By: DrJessop

Differential Revision: D127746753
…torch#24176)

Summary:

`add.Scalar(Tensor self, Scalar other, Scalar alpha=1)` takes `alpha` positionally, but `add.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)` takes it as keyword-only, and the same holds for `sub`. When `alpha` was the third positional argument, `get_replacement` passed it through `*args[2:]`, and building the `.Tensor` node raised `RuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given`. The 3-argument path now binds the call by name with `torch.fx.operator_schemas.normalize_function` (the part of `get_arg` that doesn't need a `Node`; `call_operator` gets no node), passes `self` (`input` after normalization) and `other` positionally, and `alpha` as a kwarg. `get_replacement` always gets 2 args and no longer forwards extra ones. The Arm `ReplaceScalarWithTensorByProfilePass` subclass routes through the same base `call_operator`, so it gets the fix too for edge `add/sub.Scalar`. `torch.ops.aten.add/sub.Scalar` with a positional `alpha` still pass through unreplaced, as before. The changed path previously always raised, so no graph that worked before is affected.

Authored with Claude Code.

Reviewed By: DrJessop

Differential Revision: D127746753
@meta-codesync meta-codesync Bot changed the title Move positional alpha to kwargs in ReplaceScalarWithTensorArgPass Move positional alpha to kwargs in ReplaceScalarWithTensorArgPass (#24176) Oct 28, 2026
@meta-codesync
meta-codesync Bot merged commit a02062d into pytorch:main Oct 29, 2026
233 checks passed

This branch was previously deployed

1 inactive deployment
cadence — 9e147d7c Deployed Oct 28, 2026 by aliafzal via hifi-op-test / hifi4 #35137
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants