Skip to content

[SymmMem] Fix memory allocation hold-up#162680

Closed
kwen2501 wants to merge 7 commits intogh/kwen2501/239/basefrom
gh/kwen2501/239/head
Closed

[SymmMem] Fix memory allocation hold-up#162680
kwen2501 wants to merge 7 commits intogh/kwen2501/239/basefrom
gh/kwen2501/239/head

Conversation

@kwen2501
Copy link
Collaborator

@kwen2501 kwen2501 commented Sep 11, 2025

Stack from ghstack (oldest at bottom):

Problem:
Without MemPool it looks like nvshmem backend never deallocates memory.

Cause:
Handles in symm_mems_ (a map) keeps reference to memory allocations.

Solution:

  • Remove reference to allocation from handles -- the reference is never used anyway.
  • Use unique_ptr instead of shared_ptr to wrap allocation to ensure single ownership.

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k @pragupta @ezyang @msaroufim @dcci

[ghstack-poisoned]
@pytorch-bot
Copy link

pytorch-bot bot commented Sep 11, 2025

🔗 Helpful Links

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

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

✅ No Failures

As of commit f1c4e75 with merge base 4840a1a (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot bot added ciflow/h100-symm-mem oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category labels Sep 11, 2025
@kwen2501 kwen2501 changed the title Remove reference [SymmMem] Fix memory allocation hold-up Sep 11, 2025
@ezyang
Copy link
Contributor

ezyang commented Sep 11, 2025

And perhaps, this is worth a test?

@ezyang
Copy link
Contributor

ezyang commented Sep 11, 2025

I see #162681 is (indirectly) testing it

[ghstack-poisoned]
public:
NVSHMEMPeerAllocInfo(
std::shared_ptr<NVSHMEMAllocation> allocation,
NVSHMEMAllocation* allocation,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why use bare pointers here? We should use unique_ptr here and just use std::move with the member intiializers

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will let you battle with @ezyang lol, see discussion above.
tldr:

  • there is no ownership move here.
  • Passing a bare pointer just for reading some values in the object.

Copy link
Contributor

Choose a reason for hiding this comment

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

no ownership move means don't std::move

Copy link
Contributor

@ezyang ezyang left a comment

Choose a reason for hiding this comment

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

suuure

[ghstack-poisoned]
@kwen2501 kwen2501 added the topic: bug fixes topic category label Sep 18, 2025
@kwen2501
Copy link
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot bot added the ciflow/trunk Trigger trunk jobs on your pull request label Sep 18, 2025
@pytorchmergebot
Copy link
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
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: Limited CI for symmetric memory tests on H100 / linux-jammy-cuda12.8-py3.10-gcc11-sm90-symm / test (h100-symm-mem, 1, 1, linux.aws.h100.4)

Details for Dev Infra team Raised by workflow job

[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
[ghstack-poisoned]
@kwen2501
Copy link
Collaborator Author

@pytorchbot merge

@pytorchmergebot
Copy link
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

@kwen2501
Copy link
Collaborator Author

@pytorchbot cherry-pick --onto release/2.9 -c critical

pytorchbot pushed a commit that referenced this pull request Sep 19, 2025
Problem:
Without MemPool it looks like nvshmem backend never deallocates memory.

Cause:
Handles in `symm_mems_` (a map) keeps reference to memory allocations.

Solution:
- Remove reference to allocation from handles -- the reference is never used anyway.
- Use `unique_ptr` instead of `shared_ptr` to wrap allocation to ensure single ownership.

Pull Request resolved: #162680
Approved by: https://github.com/ezyang
ghstack dependencies: #163298

(cherry picked from commit 7130b17)
@pytorchbot
Copy link
Collaborator

Cherry picking #162680

The cherry pick PR is at #163375 and it is recommended to link a critical cherry pick PR with an issue. The following tracker issues are updated:

Details for Dev Infra team Raised by workflow job

mansiag05 pushed a commit to mansiag05/pytorch that referenced this pull request Sep 22, 2025
Problem:
Without MemPool it looks like nvshmem backend never deallocates memory.

Cause:
Handles in `symm_mems_` (a map) keeps reference to memory allocations.

Solution:
- Remove reference to allocation from handles -- the reference is never used anyway.
- Use `unique_ptr` instead of `shared_ptr` to wrap allocation to ensure single ownership.

Pull Request resolved: pytorch#162680
Approved by: https://github.com/ezyang
ghstack dependencies: pytorch#163298
cleonard530 pushed a commit to cleonard530/pytorch that referenced this pull request Sep 22, 2025
Problem:
Without MemPool it looks like nvshmem backend never deallocates memory.

Cause:
Handles in `symm_mems_` (a map) keeps reference to memory allocations.

Solution:
- Remove reference to allocation from handles -- the reference is never used anyway.
- Use `unique_ptr` instead of `shared_ptr` to wrap allocation to ensure single ownership.

Pull Request resolved: pytorch#162680
Approved by: https://github.com/ezyang
ghstack dependencies: pytorch#163298
dsashidh pushed a commit to dsashidh/pytorch that referenced this pull request Sep 26, 2025
Problem:
Without MemPool it looks like nvshmem backend never deallocates memory.

Cause:
Handles in `symm_mems_` (a map) keeps reference to memory allocations.

Solution:
- Remove reference to allocation from handles -- the reference is never used anyway.
- Use `unique_ptr` instead of `shared_ptr` to wrap allocation to ensure single ownership.

Pull Request resolved: pytorch#162680
Approved by: https://github.com/ezyang
ghstack dependencies: pytorch#163298
Camyll pushed a commit that referenced this pull request Sep 26, 2025
[SymmMem] Fix memory allocation hold-up (#162680)

Problem:
Without MemPool it looks like nvshmem backend never deallocates memory.

Cause:
Handles in `symm_mems_` (a map) keeps reference to memory allocations.

Solution:
- Remove reference to allocation from handles -- the reference is never used anyway.
- Use `unique_ptr` instead of `shared_ptr` to wrap allocation to ensure single ownership.

Pull Request resolved: #162680
Approved by: https://github.com/ezyang
ghstack dependencies: #163298

(cherry picked from commit 7130b17)

Co-authored-by: Ke Wen <kw2501@meta.com>
@github-actions github-actions bot deleted the gh/kwen2501/239/head branch October 20, 2025 02:18
Khanaksahu pushed a commit to Khanaksahu/pytorch-fork that referenced this pull request Nov 17, 2025
Unique ptr

ghstack-source-id: 8dac2af
Pull-Request-resolved: pytorch/pytorch#162680

Barrier before and after access
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/h100-symm-mem ciflow/trunk Trigger trunk jobs on your pull request Merged oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category topic: bug fixes topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants