[Bugfix] Detect the CUDA toolkit the way FlashInfer does in has_flashinfer() (#58360)

Signed-off-by: Bowen Wang <bowen@inferact.ai>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bowen Wang
2026-09-29 04:14:49 +00:00
committed by GitHub
co-authored by Claude Opus 5.5
parent 13c8589b86
commit 1fde8ff7da
2 changed files with 86 additions and 6 deletions
+60
View File
@@ -0,0 +1,60 @@
# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
import importlib.util
from collections.abc import Iterator
from pathlib import Path
import pytest
import vllm.utils.flashinfer as fi
def _make_exe(path: Path) -> None:
path.parent.mkdir(parents=True, exist_ok=True)
path.touch(mode=0o755)
@pytest.fixture
def default_cuda_home(monkeypatch: pytest.MonkeyPatch, tmp_path: Path) -> Path:
"""Hide any real toolkit, keep ninja on PATH, redirect /usr/local/cuda."""
for var in ("CUDA_HOME", "CUDA_PATH", "FLASHINFER_NVCC"):
monkeypatch.delenv(var, raising=False)
_make_exe(tmp_path / "venv" / "bin" / "ninja")
monkeypatch.setenv("PATH", str(tmp_path / "venv" / "bin"))
home = tmp_path / "usr_local_cuda"
monkeypatch.setattr(fi, "_DEFAULT_CUDA_HOME", str(home))
return home
@pytest.fixture(autouse=True)
def flashinfer_without_cubin(monkeypatch: pytest.MonkeyPatch) -> Iterator[None]:
"""Pretend flashinfer-python is installed without flashinfer-cubin."""
real_find_spec = importlib.util.find_spec
monkeypatch.setattr(
importlib.util,
"find_spec",
lambda name, *args: (
object() if name == "flashinfer" else real_find_spec(name, *args)
),
)
monkeypatch.setattr(fi, "has_flashinfer_cubin", lambda: False)
fi.has_flashinfer.cache_clear()
yield
fi.has_flashinfer.cache_clear()
def test_has_flashinfer_finds_toolkit_off_path(default_cuda_home: Path):
"""Bare-metal installs keep nvcc in /usr/local/cuda, off PATH, which is
where FlashInfer's JIT finds it."""
_make_exe(default_cuda_home / "bin" / "nvcc")
assert fi.has_flashinfer()
def test_has_flashinfer_requires_ninja(
default_cuda_home: Path, monkeypatch: pytest.MonkeyPatch, tmp_path: Path
):
"""FlashInfer runs `ninja` from PATH, which lacks the venv's bin directory
when vLLM is launched without activating the venv."""
_make_exe(tmp_path / "cuda" / "bin" / "nvcc")
monkeypatch.setenv("PATH", str(tmp_path / "cuda" / "bin"))
assert not fi.has_flashinfer()