Repository navigation
Keep single-rank barrier() free of torch's device_id warning - #8779
usmanmateen wants to merge 2 commits into
Conversation
Since deepspeedai#8269, a single-rank job initializes the process group without a bound device, to avoid the eager communicator creation in new_group() behind deepspeedai#8248. torch then warns at every barrier() that it uses the device under the current context. A single rank has no peer that could pick a different device, so the warning is only noise there, and it fails test suites that run with warnings as errors (deepspeedai#8775). Ignore exactly that message when DeepSpeed created the process group without a device and the world has a single rank. Multi-rank jobs are unchanged: on CUDA they still bind a device, and elsewhere the warning stays visible. Fixes deepspeedai#8775 Signed-off-by: usmanmateen <usmanmateen255@gmail.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d0f7becae3
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
🟡 Changes recommended
The process-wide filter currently suppresses any warning sharing the message prefix rather than only the exact PyTorch warning.
1 open finding
What changed in this PR
Suppresses PyTorch’s single-rank barrier device warning without binding a device and reintroducing #8248.
Changes:
- Adds targeted warning filtering after single-rank initialization.
- Adds mocked and NCCL integration coverage.
| File | Description |
|---|---|
deepspeed/comm/torch.py |
Filters the barrier warning for unbound single-rank groups. |
tests/unit/comm/test_dist.py |
Tests single- and multi-rank warning behavior. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
warnings.filterwarnings matches a message from its start, so the filter also hid any other warning that begins with the same text. Match the whole message torch (2.9+) emits instead, and check in the test that a longer message with the same start stays visible. Signed-off-by: usmanmateen <74776275+usmanmateen@users.noreply.github.com>
|
Hi @tohtana, gentle ping on this when you have a moment. Happy to adjust anything. |
|
@delock, could you take a look at this when you have a moment? Happy to adjust anything. |

Fixes #8775.
Problem
Since #8269 (0.19.7), a single-rank job initializes the process group without a bound device so that
new_group()stays lazy (#8248). torch'sbarrier()then has neitherdevice_idsnorgroup.bound_device_id, and warns on every call:This hits any single-GPU job: Lightning as reported, and also DeepSpeed's own
dist.barrier()calls (a single-GPU ZeRO-3deepspeed.initializeplus one step prints it 3 times). Suites that run with warnings as errors fail on it.Binding a device in any form brings #8248 back:
new_group()inheritsdefault_pg.bound_device_idand callseager_connect_single_device. Settingbound_device_idafter init does the same.Change
When DeepSpeed creates the process group without a device and the world has a single rank, ignore exactly that torch message. With one rank there is no peer that could pick a different device, which is the hang the warning is about. Multi-rank jobs are unchanged: on CUDA the device is still bound, and on other accelerators the warning stays visible. The condition uses
torch.distributed.get_world_size()after init, so a wrongWORLD_SIZEcannot hide the warning in a multi-rank job.Verification
WSL2 Ubuntu, RTX 5060 Ti (sm_120), driver 596.49, torch 2.14.1+cu130, NCCL 2.30.7. Single rank,
-W error::UserWarning,barrier()then 64new_group([0])(8 of them used for anall_reduce):barrier()new_group([0])Cuda failure 600 'device not ready'ineager_connect_single_device(#8248)On this machine #8248 looks like a cap on live NCCL communicators per process. Without a bound device, actually using 40 single-rank groups fails the same way. Binding makes every
new_group()count toward that cap, so keeping it unbound for a single rank is still right.Tests
test_barrier_device_warning: withtorch.distributedstand-ins, the message is hidden after a single-rank init and stays visible for two ranks.TestSingleRankDeviceId::test_barrier_does_not_warn: real single-rank NCCL init andbarrier()with that warning set to error. It fails on master and passes with this change.pytest tests/unit/comm/test_dist.pyon 1× RTX 5060 Ti: 19 passed, 26 skipped (multi-GPU / MPS).pre-commit run --fileson both files passes.Trade-offs
barrier()calls made outside DeepSpeed in the same process. That is the point for the Lightning case, but it means a user who wants to see this message after a single-rank DeepSpeed init has to add their own filter afterinit_distributed.ProcessGroupNCCL.cpp: Guessing device ID based on global rank...from C++ before the first collective. It is not a Python warning, so it does not fail warnings-as-errors runs, and this change does not touch it.