Skip impure ops in constant_prop_pass - #22418
Conversation
constant_prop_pass folds any call_function node whose arguments are all constants. Ops that draw from the RNG, such as aten.rand, take only sizes as arguments, so they qualified and were replaced by a single frozen draw: a model returning x + torch.rand(4) produced the same output on every call once the pass had run. Skip nodes that torch.fx.Node.is_impure() reports as impure. That covers ops tagged nondeterministic_seeded, mutable schemas and side-effectful functions, and is the same test eliminate_dead_code uses to decide what it must keep.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/22418
Note: Links to docs will display an error until the docs builds have been completed. ❌ 3 New Failures, 2 Unrelated FailuresAs of commit 65ff880 with merge base 448fbfe ( NEW FAILURES - The following jobs have failed:
FLAKY - The following job failed but was likely due to flakiness present on trunk:
BROKEN TRUNK - The following job failed but was present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
This PR needs a
|
| or node.target is memory.alloc | ||
| or node.target in all_skip_targets | ||
| # Ops with side effects (RNG draws, mutation) have to run at | ||
| # runtime. `aten.rand` has no tensor inputs, so without this check |
There was a problem hiding this comment.
| # runtime. `aten.rand` has no tensor inputs, so without this check | |
| # runtime. |
| or node.target in all_skip_targets | ||
| # Ops with side effects (RNG draws, mutation) have to run at | ||
| # runtime. `aten.rand` has no tensor inputs, so without this check | ||
| # it would be folded into a single frozen draw. |
There was a problem hiding this comment.
| # it would be folded into a single frozen draw. |
JakeStevens
left a comment
There was a problem hiding this comment.
some nits on comment
Summary
constant_prop_passfolds everycall_functionnode whose arguments are all constants. Ops that draw from the RNG take only sizes as arguments, so they qualify: a model returningx + torch.rand(4)came out of the pass with the draw frozen into_prop_tensor_constant0, and returned the same value on every call.@JakeStevens spotted this while reviewing #22391 (repro there). The pass already runs in the Qualcomm and Samsung backends and in
quant_fusion_pass, so the fix stands on its own.Skip nodes that
torch.fx.Node.is_impure()reports as impure. That covers ops taggednondeterministic_seeded(rand,randn,bernoulli,dropout, ...), mutable schemas and side-effectful functions, and is the same checkeliminate_dead_codeuses to decide what it must keep.Test plan
New
test_constant_prop_pass_skips_nondeterministic_opsinexir/tests/test_passes.py: after the pass oneaten.randnode remains, no constant was added, and two calls give different outputs. It fails on main with0 != 1.python -m unittest executorch.exir.tests.test_passes -k constant_prop: 15 tests pass (torch 2.13.0, macOS arm64).