Repository navigation
[inductor] Generalize reinplacing to functional ATen ops with an in-place variant - #189080
jbschlosser wants to merge 2 commits into
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/189080
Note: Links to docs will display an error until the docs builds have been completed. ❌ 7 New FailuresAs of commit 3b817f5 with merge base caf9663 ( NEW FAILURES - The following jobs have failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
Benchmark script (P2398638090) shows a performance issue with the new stateless RNG APIs within torch.compile. Tracked this down to the auto-generated functional variants of the new ops performing an extra clone. To address this, this PR: * ~~Introduces explicit, non-autogenerated functional variants for the in-place ops that use `empty_like(self)` instead of `self.clone()` to indicate to functionalization that the data is completely overwritten and is not needed for correctness. This addresses the performance issue for the in-place ops, but still (briefly) results in a 2x allocation for an unused buffer alongside the output when the out-of-place APIs call the in-place ops.~~ * ~~Introduces new size-based overloads for the out-of-place APIs. Now they bypass the in-place ops entirely (preferring the size-based, out-of-place ops), avoiding the aforementioned 2x allocation.~~ * Adds `inplaceable_ops` registry entries for the philox uniform / normal ops. These will be unneeded once we land Inductor lowerings or a more general fix (e.g. #189080). Pull Request resolved: #188495 Approved by: https://github.com/ngimel, https://github.com/zou3519
|
@claude root-cause the CI failures |
|
Claude finished @jbschlosser's task in 10m 45s —— View job Root cause of the CI failuresSummary: The Full analysisThe failing testsAll ~37 new failures collapse to one family: Why
|
|
@claude root-cause the CI failures |
|
Claude finished @jbschlosser's task in 5m 21s —— View job Root-cause of the CI failuresSummary: All 7 reported failures are non-code issues. The 2 model-test failures are stale expected-accuracy CSVs on the PR branch (a trunk baseline bump for graph breaks never got merged in) — the "new graph breaks" the harness reports exactly match trunk's current expected counts, and the reinplace pass runs post-Dynamo so it cannot produce graph breaks. The other 5 are pure infra flakes (sccache, k8s pod, read-only HF cache). Full analysisNote: this is a different failure than my earlier
|
| Model | Suite | PR branch reports | PR branch CSV expects | Trunk main CSV expects |
|---|---|---|---|---|
mobilenetv2_100 |
timm training | 7 | 0 | 7 |
tf_efficientnet_b0 |
timm training | 6 | 0 | 6 |
mnasnet1_0 |
torchbench training | 7 | 0 | 7 |
mobilenet_v2 |
torchbench training | 6 | 0 | 6 |
shufflenet_v2_x1_0 |
torchbench training | 6 | 0 | 6 |
The observed counts match trunk's expected values exactly. Verified:
$ git show origin/main:benchmarks/dynamo/ci_expected_accuracy/inductor_timm_training.csv | grep -E "mobilenetv2_100|tf_efficientnet_b0"
mobilenetv2_100,pass,7
tf_efficientnet_b0,pass,6
$ git show origin/main:benchmarks/dynamo/ci_expected_accuracy/inductor_torchbench_training.csv | grep -E "mobilenet_v2,|mnasnet1_0|shufflenet_v2_x1_0"
mnasnet1_0,pass,7
mobilenet_v2,pass,6
shufflenet_v2_x1_0,pass,6
But this PR's base still has the old 0 baseline:
$ git show origin/gh/jbschlosser/279/base:.../inductor_torchbench_training.csv | grep -E "mobilenet_v2,|mnasnet1_0|shufflenet_v2_x1_0"
mnasnet1_0,pass,0
mobilenet_v2,pass,0
shufflenet_v2_x1_0,pass,0
So trunk bumped these graph-break baselines (for an unrelated reason — these are conv/batchnorm training models; the breaks are the standard training-mode breaks, not anything this PR introduces) after this stack was branched, and the stack never picked up that update.
Why this cannot be caused by the PR's code
The reinplacing pass (reinplace_inplaceable_ops_core) runs in Inductor's post-grad passes, after Dynamo has already traced and produced the FX graph. Dynamo graph breaks are decided during tracing, upstream of Inductor entirely. Nothing in reinplace.py, graph.py, or _ops.py in this PR can change the graph-break count. The log confirms the models compile fine (pass) — they only fail the check_graph_breaks.py count comparison against the stale CSV.
The other 5 failures are infra (matches HUD verdicts)
inductor ... test-osdc (inductor, 1, 2)— k8sCreateContainerError, no tests ran.inductor ... test-osdc (inductor, 2, 2)—sccache: error: couldn't connect to server.- both
torchtitanjobs —OSError: [Errno 30] Read-only file systemon/mnt/hf_cache/datasets/.
None touch the reinplace path.
Recommended fix
Rebase the stack onto current main (or cherry-pick the trunk CSV bump), so the branch's inductor_timm_training.csv and inductor_torchbench_training.csv carry the updated expected counts. Alternatively, run:
python benchmarks/dynamo/ci_expected_accuracy/update_expected.py 3b817f571638870003138a4ac141017fdba7bfff
and git add the updated CSVs — though a plain rebase is cleaner since the new baselines already exist on trunk.
- Fetch CI status & identify real (non-infra) failures
- Download logs for the graph-break failures
- Inspect PR changes to correlate with failures
- Determine root cause & report
· branchgh/jbschlosser/279/head
Benchmark script (P2398638090) shows a performance issue with the new stateless RNG APIs within torch.compile. Tracked this down to the auto-generated functional variants of the new ops performing an extra clone. To address this, this PR: * ~~Introduces explicit, non-autogenerated functional variants for the in-place ops that use `empty_like(self)` instead of `self.clone()` to indicate to functionalization that the data is completely overwritten and is not needed for correctness. This addresses the performance issue for the in-place ops, but still (briefly) results in a 2x allocation for an unused buffer alongside the output when the out-of-place APIs call the in-place ops.~~ * ~~Introduces new size-based overloads for the out-of-place APIs. Now they bypass the in-place ops entirely (preferring the size-based, out-of-place ops), avoiding the aforementioned 2x allocation.~~ * Adds `inplaceable_ops` registry entries for the philox uniform / normal ops. These will be unneeded once we land Inductor lowerings or a more general fix (e.g. pytorch#189080). Pull Request resolved: pytorch#188495 Approved by: https://github.com/ngimel, https://github.com/zou3519
Benchmark script (P2398638090) shows a performance issue with the new stateless RNG APIs within torch.compile. Tracked this down to the auto-generated functional variants of the new ops performing an extra clone. To address this, this PR: * ~~Introduces explicit, non-autogenerated functional variants for the in-place ops that use `empty_like(self)` instead of `self.clone()` to indicate to functionalization that the data is completely overwritten and is not needed for correctness. This addresses the performance issue for the in-place ops, but still (briefly) results in a 2x allocation for an unused buffer alongside the output when the out-of-place APIs call the in-place ops.~~ * ~~Introduces new size-based overloads for the out-of-place APIs. Now they bypass the in-place ops entirely (preferring the size-based, out-of-place ops), avoiding the aforementioned 2x allocation.~~ * Adds `inplaceable_ops` registry entries for the philox uniform / normal ops. These will be unneeded once we land Inductor lowerings or a more general fix (e.g. pytorch#189080). Pull Request resolved: pytorch#188495 Approved by: https://github.com/ngimel, https://github.com/zou3519
Benchmark script (P2398638090) shows a performance issue with the new stateless RNG APIs within torch.compile. Tracked this down to the auto-generated functional variants of the new ops performing an extra clone. To address this, this PR: * ~~Introduces explicit, non-autogenerated functional variants for the in-place ops that use `empty_like(self)` instead of `self.clone()` to indicate to functionalization that the data is completely overwritten and is not needed for correctness. This addresses the performance issue for the in-place ops, but still (briefly) results in a 2x allocation for an unused buffer alongside the output when the out-of-place APIs call the in-place ops.~~ * ~~Introduces new size-based overloads for the out-of-place APIs. Now they bypass the in-place ops entirely (preferring the size-based, out-of-place ops), avoiding the aforementioned 2x allocation.~~ * Adds `inplaceable_ops` registry entries for the philox uniform / normal ops. These will be unneeded once we land Inductor lowerings or a more general fix (e.g. pytorch#189080). Pull Request resolved: pytorch#188495 Approved by: https://github.com/ngimel, https://github.com/zou3519
|
Looks like this PR hasn't been updated in a while so we're going to go ahead and mark this as |
Stack from ghstack (oldest at bottom):
Broader fix for #188495
Under
torch.compile, functionalization rewrites in-place ops (e.g.uniform_) into functional ones that clone self before writing. For write-only ops, that clone is wasted and survives as an Inductor fallback, doubling peak memory. Inductor's reinplacing pass only undid this for a hand-maintainedinplaceable_opsregistry.This PR generalizes this to any functional op with a valid in-place variant when the buffer is dead:
OpOverload._inplace_variantusing a naming convention + schema validation to identify an in-place variantnode.metaso GraphLowering can passoverride_decompappropriately, avoiding an error for reintroduced in-place ops withmake_fallback's fallback-vs-decomp assertionCovers
_philox_uniform/_philox_normal,uniform/normal, and fallbacks likedigamma/gcd. Note thatbernoulli.Tensoris excluded because reinplacing to eager would break RNG determinism; a decomp should be added for this op variant instead (bernoulli.defaultalready has one). This is left to a future PR.Test Plan:
Alternative approach: signal to functionalization some other way that an op is write-only rather than read-modify-write, avoiding the need for reinplacing entirely.
Authored with assistance from Claude.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo