@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 2a36d8fb72
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 5, 13:30 UTC

[Bugfix][CPU] Fix macOS compatibility broken by #36487 (#38970)

Signed-off-by: Ziming (2imi9) <148090931+2imi9@users.noreply.github.com>

Ziming Qi committed Apr 4, 2026 at 10:05 UTC 2a36d8fb72e6664324340c2e6214b5a0c95893da
2 files changed +36 -5
vllm/platforms/cpu.py
+6 -1
@@ -381,7 +381,12 @@ class CpuPlatform(Platform):
381 def get_global_cpu_mask(cls) -> set[int]:
382 # get global cpu mask
383 if cls.global_cpu_mask is None:
384 - cls.global_cpu_mask = os.sched_getaffinity(0)
384 + if hasattr(os, "sched_getaffinity"):
385 + cls.global_cpu_mask = os.sched_getaffinity(0)
386 + else:
387 + # macOS does not support sched_getaffinity
388 + cpu_count = os.cpu_count() or 1
389 + cls.global_cpu_mask = set(range(cpu_count))
390 return cls.global_cpu_mask
391
392 @classmethod
vllm/utils/ompmultiprocessing.py
+30 -4
@@ -7,6 +7,7 @@ Copyright (c) 2026 Cambridge Greys Ltd
7
8 import json
9 import os
10 +import platform
11 import subprocess
12
13
@@ -38,10 +39,37 @@ def parse_mask(mask):
39 return set(result)
40
41
42 +def _get_default_affinity() -> set[int]:
43 + """Get the set of CPUs the process is allowed to run on."""
44 + if hasattr(os, "sched_getaffinity"):
45 + return os.sched_getaffinity(0)
46 + # macOS does not support sched_getaffinity; fall back to cpu_count
47 + cpu_count = os.cpu_count() or 1
48 + return set(range(cpu_count))
49 +
50 +
51 +def _get_cpu_topology_json() -> bytes:
52 + """Get CPU topology as JSON.
53 +
54 + On Linux this uses ``lscpu -Je``. On other platforms (e.g. macOS) we
55 + synthesize a simple topology where every logical CPU is its own core
56 + on NUMA node 0, which is sufficient for the OMP place-list builder.
57 + """
58 + if platform.system() == "Linux":
59 + return subprocess.run(["lscpu", "-Je"], check=True, capture_output=True).stdout
60 +
61 + # Fallback for non-Linux (macOS, etc.)
62 + cpu_count = os.cpu_count() or 1
63 + cpus = []
64 + for i in range(cpu_count):
65 + cpus.append({"cpu": str(i), "core": str(i), "node": "0"})
66 + return json.dumps({"cpus": cpus}).encode()
67 +
68 +
69 def enumerate_resources(resource_map, mask=None, allowed=None):
70 """Enumerate system resources"""
71 if allowed is None:
44 - allowed = os.sched_getaffinity(0)
72 + allowed = _get_default_affinity()
73 if mask is not None:
74 allowed = allowed & mask
75
@@ -140,9 +168,7 @@ class OMPProcessManager:
168 else:
169 masks = [None]
170 if mock is None:
143 - data = subprocess.run(
144 - ["lscpu", "-Je"], check=True, capture_output=True
145 - ).stdout
171 + data = _get_cpu_topology_json()
172 else:
173 with open(mock, mode="rb") as jf:
174 data = jf.read()