Skip to content

Keep single-rank barrier() free of torch's device_id warning - #8779

Open
usmanmateen wants to merge 2 commits into
deepspeedai:masterfrom
usmanmateen:fix-single-rank-barrier-warning
Open

usmanmateen wants to merge 2 commits into
deepspeedai:masterfrom
usmanmateen:fix-single-rank-barrier-warning

Conversation

@usmanmateen

Copy link
Copy Markdown

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's barrier() then has neither device_ids nor group.bound_device_id, and warns on every call:

UserWarning: barrier(): using the device under current context. You can specify `device_id` in `init_process_group` to mute this warning.

This hits any single-GPU job: Lightning as reported, and also DeepSpeed's own dist.barrier() calls (a single-GPU ZeRO-3 deepspeed.initialize plus 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() inherits default_pg.bound_device_id and calls eager_connect_single_device. Setting bound_device_id after 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 wrong WORLD_SIZE cannot 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 64 new_group([0]) (8 of them used for an all_reduce):

barrier() 64 × new_group([0])
0.19.6 OK fails at the 40th: Cuda failure 600 'device not ready' in eager_connect_single_device (#8248)
master raises the UserWarning OK
this PR OK OK

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: with torch.distributed stand-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 and barrier() with that warning set to error. It fails on master and passes with this change.
  • pytest tests/unit/comm/test_dist.py on 1× RTX 5060 Ti: 19 passed, 26 skipped (multi-GPU / MPS).
  • pre-commit run --files on both files passes.

Trade-offs

  • Python warning filters are process-wide, so the filter also covers 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 after init_distributed.
  • torch still logs 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.
  • I only have one GPU, so the multi-rank CUDA path was checked by reading the code and with a 2-process gloo run (no filter added on either rank), not on multiple GPUs.

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T00:44:40.888220Z d0f7bec PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread deepspeed/comm/torch.py Resolved
Comment thread tests/unit/comm/test_dist.py Resolved

Copilot AI 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.

🟡 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.

Comment thread deepspeed/comm/torch.py Resolved
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>
@usmanmateen

Copy link
Copy Markdown
Author

Hi @tohtana, gentle ping on this when you have a moment. Happy to adjust anything.

@usmanmateen

Copy link
Copy Markdown
Author

@delock, could you take a look at this when you have a moment? Happy to adjust anything.

@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
@usmanmateen

Copy link
Copy Markdown
Author

@tjruwase @loadams could one of you take a look when you have time? The review comments are addressed and the checks pass.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Single-rank init_distributed binds no device_id, so torch warns at barrier() (since 0.19.7)

2 participants