From 3ef9cc24aeb2e2fc32cc7feae4b8e1188b39a4da Mon Sep 17 00:00:00 2001 From: Arif Ahmed Date: Thu, 3 Sep 2026 09:06:24 -0700 Subject: [PATCH 1/3] [Build][Windows ARM64] Isolate architecture profiles Use separate setuptools and CMake staging directories per CUDA architecture profile, normalize the ARM64 MSVC environment, and validate the standard protobuf include tree required by the Rust frontend. Assisted-by: OpenAI Codex Signed-off-by: Arif Ahmed --- setup.py | 7 +++- tools/build-win-arm64.ps1 | 80 +++++++++++++++++++++++++++++++++++---- 2 files changed, 79 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 1522d104b833..0d81f4610f46 100644 --- a/setup.py +++ b/setup.py @@ -1334,6 +1334,10 @@ def add_vllm_package_data(filename: str) -> None: optional=not should_require_rust_frontend() ) +setup_options: dict[str, dict[str, str]] = {} +if build_base := os.environ.get("VLLM_BUILD_BASE"): + setup_options["build"] = {"build_base": str(Path(build_base).resolve())} + setup( # static metadata should rather go in pyproject.toml version=get_vllm_version(), @@ -1379,4 +1383,5 @@ def add_vllm_package_data(filename: str) -> None: }, cmdclass=cmdclass, package_data=package_data, -) \ No newline at end of file + options=setup_options, +) diff --git a/tools/build-win-arm64.ps1 b/tools/build-win-arm64.ps1 index 32c926d05e8a..59c15fc172af 100644 --- a/tools/build-win-arm64.ps1 +++ b/tools/build-win-arm64.ps1 @@ -2,6 +2,8 @@ param( [string]$VenvDir = "", [string]$WheelDir = "", + [string]$BuildBase = "", + [string]$ConfigureDir = "", [string]$CudaPath = $env:CUDA_PATH, [string]$VisualStudioPath = "", [string]$MsvcToolsetVersion = "14.51.36231", @@ -13,6 +15,7 @@ param( [string]$VersionOverride = "0.26.0+cu134", [string]$PerlPath = "", [string]$ProtocPath = "", + [string]$ProtocIncludePath = "", [switch]$SkipRustFrontend, [switch]$SkipBuild ) @@ -23,7 +26,8 @@ param( # cmake>=3.26.1, ninja, packaging>=24.2, setuptools>=77.0.3,<81.0.0, # setuptools-scm>=8, setuptools-rust>=1.9.0, wheel, jinja2>=3.1.6, regex, # build, protobuf, Rust 1.95+, and a full Perl distribution for vendored -# OpenSSL. Pass -PerlPath and -ProtocPath when they are not discoverable. +# OpenSSL. Pass -PerlPath, -ProtocPath, and -ProtocIncludePath when they are not +# discoverable; the include path must contain google\protobuf\struct.proto. # # Example: # uv pip install --python "\Scripts\python.exe" ` @@ -44,8 +48,23 @@ if (-not $WheelDir) { $VenvDir = [IO.Path]::GetFullPath($VenvDir) $WheelDir = [IO.Path]::GetFullPath($WheelDir) +$buildProfile = [regex]::Replace( + $CudaArchList.ToLowerInvariant().Replace("+", "-"), + "[^0-9a-z]+", + "-" +).Trim("-") +if (-not $buildProfile) { + throw "CudaArchList did not produce a valid build profile name." +} +if (-not $BuildBase) { + $BuildBase = Join-Path $RepoRoot "build\profiles\$buildProfile" +} +$BuildBase = [IO.Path]::GetFullPath($BuildBase) $CudaOverlay = Join-Path $RepoRoot "build\cuda-include-arm64" -$ConfigureDir = Join-Path $RepoRoot "build\win-arm64-config" +if (-not $ConfigureDir) { + $ConfigureDir = Join-Path $BuildBase "configure-only" +} +$ConfigureDir = [IO.Path]::GetFullPath($ConfigureDir) function Find-VcVarsAll { if ($VisualStudioPath) { @@ -93,27 +112,44 @@ function Find-VcVarsAll { function Import-Arm64MsvcEnvironment { $vcvars = Find-VcVarsAll $installer = Join-Path ${env:ProgramFiles(x86)} "Microsoft Visual Studio\Installer" + $pathMarker = "__VLLM_VCVARS_PATH__=" $command = ( - "set `"PATH=$installer;%PATH%`" && " + - "call `"$vcvars`" arm64 -vcvars_ver=$MsvcToolsetVersion >nul && set" + "set `"PATH=$installer;!PATH!`" && " + + "call `"$vcvars`" arm64 -vcvars_ver=$MsvcToolsetVersion >nul && " + + "echo $pathMarker!PATH! && set" ) - $lines = & $env:ComSpec /d /s /c $command + $lines = & $env:ComSpec /d /v:on /s /c $command if ($LASTEXITCODE -ne 0) { throw "vcvarsall.bat failed with code $LASTEXITCODE" } + $vcvarsPath = $null foreach ($line in $lines) { + if ($line.StartsWith($pathMarker, [StringComparison]::Ordinal)) { + $vcvarsPath = $line.Substring($pathMarker.Length) + continue + } $separator = $line.IndexOf("=") if ($separator -le 0) { continue } + $name = $line.Substring(0, $separator) + $value = $line.Substring($separator + 1) + if ($name -ieq "Path") { + continue + } [Environment]::SetEnvironmentVariable( - $line.Substring(0, $separator), - $line.Substring($separator + 1), + $name, + $value, "Process" ) } + if (-not $vcvarsPath) { + throw "vcvarsall.bat did not emit PATH." + } + $env:PATH = $vcvarsPath + $cl = Get-Command cl.exe -ErrorAction Stop if ($cl.Source -notmatch "\\(HostARM64|Hostx64)\\arm64\\cl\.exe$") { throw "MSVC is not targeting ARM64: $($cl.Source)" @@ -170,11 +206,38 @@ function Initialize-RustBuildEnvironment { throw "protoc.exe is required for the Rust frontend. Pass -ProtocPath." } + $resolvedProtocInclude = $ProtocIncludePath + if (-not $resolvedProtocInclude) { + $protocRoot = Split-Path -Parent (Split-Path -Parent $resolvedProtoc) + $protocIncludeCandidates = @( + (Join-Path $protocRoot "include"), + (Join-Path $VenvDir "Library\include") + ) + $resolvedProtocInclude = $protocIncludeCandidates | + Where-Object { + Test-Path -LiteralPath ( + Join-Path $_ "google\protobuf\struct.proto" + ) -PathType Leaf + } | + Select-Object -First 1 + } + $standardProto = if ($resolvedProtocInclude) { + Join-Path $resolvedProtocInclude "google\protobuf\struct.proto" + } + if (-not $standardProto -or -not (Test-Path -LiteralPath $standardProto -PathType Leaf)) { + throw ( + "The protoc standard include tree is required for the Rust frontend. " + + "Pass -ProtocIncludePath with a directory containing " + + "google\protobuf\struct.proto." + ) + } + $env:PATH = ( (Split-Path -Parent $resolvedPerl), $env:PATH ) -join [IO.Path]::PathSeparator $env:PROTOC = (Resolve-Path -LiteralPath $resolvedProtoc).Path + $env:PROTOC_INCLUDE = (Resolve-Path -LiteralPath $resolvedProtocInclude).Path $env:VLLM_REQUIRE_RUST_FRONTEND = "1" } @@ -340,6 +403,7 @@ function Set-BuildEnvironment { $env:VLLM_DISABLE_FA3_BUILD = "1" $env:VLLM_DISABLE_SCCACHE = "1" $env:VLLM_VERSION_OVERRIDE = $VersionOverride + $env:VLLM_BUILD_BASE = $BuildBase Initialize-RustBuildEnvironment @@ -458,6 +522,8 @@ function Invoke-ConfigureOnly { } $tools = Set-BuildEnvironment +Write-Host "Build profile: $buildProfile" +Write-Host "Build base: $BuildBase" git -C $RepoRoot diff --check if ($LASTEXITCODE -ne 0) { throw "The source worktree has whitespace errors." From a3ac9f2f5675a800ab06abc5d08f883503abf3e2 Mon Sep 17 00:00:00 2001 From: Arif Ahmed Date: Thu, 3 Sep 2026 09:06:25 -0700 Subject: [PATCH 2/3] [Runtime][Windows] Use native shutdown primitives Register Windows signals through signal.signal and terminate process trees through psutil while retaining the existing Unix behavior. Assisted-by: OpenAI Codex Signed-off-by: Arif Ahmed --- tests/entrypoints/test_launcher.py | 42 ++++++++++++++++++++++++++++++ tests/utils_/test_system_utils.py | 28 ++++++++++++++++++++ vllm/entrypoints/launcher.py | 17 ++++++++++-- vllm/utils/system_utils.py | 27 ++++++++++++------- 4 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 tests/entrypoints/test_launcher.py diff --git a/tests/entrypoints/test_launcher.py b/tests/entrypoints/test_launcher.py new file mode 100644 index 000000000000..beda790eda5e --- /dev/null +++ b/tests/entrypoints/test_launcher.py @@ -0,0 +1,42 @@ +# SPDX-License-Identifier: Apache-2.0 +# SPDX-FileCopyrightText: Copyright contributors to the vLLM project + +import signal +from unittest.mock import Mock, call + +from vllm.entrypoints import launcher + + +def test_register_signal_handlers_on_windows(monkeypatch): + loop = Mock() + handler = Mock() + register = Mock() + monkeypatch.setattr(launcher.sys, "platform", "win32") + monkeypatch.setattr(launcher.signal, "signal", register) + + launcher._register_signal_handlers(loop, handler) + + loop.add_signal_handler.assert_not_called() + assert [registered.args[0] for registered in register.call_args_list] == [ + signal.SIGINT, + signal.SIGTERM, + ] + for registered in register.call_args_list: + registered.args[1](None, None) + assert handler.call_count == 2 + + +def test_register_signal_handlers_on_non_windows(monkeypatch): + loop = Mock() + handler = Mock() + register = Mock() + monkeypatch.setattr(launcher.sys, "platform", "linux") + monkeypatch.setattr(launcher.signal, "signal", register) + + launcher._register_signal_handlers(loop, handler) + + assert loop.add_signal_handler.call_args_list == [ + call(signal.SIGINT, handler), + call(signal.SIGTERM, handler), + ] + register.assert_not_called() diff --git a/tests/utils_/test_system_utils.py b/tests/utils_/test_system_utils.py index 5ef55877a7c7..e2e045fb26fd 100644 --- a/tests/utils_/test_system_utils.py +++ b/tests/utils_/test_system_utils.py @@ -5,6 +5,7 @@ import tempfile from pathlib import Path +from vllm.utils import system_utils from vllm.utils.system_utils import _maybe_force_spawn, unique_filepath @@ -25,3 +26,30 @@ def test_numa_bind_forces_spawn(monkeypatch): monkeypatch.setattr("sys.argv", ["vllm", "serve", "--numa-bind"]) _maybe_force_spawn() assert os.environ["VLLM_WORKER_MULTIPROC_METHOD"] == "spawn" + + +def test_kill_process_tree_uses_psutil_kill_on_windows(monkeypatch): + killed: list[int] = [] + + class FakeProcess: + def __init__(self, pid: int, children: list["FakeProcess"] | None = None): + self.pid = pid + self._children = children or [] + + def children(self, recursive: bool): + assert recursive + return self._children + + def kill(self): + killed.append(self.pid) + + child_one = FakeProcess(11) + child_two = FakeProcess(12) + parent = FakeProcess(10, [child_one, child_two]) + + monkeypatch.setattr(system_utils.sys, "platform", "win32") + monkeypatch.setattr(system_utils.psutil, "Process", lambda pid: parent) + + system_utils.kill_process_tree(10) + + assert killed == [11, 12, 10] diff --git a/vllm/entrypoints/launcher.py b/vllm/entrypoints/launcher.py index 08a3ab58c780..b76ee8aeaade 100644 --- a/vllm/entrypoints/launcher.py +++ b/vllm/entrypoints/launcher.py @@ -4,6 +4,8 @@ import asyncio import signal import socket +import sys +from collections.abc import Callable from functools import partial from typing import Any @@ -23,6 +25,18 @@ logger = init_logger(__name__) +def _register_signal_handlers( + loop: asyncio.AbstractEventLoop, + signal_handler: Callable[[], None], +) -> None: + if sys.platform == "win32": + signal.signal(signal.SIGINT, lambda *_: signal_handler()) + signal.signal(signal.SIGTERM, lambda *_: signal_handler()) + else: + loop.add_signal_handler(signal.SIGINT, signal_handler) + loop.add_signal_handler(signal.SIGTERM, signal_handler) + + async def serve_http( app: FastAPI, sock: socket.socket | None, @@ -103,8 +117,7 @@ def signal_handler() -> None: async def dummy_shutdown() -> None: pass - loop.add_signal_handler(signal.SIGINT, signal_handler) - loop.add_signal_handler(signal.SIGTERM, signal_handler) + _register_signal_handlers(loop, signal_handler) async def handle_shutdown() -> None: await shutdown_event.wait() diff --git a/vllm/utils/system_utils.py b/vllm/utils/system_utils.py index c3b59344354d..c9bf0b081144 100644 --- a/vllm/utils/system_utils.py +++ b/vllm/utils/system_utils.py @@ -257,7 +257,7 @@ def decorate_logs( def kill_process_tree(pid: int): """ - Kills all descendant processes of the given pid by sending SIGKILL. + Forcefully terminates the process and all of its descendants. Args: pid (int): Process ID of the parent process @@ -270,14 +270,23 @@ def kill_process_tree(pid: int): # Get all children recursively children = parent.children(recursive=True) - # Send SIGKILL to all children first - for child in children: - with contextlib.suppress(ProcessLookupError): - os.kill(child.pid, signal.SIGKILL) + if sys.platform == "win32": + # signal.SIGKILL does not exist on Windows; psutil.kill() uses + # TerminateProcess and preserves the same forceful-shutdown semantics. + for child in children: + with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied): + child.kill() + with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied): + parent.kill() + else: + # Send SIGKILL to all children first + for child in children: + with contextlib.suppress(ProcessLookupError): + os.kill(child.pid, signal.SIGKILL) - # Finally kill the parent - with contextlib.suppress(ProcessLookupError): - os.kill(pid, signal.SIGKILL) + # Finally kill the parent + with contextlib.suppress(ProcessLookupError): + os.kill(pid, signal.SIGKILL) # Resource utilities @@ -380,4 +389,4 @@ def find_loaded_library(lib_name: str) -> str | None: elif "cumem_allocator" in lib_name: path = os.path.join(os.path.dirname(__file__), '..', 'cumem_allocator.pyd') - return path \ No newline at end of file + return path From cc1a57a593e9497c46c45cfc94155d4cb48b6e38 Mon Sep 17 00:00:00 2001 From: Arif Ahmed Date: Tue, 8 Sep 2026 11:39:42 -0700 Subject: [PATCH 3/3] [Runtime][Windows] Address shutdown review feedback Preserve winloop signal registration and add SIGBREAK for Windows console shutdown. Continue process-tree cleanup after AccessDenied and surface the error after remaining processes are attempted. Assisted-by: OpenAI Codex Signed-off-by: Arif Ahmed --- tests/entrypoints/test_launcher.py | 42 ------------------------------ tests/utils_/test_system_utils.py | 40 ++++++++++++++++++++++++++++ vllm/entrypoints/launcher.py | 18 +++---------- vllm/utils/system_utils.py | 18 ++++++++----- 4 files changed, 56 insertions(+), 62 deletions(-) delete mode 100644 tests/entrypoints/test_launcher.py diff --git a/tests/entrypoints/test_launcher.py b/tests/entrypoints/test_launcher.py deleted file mode 100644 index beda790eda5e..000000000000 --- a/tests/entrypoints/test_launcher.py +++ /dev/null @@ -1,42 +0,0 @@ -# SPDX-License-Identifier: Apache-2.0 -# SPDX-FileCopyrightText: Copyright contributors to the vLLM project - -import signal -from unittest.mock import Mock, call - -from vllm.entrypoints import launcher - - -def test_register_signal_handlers_on_windows(monkeypatch): - loop = Mock() - handler = Mock() - register = Mock() - monkeypatch.setattr(launcher.sys, "platform", "win32") - monkeypatch.setattr(launcher.signal, "signal", register) - - launcher._register_signal_handlers(loop, handler) - - loop.add_signal_handler.assert_not_called() - assert [registered.args[0] for registered in register.call_args_list] == [ - signal.SIGINT, - signal.SIGTERM, - ] - for registered in register.call_args_list: - registered.args[1](None, None) - assert handler.call_count == 2 - - -def test_register_signal_handlers_on_non_windows(monkeypatch): - loop = Mock() - handler = Mock() - register = Mock() - monkeypatch.setattr(launcher.sys, "platform", "linux") - monkeypatch.setattr(launcher.signal, "signal", register) - - launcher._register_signal_handlers(loop, handler) - - assert loop.add_signal_handler.call_args_list == [ - call(signal.SIGINT, handler), - call(signal.SIGTERM, handler), - ] - register.assert_not_called() diff --git a/tests/utils_/test_system_utils.py b/tests/utils_/test_system_utils.py index e2e045fb26fd..7e551d800d94 100644 --- a/tests/utils_/test_system_utils.py +++ b/tests/utils_/test_system_utils.py @@ -5,6 +5,8 @@ import tempfile from pathlib import Path +import pytest + from vllm.utils import system_utils from vllm.utils.system_utils import _maybe_force_spawn, unique_filepath @@ -53,3 +55,41 @@ def kill(self): system_utils.kill_process_tree(10) assert killed == [11, 12, 10] + + +def test_kill_process_tree_surfaces_access_denied_after_remaining_kills(monkeypatch): + attempted: list[int] = [] + access_denied = system_utils.psutil.AccessDenied(pid=11) + + class FakeProcess: + def __init__( + self, + pid: int, + error: Exception | None = None, + children: list["FakeProcess"] | None = None, + ): + self.pid = pid + self._error = error + self._children = children or [] + + def children(self, recursive: bool): + assert recursive + return self._children + + def kill(self): + attempted.append(self.pid) + if self._error is not None: + raise self._error + + child_denied = FakeProcess(11, access_denied) + child_exited = FakeProcess(12, system_utils.psutil.NoSuchProcess(pid=12)) + parent = FakeProcess(10, children=[child_denied, child_exited]) + + monkeypatch.setattr(system_utils.sys, "platform", "win32") + monkeypatch.setattr(system_utils.psutil, "Process", lambda pid: parent) + + with pytest.raises(system_utils.psutil.AccessDenied) as exc_info: + system_utils.kill_process_tree(10) + + assert exc_info.value is access_denied + assert attempted == [11, 12, 10] diff --git a/vllm/entrypoints/launcher.py b/vllm/entrypoints/launcher.py index b76ee8aeaade..59ae90825226 100644 --- a/vllm/entrypoints/launcher.py +++ b/vllm/entrypoints/launcher.py @@ -5,7 +5,6 @@ import signal import socket import sys -from collections.abc import Callable from functools import partial from typing import Any @@ -25,18 +24,6 @@ logger = init_logger(__name__) -def _register_signal_handlers( - loop: asyncio.AbstractEventLoop, - signal_handler: Callable[[], None], -) -> None: - if sys.platform == "win32": - signal.signal(signal.SIGINT, lambda *_: signal_handler()) - signal.signal(signal.SIGTERM, lambda *_: signal_handler()) - else: - loop.add_signal_handler(signal.SIGINT, signal_handler) - loop.add_signal_handler(signal.SIGTERM, signal_handler) - - async def serve_http( app: FastAPI, sock: socket.socket | None, @@ -117,7 +104,10 @@ def signal_handler() -> None: async def dummy_shutdown() -> None: pass - _register_signal_handlers(loop, signal_handler) + loop.add_signal_handler(signal.SIGINT, signal_handler) + loop.add_signal_handler(signal.SIGTERM, signal_handler) + if sys.platform == "win32": + loop.add_signal_handler(signal.SIGBREAK, signal_handler) async def handle_shutdown() -> None: await shutdown_event.wait() diff --git a/vllm/utils/system_utils.py b/vllm/utils/system_utils.py index c9bf0b081144..74f9821c68d7 100644 --- a/vllm/utils/system_utils.py +++ b/vllm/utils/system_utils.py @@ -7,11 +7,11 @@ import multiprocessing import os import platform -from shutil import which import signal import sys from collections.abc import Callable, Iterator from pathlib import Path +from shutil import which from typing import TextIO import psutil @@ -273,11 +273,17 @@ def kill_process_tree(pid: int): if sys.platform == "win32": # signal.SIGKILL does not exist on Windows; psutil.kill() uses # TerminateProcess and preserves the same forceful-shutdown semantics. - for child in children: - with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied): - child.kill() - with contextlib.suppress(psutil.NoSuchProcess, psutil.AccessDenied): - parent.kill() + access_denied: psutil.AccessDenied | None = None + for process in [*children, parent]: + try: + process.kill() + except psutil.NoSuchProcess: + pass + except psutil.AccessDenied as exc: + if access_denied is None: + access_denied = exc + if access_denied is not None: + raise access_denied else: # Send SIGKILL to all children first for child in children: