Repository navigation
Move positional alpha to kwargs in ReplaceScalarWithTensorArgPass (#24176) - #24176
Conversation
🔗 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 FailuresAs of commit 9e147d7 with merge base bf9bef3 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@aliafzal has exported this pull request. If you are a Meta employee, you can view the originating Diff in D127746753. |
This PR needs a
|
…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
…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
…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
fd4fbd3 to
1e43d66
Compare
1e43d66 to
b5303f7
Compare
…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
…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
b5303f7 to
9e147d7
Compare
Summary:
add.Scalar(Tensor self, Scalar other, Scalar alpha=1)takesalphapositionally, butadd.Tensor(Tensor self, Tensor other, *, Scalar alpha=1)takes it as keyword-only, and the same holds forsub. Whenalphawas the third positional argument,get_replacementpassed it through*args[2:], and building the.Tensornode raisedRuntimeError: aten::add() takes 2 positional argument(s) but 3 was/were given. The 3-argument path now binds the call by name withtorch.fx.operator_schemas.normalize_function(the part ofget_argthat doesn't need aNode;call_operatorgets no node), passesself(inputafter normalization) andotherpositionally, andalphaas a kwarg.get_replacementalways gets 2 args and no longer forwards extra ones. The ArmReplaceScalarWithTensorByProfilePasssubclass routes through the same basecall_operator, so it gets the fix too for edgeadd/sub.Scalar.torch.ops.aten.add/sub.Scalarwith a positionalalphastill 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