vllm - ✅(Solved) Fix [RFC]: Unify the function of getting device count [1 pull requests, 6 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vllm-project/vllm#37849Fetched 2026-04-08 01:17:40
View on GitHub
Comments
6
Participants
3
Timeline
21
Reactions
1
Author
Timeline (top)
commented ×6mentioned ×6subscribed ×6cross-referenced ×1

Fix Action

Fixed

PR fix notes

PR #37841: replace cuda_device_count_stateless() to current_platform.device_count()

Description (problem / solution / changelog)

Purpose

as part of https://github.com/vllm-project/vllm/issues/37849 this pr, we have replaced all cuda_device_count_stateless() to current_platform.device_count() to extend the support for other accelerators like XPU

Test Plan

CI

Test Result


<details> <summary> Essential Elements of an Effective PR Description Checklist </summary>
  • The purpose of the PR, such as "Fix some issue (link existing issues this PR will resolve)".
  • The test plan, such as providing test command.
  • The test results, such as pasting the results comparison before and after, or e2e results
  • (Optional) The necessary documentation update, such as updating supported_models.md and examples for a new model.
  • (Optional) Release notes update. If your change is user facing, please update the release notes draft in the Google Doc.
</details>

Changed files

  • tests/compile/fullgraph/test_basic_correctness.py (modified, +2/-3)
  • tests/distributed/test_utils.py (modified, +1/-2)
  • tests/kernels/moe/test_modular_kernel_combinations.py (modified, +2/-2)
  • tests/model_executor/model_loader/test_reload.py (modified, +1/-2)
  • tests/models/quantization/test_gpt_oss.py (modified, +2/-2)
  • tests/utils.py (modified, +3/-4)
  • tests/v1/shutdown/test_delete.py (modified, +3/-3)
  • tests/v1/shutdown/test_forward_error.py (modified, +3/-3)
  • tests/v1/shutdown/test_startup_error.py (modified, +3/-3)
  • vllm/config/parallel.py (modified, +2/-3)
  • vllm/distributed/device_communicators/all_reduce_utils.py (modified, +2/-2)
  • vllm/distributed/device_communicators/custom_all_reduce.py (modified, +1/-2)
  • vllm/distributed/device_communicators/quick_all_reduce.py (modified, +1/-2)
  • vllm/usage/usage_lib.py (modified, +1/-2)
  • vllm/v1/executor/ray_utils.py (modified, +1/-2)
RAW_BUFFERClick to expand / collapse

Motivation.

now, we have three kinds of functions for getting device count as below,

  • cuda_device_count_stateless
  • current_platform.device_count
  • torch.accelerator.device_count() Sometimes it will make user to be confused to choose. we had better using one to unify. And for the first one, it is only for cuda, in some current usage in test/, it will block other accelerators like xpu. https://github.com/vllm-project/vllm/pull/37841 as an example, it will make the decorator multi_gpu_test can not work on xpu.

Proposed Change.

To choose current_platform.device_count or torch.accelerator.device_count(), I suggest torch.accelerator.device_count() as it is suggested by torch community, but current_platform.device_count is also ok to me. We can do below step by step.

  1. to replace the cuda_device_count_stateless() with current_platform.device_count or torch.accelerator.device_count()
  2. unify the usage of getting device count to current_platform.device_count or torch.accelerator.device_count()

Feedback Period.

No response

CC List.

@youkaichao @simon-mo @WoosukKwon @zhuohan123 @jikunshang

Any Other Things.

maybe related: https://github.com/vllm-project/vllm/issues/30679

Before submitting a new issue...

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

extent analysis

Fix Plan

To unify device count functions, we will replace cuda_device_count_stateless() with torch.accelerator.device_count().

Step-by-Step Solution:

  1. Replace cuda_device_count_stateless():

Before

from cuda_device_count_stateless import cuda_device_count_stateless

After

import torch

device_count = torch.accelerator.device_count()

2. **Unify device count usage**:
   * Search for `current_platform.device_count` and `cuda_device_count_stateless()` in the codebase.
   * Replace them with `torch.accelerator.device_count()`.

**Example Code Snippet:**
```python
import torch

def get_device_count():
    return torch.accelerator.device_count()

# Usage
device_count = get_device_count()
print(device_count)

Verification

Verify the fix by:

  • Running tests that previously used cuda_device_count_stateless() or current_platform.device_count.
  • Checking that torch.accelerator.device_count() returns the correct device count for different accelerators (e.g., CUDA, XPU).

Extra Tips

  • Ensure that the torch library is up-to-date to avoid compatibility issues.
  • Consider adding a fallback or error handling for cases where torch.accelerator.device_count() is not available.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING