Skip to content

[Bugfix] fix v1 cpu worker fails on macOS #19121

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions vllm/engine/arg_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,7 @@ def _is_v1_supported_oracle(self, model_config: ModelConfig) -> bool:
# Skip this check if we are running on a non-GPU platform,
# or if the device capability is not available
# (e.g. in a Ray actor without GPUs).
from vllm.platforms import current_platform
from vllm.platforms import CpuArchEnum, current_platform
if (current_platform.is_cuda()
and current_platform.get_device_capability()
and current_platform.get_device_capability().major < 8):
Expand Down Expand Up @@ -1434,7 +1434,8 @@ def _is_v1_supported_oracle(self, model_config: ModelConfig) -> bool:
# Non-[CUDA, TPU] may be supported on V1, but off by default for now.
v0_hardware = not any(
(current_platform.is_cuda(), current_platform.is_tpu(),
current_platform.is_cpu()))
(current_platform.is_cpu()
and current_platform.get_cpu_architecture() == CpuArchEnum.X86)))
if v0_hardware and _warn_or_fallback( # noqa: SIM103
current_platform.device_name):
return False
Expand Down
12 changes: 11 additions & 1 deletion vllm/platforms/cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project

import os
import platform
import sys
from importlib.util import find_spec
from typing import TYPE_CHECKING, Optional
Expand All @@ -22,6 +23,15 @@
VllmConfig = None


def get_max_threads(pid=0):
if hasattr(os, 'sched_getaffinity'):
return len(os.sched_getaffinity(pid))
elif platform.system() == 'Darwin':
return os.cpu_count()
else:
raise NotImplementedError("Unsupported OS")


class CpuPlatform(Platform):
_enum = PlatformEnum.CPU
device_name: str = "cpu"
Expand Down Expand Up @@ -190,7 +200,7 @@ def check_and_update_config(cls, vllm_config: VllmConfig) -> None:

# Note: to avoid the error 'nthreads cannot be larger than environment
# variable "NUMEXPR_MAX_THREADS" (64)'.
os.environ["NUMEXPR_MAX_THREADS"] = str(len(os.sched_getaffinity(0)))
os.environ["NUMEXPR_MAX_THREADS"] = str(get_max_threads())

# Set default threads num for OpenMP parallel
os.environ["OMP_NUM_THREADS"] = str(torch.get_num_threads())
Expand Down