KEMBAR78
[c10d] Fix extra CUDA context created by barrier by kwen2501 · Pull Request #152834 · pytorch/pytorch · GitHub
Skip to content

Conversation

@kwen2501
Copy link
Contributor

@kwen2501 kwen2501 commented May 5, 2025

Fixes #149119.

In ProcessGroup.hpp, we create a dummy tensor for dispatching. This requires a correct device index. This PR uses device_id given by user when calling init_process_group.

This PR also uses torch._C._get_accelerator() to determine the device type.

ghstack-source-id: 96c32b9565794d995c26bd1794856d1ef7961652
Pull Request resolved: #149144

cc @H-Huang @awgu @wanchaol @fegin @fduwjj @wz337 @wconstab @d4l3k

Fixes #149119.

In ProcessGroup.hpp, we create a dummy tensor for dispatching. This
requires a correct device index. This PR uses `device_id` given by user
when calling `init_process_group`.

This PR also uses `torch._C._get_accelerator()` to determine the device
type.

ghstack-source-id: 96c32b9
Pull Request resolved: #149144
@pytorch-bot
Copy link

pytorch-bot bot commented May 5, 2025

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

❌ 1 New Failure, 4 Cancelled Jobs, 1 Unrelated Failure

As of commit 99138ee with merge base 924a247 (image):

NEW FAILURE - The following job has failed:

CANCELLED JOBS - The following jobs were cancelled. Please retry:

FLAKY - The following job failed but was likely due to flakiness present on trunk:

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

@pytorch-bot pytorch-bot bot added oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category labels May 5, 2025
Copy link
Collaborator

@ngimel ngimel left a comment

Choose a reason for hiding this comment

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

Please add test that no extra contexts are created?

)
# Detect the accelerator on the machine. If no accelerator is available, it
# returns CPU.
device = torch._C._get_accelerator()
Copy link
Collaborator

Choose a reason for hiding this comment

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

_get_accelerator poisons the context on the current device, to just get the accelerator on the machine it's better to use _accelerator_getAccelerator.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Per @albanD torch.accelerator.current_accelerator() is also non-poisoning

# may use default device 0, causing issues like hang or all processes
# creating context on device 0.
opts.device = device
warnings.warn( # warn only once
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it actually warn only once by default?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@atalman atalman merged commit 1214198 into release/2.7 May 27, 2025
179 of 187 checks passed
@github-actions github-actions bot deleted the bcon_2.7 branch June 27, 2025 02:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

oncall: distributed Add this issue/PR to distributed oncall triage queue release notes: distributed (c10d) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants