Skip to content

[inductor] Fix buffer reuse corrupting re-inplaced mutating fallback kernels - #189735

Closed
jbschlosser wants to merge 4 commits into
gh/jbschlosser/282/basefrom
gh/jbschlosser/282/head
Closed

jbschlosser wants to merge 4 commits into
gh/jbschlosser/282/basefrom
gh/jbschlosser/282/head

Conversation

@jbschlosser

@jbschlosser jbschlosser commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

Original repro in P2415048693.

Found to affect the _philox_uniform / _philox_normal ops in practice, which currently utilize FallbackKernel and are re-inplaced as of #188495.

FallbackKernel previously did not record that the returned buffer aliases the input for re-inplaced ops. As a result, memory planning treated the input buffer as dead after the op and wrongly reused its storage while the aliasing output was still live, corrupting results.

This PR fixes this by recording the output <-> first-arg alias in FallbackKernel so memory planning keeps the buffer live.

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Jul 13, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit 6e873c8 with merge base 20aa640 (image):

BROKEN TRUNK - The following job failed but were 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.

Comment thread torch/_inductor/ir.py
self.mutation_names.append(tensor_args[0].get_name())
# Record aliasing relationship so memory planning doesn't wrongly
# reuse its storage.
self.alias_names.append(tensor_args[0].get_name())

@jbschlosser jbschlosser Jul 13, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as stated in the comments above, this is only triggered if a lowering or pass introduced it, and in practice that pass is reinplacing. so this only affects ops that have a fallback + are reinplaced, which I think today is only the philox ops (unless #189080 lands)

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]

@eellison eellison left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!

@jbschlosser

Copy link
Copy Markdown
Contributor Author

@claude are the CI failures related?

@claude

claude Bot commented Jul 15, 2026 •

Copy link
Copy Markdown

Claude finished @jbschlosser's task in 40s —— View job


CI failure analysis

No, the CI failure is not related to this PR.

The only failing job is:

  • pull / linux-jammy-py3.10-gcc11 / test (backwards_compat, 1, 1, ...) → failing test test_modules_can_be_imported

Two independent signals confirm it's a pre-existing broken-trunk failure:

  1. Dr. CI classified it as BROKEN TRUNK — the same job/test is failing on the merge base commit 20aa640b8048 (trunk failure). It's failing independently of your changes.

  2. The failing test has nothing to do with the change. test_modules_can_be_imported (backwards-compat, module import check) is unrelated to the two files this PR touches:

    • torch/_inductor/ir.py (+3) — records the output↔first-arg alias in FallbackKernel
    • test/test_stateless_rng.py (+18) — the regression test

    An Inductor memory-planning aliasing fix cannot affect whether Python modules import.

Recommendation: rebase onto viable/strict to pick up a green merge base and clear the failure, as Dr. CI suggests. All build jobs and the Inductor/dynamo test shards passed.

@jbschlosser

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jul 15, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: pull / linux-jammy-py3.10-gcc11 / test (backwards_compat, 1, 1, lf-l-x86iavx512-8-64)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: trunk / linux-jammy-rocm-py3.10-mi350 / test (distributed, 3, 3, linux.rocm.gpu.gfx950.2)

Details for Dev Infra team Raised by workflow job

@lucasb-eyer

Copy link
Copy Markdown
Contributor

@claude are the CI failures related?

@claude

claude Bot commented Jul 16, 2026 •

Copy link
Copy Markdown

Claude finished @lucasb-eyer's task in 43s —— View job


CI failure analysis

No — the CI failures are not related to this PR. There are two distinct failures in play here, both unrelated to the change:

1. pull workflow — test (backwards_compat, 1, 1, ...) → test_modules_can_be_imported

This is the only failing check on the PR, and Dr. CI classified it as BROKEN TRUNK: the same job/test is failing on the merge base commit 20aa640b8048, so it fails independently of your change. All builds and the Inductor/dynamo/default test shards passed.

test_modules_can_be_imported is a backwards-compat module-import check — it has nothing to do with the two files this PR touches (torch/_inductor/ir.py recording an Inductor memory-planning alias, and test/test_stateless_rng.py). An aliasing fix in Inductor memory planning cannot affect whether Python modules import.

2. Merge attempt — trunk / linux-jammy-rocm-py3.10-mi350 / test (distributed, 3, 3, ...)

The @pytorchbot merge -i on 2026-07-15 failed on a ROCm distributed test shard. This is also unrelated to the change:

  • Distributed collective tests on ROCm GPUs exercise none of the RNG-fallback / memory-planning code path this PR modifies.
  • ROCm distributed shards are a common source of flaky/infra failures in trunk.

Recommendation: Rebase onto viable/strict to pick up a green merge base (clears the backwards_compat broken-trunk failure), then re-run the merge. If the ROCm distributed job flakes again on the merge, it can be retried or ignored with -i, since it doesn't touch this PR's code path.

@jbschlosser

Copy link
Copy Markdown
Contributor Author

@pytorchbot merge -i

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 1 checks: pull / linux-jammy-py3.10-gcc11 / test (backwards_compat, 1, 1, lf-l-x86iavx512-8-64)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…kernels (pytorch#189735)

Original repro in P2415048693.

Found to affect the `_philox_uniform` / `_philox_normal` ops in practice, which currently utilize `FallbackKernel` and are re-inplaced as of pytorch#188495.

`FallbackKernel` previously did not record that the returned buffer aliases the input for re-inplaced ops. As a result, memory planning treated the input buffer as dead after the op and wrongly reused its storage while the aliasing output was still live, corrupting results.

This PR fixes this by recording the output <-> first-arg alias in `FallbackKernel` so memory planning keeps the buffer live.

Pull Request resolved: pytorch#189735
Approved by: https://github.com/eellison
ghstack dependencies: pytorch#189767
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…kernels (pytorch#189735)

Original repro in P2415048693.

Found to affect the `_philox_uniform` / `_philox_normal` ops in practice, which currently utilize `FallbackKernel` and are re-inplaced as of pytorch#188495.

`FallbackKernel` previously did not record that the returned buffer aliases the input for re-inplaced ops. As a result, memory planning treated the input buffer as dead after the op and wrongly reused its storage while the aliasing output was still live, corrupting results.

This PR fixes this by recording the output <-> first-arg alias in `FallbackKernel` so memory planning keeps the buffer live.

Pull Request resolved: pytorch#189735
Approved by: https://github.com/eellison
ghstack dependencies: pytorch#189767
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…kernels (pytorch#189735)

Original repro in P2415048693.

Found to affect the `_philox_uniform` / `_philox_normal` ops in practice, which currently utilize `FallbackKernel` and are re-inplaced as of pytorch#188495.

`FallbackKernel` previously did not record that the returned buffer aliases the input for re-inplaced ops. As a result, memory planning treated the input buffer as dead after the op and wrongly reused its storage while the aliasing output was still live, corrupting results.

This PR fixes this by recording the output <-> first-arg alias in `FallbackKernel` so memory planning keeps the buffer live.

Pull Request resolved: pytorch#189735
Approved by: https://github.com/eellison
ghstack dependencies: pytorch#189767
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…kernels (pytorch#189735)

Original repro in P2415048693.

Found to affect the `_philox_uniform` / `_philox_normal` ops in practice, which currently utilize `FallbackKernel` and are re-inplaced as of pytorch#188495.

`FallbackKernel` previously did not record that the returned buffer aliases the input for re-inplaced ops. As a result, memory planning treated the input buffer as dead after the op and wrongly reused its storage while the aliasing output was still live, corrupting results.

This PR fixes this by recording the output <-> first-arg alias in `FallbackKernel` so memory planning keeps the buffer live.

Pull Request resolved: pytorch#189735
Approved by: https://github.com/eellison
ghstack dependencies: pytorch#189767
@github-actions
github-actions Bot deleted the gh/jbschlosser/282/head branch August 16, 2026 02:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor release notes: inductor topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants