Skip to content

Use device names, not rank ids, for device placement in test helpers - #8397

Merged
delock merged 2 commits into
deepspeedai:masterfrom
delock:pr-a-device-names
Sep 3, 2026
Merged

Use device names, not rank ids, for device placement in test helpers#8397
delock merged 2 commits into
deepspeedai:masterfrom
delock:pr-a-device-names

Conversation

@delock

@delock delock commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

Problem

get_accelerator().current_device() returns a device index on GPU backends (torch.cuda.current_device() → int), but on CPU it returns the LOCAL_RANK environment value — a plain string like '1'. Two test-side consumers fed that value straight into tensor/device placement:

  • reduce_boolean_flags in tests/unit/common.py (backbone of allclose_on_all_ranks, the "all ranks succeed or fail together" check)
  • 15 call sites in tests/unit/v1/autotp/test_autotp_training.py

On CPU this fails immediately with RuntimeError: Invalid device string: '1' — before the first collective even runs.

Change

  • Use current_device_name(), which returns a full device string on every backend ('cpu', 'cuda:N', 'mps:0', …) and is equivalent to the index on GPU backends.
  • In reduce_boolean_flags, carry the flag in a 1-dim tensor: gloo rejects 0-dim inputs to all_gather_into_tensor (NCCL tolerates them), so the previous form would have failed on the very next line.

Validation

Validated as part of the multi-rank CPU CI experiment in #8381 (same-commit baseline comparison): this failure class disappeared, zero regressions on previously-passing tests.

get_accelerator().current_device() returns a CUDA device index on GPU
backends, but on CPU it is the LOCAL_RANK environment value, a plain
string like '1' that torch rejects as a device ("Invalid device
string"). reduce_boolean_flags and the autotp tests fed that value
straight into tensor/device placement, so multi-rank CPU runs failed
before reaching their first collective.

Use current_device_name() instead: it yields a full device string on
every backend ('cpu', 'cuda:N', ...) and is equivalent to the index on
GPU backends. Also carry the boolean flag in a 1-dim tensor because
gloo rejects 0-dim inputs to all_gather_into_tensor.

Validated as part of the multi-rank CPU experiment in deepspeedai#8381: this
failure class disappeared with zero regressions vs the same-commit
baseline.

Signed-off-by: Guokai Ma <guokai.ma@intel.com>

@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: 8ceca37333

ℹ️ 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 tests/unit/common.py
device = get_accelerator().current_device()
tensor_flag = torch.tensor(1 if flag else 0, dtype=torch.int, device=device)
# current_device() is a rank id on CPU, not a valid torch device; use the device name.
device = get_accelerator().current_device_name()

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Add the required sign-off trailer

This is a non-merge commit, but its message has no Signed-off-by trailer, so it violates the repository's mandatory commit requirement and may be rejected by DCO/CI checks. Recreate the commit with --signoff using the configured Git identity.

AGENTS.md reference: AGENTS.md:L8-L8

Useful? React with 👍 / 👎.

@delock
delock enabled auto-merge September 3, 2026 09:55
@delock
delock disabled auto-merge September 3, 2026 09:55
The reference-input randn() call exceeds the 119-column limit, failing
the formatting CI. Split one argument per line as yapf requires.

Signed-off-by: Ma, Guokai <guokai.ma@intel.com>
@delock
delock enabled auto-merge September 3, 2026 10:34
@delock
delock added this pull request to the merge queue Sep 3, 2026
Merged via the queue into deepspeedai:master with commit 4fd3c82 Sep 3, 2026
13 checks passed
@delock
delock deleted the pr-a-device-names branch September 3, 2026 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants