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/tests/utils_/test_system_utils.py b/tests/utils_/test_system_utils.py index 5ef55877a7c7..7e551d800d94 100644 --- a/tests/utils_/test_system_utils.py +++ b/tests/utils_/test_system_utils.py @@ -5,6 +5,9 @@ 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 @@ -25,3 +28,68 @@ 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] + + +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/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." diff --git a/vllm/entrypoints/launcher.py b/vllm/entrypoints/launcher.py index 08a3ab58c780..59ae90825226 100644 --- a/vllm/entrypoints/launcher.py +++ b/vllm/entrypoints/launcher.py @@ -4,6 +4,7 @@ import asyncio import signal import socket +import sys from functools import partial from typing import Any @@ -105,6 +106,8 @@ async def dummy_shutdown() -> None: 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 c3b59344354d..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 @@ -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,29 @@ 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. + 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: + 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 +395,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