Skip to content

[inductor] dont reuse buffers if it affects peak (#145883)#159530

Closed
v0i0 wants to merge 15 commits intogh/v0i0/4/basefrom
gh/v0i0/4/head
Closed

[inductor] dont reuse buffers if it affects peak (#145883)#159530
v0i0 wants to merge 15 commits intogh/v0i0/4/basefrom
gh/v0i0/4/head

Conversation

@v0i0
Copy link
Copy Markdown
Contributor

@v0i0 v0i0 commented Jul 30, 2025

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot bot commented Jul 30, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit daa588c with merge base 6f0f4e0 (image):
💚 Looks good so far! There are no failures yet. 💚

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

v0i0 added a commit that referenced this pull request Jul 30, 2025
@v0i0
Copy link
Copy Markdown
Contributor Author

v0i0 commented Jul 30, 2025

@pytorchbot label "topic: not user facing"

@pytorch-bot pytorch-bot bot added the topic: not user facing topic category label Jul 30, 2025
@v0i0 v0i0 requested a review from eellison July 30, 2025 23:43
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Jul 31, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Jul 31, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 2, 2025
[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 5, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 7, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 7, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 7, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 7, 2025
@eellison eellison self-requested a review August 11, 2025 23:16
Copy link
Copy Markdown
Contributor

@eellison eellison left a comment

Choose a reason for hiding this comment

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

looks good, a couple questions about the tree. would you mind doing one dashboard run ? I believe we expect to see memory improvmenets in timm benchmark.

@v0i0
Copy link
Copy Markdown
Contributor Author

v0i0 commented Aug 12, 2025

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

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 12, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 15, 2025
v0i0 added a commit that referenced this pull request Aug 15, 2025
v0i0 added a commit that referenced this pull request Aug 15, 2025
cc voznesenskym penguinwu EikanWang jgong5 Guobing-Chen XiaobingSuper zhuhaozhe blzheng wenzhe-nrv jiayisunx ipiszy chenyang78 kadeng muchulee8 amjames chauhang aakhundov coconutruben

[ghstack-poisoned]
v0i0 added a commit that referenced this pull request Aug 15, 2025
@v0i0
Copy link
Copy Markdown
Contributor Author

v0i0 commented Aug 19, 2025

@pytorchbot merge

@pytorchmergebot
Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

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: HTTP Error 504: Gateway Timeout

Details for Dev Infra team Raised by workflow job

inp = torch.randn(100, 100, device=self.device)
self.assertFalse(CommonTemplate._is_triggering_buffer_reuse(fn, inp))

def test_allow_reuse_active_if_under_peak(self):
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Hi @v0i0 This test case causes failure of test/inductor/test_torchinductor_codegen_dynamic_shapes.py::DynamicShapesCodegenCpuTests::test_allow_reuse_active_if_under_peak_dynamic_shapes_cpu on CPU.
Wondering why CI didn't catch the failure. Can you please check and fix? Thanks.
CC @eellison

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.

this does not reproduce for me. could you file an issue with more details?
this is what main looks like for me:

^[[A(/data/users/mhoehnerbach/branches/check-dont-reuse/.venv) [mhoehnerbach@devvm7497.cco0 ~/local/branches/check-dont-reuse (check-dont-reuse)]$ python -m pytest -v -k reuse test/inductor/test_torchinductor_dynamic_shapes.py
============================================================================================================================= test session starts ==============================================================================================================================
platform linux -- Python 3.12.11, pytest-7.3.2, pluggy-1.6.0 -- /data/users/mhoehnerbach/branches/check-dont-reuse/.venv/bin/python
cachedir: .pytest_cache
hypothesis profile 'default' -> database=DirectoryBasedExampleDatabase('/data/users/mhoehnerbach/branches/check-dont-reuse/.hypothesis/examples')
rootdir: /data/users/mhoehnerbach/branches/check-dont-reuse
configfile: pytest.ini
plugins: xdoctest-1.1.0, hypothesis-5.35.1, xdist-3.3.1, subtests-0.13.1, rerunfailures-14.0, flakefinder-1.1.0, cpp-2.3.0
collected 1816 items / 1812 deselected / 4 selected
Running 4 items in this shard

test/inductor/test_torchinductor_dynamic_shapes.py::DynamicShapesCpuTests::test_aliased_buffer_reuse_dynamic_shapes_cpu PASSED [2.0221s]                                                                                                                                 [ 25%]
test/inductor/test_torchinductor_dynamic_shapes.py::DynamicShapesCpuTests::test_reuse_buffers_with_aliasing_dynamic_shapes_cpu PASSED [2.2129s]                                                                                                                          [ 50%]
test/inductor/test_torchinductor_dynamic_shapes.py::DynamicShapesGPUTests::test_aliased_buffer_reuse_dynamic_shapes_cuda PASSED [1.1616s]                                                                                                                                [ 75%]
test/inductor/test_torchinductor_dynamic_shapes.py::DynamicShapesGPUTests::test_reuse_buffers_with_aliasing_dynamic_shapes_cuda PASSED [3.4464s]                                                                                                                         [100%]

===================================================================================================================== 4 passed, 1812 deselected in 14.94s ======================================================================================================================

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks like another commit caused the failure. It's gone with latest main.

can-gaa-hou pushed a commit to can-gaa-hou/pytorch that referenced this pull request Aug 22, 2025
can-gaa-hou pushed a commit to can-gaa-hou/pytorch that referenced this pull request Aug 22, 2025
) (pytorch#159530)"

This reverts commit 3be70dc.

Reverted pytorch#159530 on behalf of https://github.com/clee2000 due to newly added test fail internally D80316528, probably just a targets change, but also imo the tests should probably go into a testcase class from common or inductor utils.  While I'm pretty sure CI can run the globally defined ones, theres some CI related functionality that on the testcase class that CI benefits from ([comment](pytorch#159530 (comment)))
@hl475
Copy link
Copy Markdown
Contributor

hl475 commented Aug 23, 2025

is there any way to turn this off @v0i0 ?

@v0i0
Copy link
Copy Markdown
Contributor Author

v0i0 commented Aug 25, 2025

is there any way to turn this off @v0i0 ?

hey @hl475! there is no config for it currently, but you can monkey patch it out, e.g. torch._inductor.codegen.wrapper. AllocateLine.should_reuse_buffer = lambda *_: True.

what sort of issues are you experiencing? the intention is for this to be a good optimization everywhere.

pytorchmergebot pushed a commit that referenced this pull request Sep 6, 2025
…62300)

As titled, this PR ensures peak memory is estimated only when buffer reuse is enabled. Without this config, some nodes' successor nodes are eliminated from memory estimation after inductor bucketing, which can cause errors.

The original codegen peak memory estimation code is from this PR: #159530

Pull Request resolved: #162300
Approved by: https://github.com/eellison, https://github.com/v0i0
daisyden pushed a commit to daisyden/pytorch that referenced this pull request Sep 8, 2025
…torch#162300)

As titled, this PR ensures peak memory is estimated only when buffer reuse is enabled. Without this config, some nodes' successor nodes are eliminated from memory estimation after inductor bucketing, which can cause errors.

The original codegen peak memory estimation code is from this PR: pytorch#159530

Pull Request resolved: pytorch#162300
Approved by: https://github.com/eellison, https://github.com/v0i0
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
) (pytorch#159530)"

This reverts commit 3be70dc.

Reverted pytorch#159530 on behalf of https://github.com/clee2000 due to newly added test fail internally D80316528, probably just a targets change, but also imo the tests should probably go into a testcase class from common or inductor utils.  While I'm pretty sure CI can run the globally defined ones, theres some CI related functionality that on the testcase class that CI benefits from ([comment](pytorch#159530 (comment)))
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
markc-614 pushed a commit to markc-614/pytorch that referenced this pull request Sep 17, 2025
…torch#162300)

As titled, this PR ensures peak memory is estimated only when buffer reuse is enabled. Without this config, some nodes' successor nodes are eliminated from memory estimation after inductor bucketing, which can cause errors.

The original codegen peak memory estimation code is from this PR: pytorch#159530

Pull Request resolved: pytorch#162300
Approved by: https://github.com/eellison, https://github.com/v0i0
mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
…torch#162300)

As titled, this PR ensures peak memory is estimated only when buffer reuse is enabled. Without this config, some nodes' successor nodes are eliminated from memory estimation after inductor bucketing, which can cause errors.

The original codegen peak memory estimation code is from this PR: pytorch#159530

Pull Request resolved: pytorch#162300
Approved by: https://github.com/eellison, https://github.com/v0i0
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
…torch#162300)

As titled, this PR ensures peak memory is estimated only when buffer reuse is enabled. Without this config, some nodes' successor nodes are eliminated from memory estimation after inductor bucketing, which can cause errors.

The original codegen peak memory estimation code is from this PR: pytorch#159530

Pull Request resolved: pytorch#162300
Approved by: https://github.com/eellison, https://github.com/v0i0
@github-actions github-actions bot deleted the gh/v0i0/4/head branch September 25, 2025 02:10
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
…torch#162300)

As titled, this PR ensures peak memory is estimated only when buffer reuse is enabled. Without this config, some nodes' successor nodes are eliminated from memory estimation after inductor bucketing, which can cause errors.

The original codegen peak memory estimation code is from this PR: pytorch#159530

Pull Request resolved: pytorch#162300
Approved by: https://github.com/eellison, https://github.com/v0i0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/inductor ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor Reverted topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants