Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: a masked NVIDIA GPU must not install the CPU bundle over CUDA (#10909)

Daniel Han9e911ee46334
diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.py
index 940ef58beb9..a822fac973c 100644
--- a/studio/install_llama_prebuilt.py
+++ b/studio/install_llama_prebuilt.py
@@ -376,6 +376,11 @@ class HostInfo:
has_physical_nvidia: bool
has_usable_nvidia: bool
has_rocm: bool = False
+ # Every compute cap nvidia-smi reported, before CUDA_VISIBLE_DEVICES filtering.
+ # compute_caps holds only the VISIBLE ones and empties under a mask, which is the
+ # selector's unknown-SM path: it skips min_sm/max_sm and could hand a masked sm_61
+ # host an sm_70 floor.
+ physical_compute_caps: list[str] = field(default_factory = list)
has_intel_gpu: bool = False
# AMD present, ROCm unusable. Probed only when neither NVIDIA nor ROCm is usable.
has_amd_gpu_without_rocm: bool = False
@@ -2563,6 +2568,7 @@ def detect_host(*, probe_rocm_with_nvidia: bool = False) -> HostInfo:
nvidia_smi = shutil.which("nvidia-smi")
driver_cuda_version = None
compute_caps: list[str] = []
+ physical_compute_caps: list[str] = []
visible_cuda_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
visible_device_tokens = parse_cuda_visible_devices(visible_cuda_devices)
has_physical_nvidia = False
@@ -2615,6 +2621,11 @@ def detect_host(*, probe_rocm_with_nvidia: bool = False) -> HostInfo:
if len(parts) != 3:
continue
index, uuid, cap = parts
+ normalized_cap = normalize_compute_cap(cap)
+ # Recorded before the mask filter: an emptied CUDA_VISIBLE_DEVICES drops
+ # every row, and a selection made for the hardware still needs its SMs.
+ if normalized_cap is not None and normalized_cap not in physical_compute_caps:
+ physical_compute_caps.append(normalized_cap)
visible_gpu_row = select_visible_gpu_rows(
[(index, uuid, cap)],
visible_device_tokens,
@@ -2622,7 +2633,6 @@ def detect_host(*, probe_rocm_with_nvidia: bool = False) -> HostInfo:
if not visible_gpu_row:
continue
visible_gpu_rows.extend(visible_gpu_row)
- normalized_cap = normalize_compute_cap(cap)
if normalized_cap is None:
continue
if normalized_cap not in compute_caps:
@@ -2843,6 +2853,7 @@ def detect_host(*, probe_rocm_with_nvidia: bool = False) -> HostInfo:
nvidia_smi = nvidia_smi,
driver_cuda_version = driver_cuda_version,
compute_caps = compute_caps,
+ physical_compute_caps = physical_compute_caps,
visible_cuda_devices = visible_cuda_devices,
has_physical_nvidia = has_physical_nvidia,
has_usable_nvidia = has_usable_nvidia,
@@ -6475,6 +6486,47 @@ def _linux_published_attempts(host: HostInfo, bundle: PublishedReleaseBundle) ->
vulkan_choice = published_asset_choice_for_kind(bundle, "linux-vulkan", host = host)
if vulkan_choice is not None:
attempts.append(vulkan_choice)
+ # physical-without-usable means exactly one thing: the GPU is there and
+ # CUDA_VISIBLE_DEVICES is empty or -1. The mask is scoped to this process;
+ # activate_install_tree is not, so one masked run would leave a CUDA machine on the
+ # CPU bundle for good. Select CUDA as if unmasked -- nvidia-smi is NVML and still
+ # answers under the mask. The mask still bites at RUN time, where the CUDA build
+ # sees no devices and runs on CPU exactly as the CPU bundle would.
+ # Below ROCm and Vulkan on purpose: a masked NVIDIA host with usable ROCm keeps ROCm,
+ # and an explicit CPU request never arrives here at all because _apply_host_overrides
+ # has already cleared has_physical_nvidia.
+ if host.has_physical_nvidia:
+ log(
+ "NVIDIA GPU present but hidden by CUDA_VISIBLE_DEVICES="
+ f"{host.visible_cuda_devices!r}; selecting the CUDA bundle for the hardware "
+ "rather than installing the CPU bundle over it"
+ )
+ # Select against the PHYSICAL caps: host.compute_caps is empty here by
+ # construction, which is the selector's unknown-SM path, so a masked sm_61 host
+ # would accept an sm_70 floor and still have no offload once unmasked.
+ selection_host = host
+ if host.physical_compute_caps and not host.compute_caps:
+ selection_host = dataclasses_replace(
+ host, compute_caps = list(host.physical_compute_caps)
+ )
+ log(
+ "selecting against the physical compute caps "
+ f"{','.join(selection_host.compute_caps)} the mask hid"
+ )
+ torch_preference = detect_torch_cuda_runtime_preference(
+ selection_host, gpu_hidden_by_mask = True
+ )
+ masked_selection = linux_cuda_choice_from_release(
+ selection_host,
+ bundle,
+ preferred_runtime_line = torch_preference.runtime_line,
+ selection_preamble = torch_preference.selection_log,
+ )
+ if masked_selection is not None:
+ attempts.extend(masked_selection.attempts)
+ # No CUDA match: fall through to an empty list so the caller source-builds with
+ # CUDA, exactly as a visible NVIDIA host with no match does. Never the CPU bundle.
+ return attempts
# CPU-only host. A usable-NVIDIA host never reaches here -- if its CUDA
# selection produced nothing we want an empty attempt list so the caller
# source-builds with CUDA, not a CPU-only binary silently installed on a
diff --git a/studio/prebuilt_core.py b/studio/prebuilt_core.py
index 6a227d8ebf4..afceebfb617 100644
--- a/studio/prebuilt_core.py
+++ b/studio/prebuilt_core.py
@@ -1509,12 +1509,21 @@ class CudaRuntimePreference:
selection_log: list[str]
-def detect_torch_cuda_runtime_preference(host: Any) -> CudaRuntimePreference:
+def detect_torch_cuda_runtime_preference(
+ host: Any, *, gpu_hidden_by_mask: bool = False
+) -> CudaRuntimePreference:
+ """The runtime line Torch was built against, so the bundle matches the venv.
+
+ `gpu_hidden_by_mask` is for a caller that already established an NVIDIA GPU hidden by
+ CUDA_VISIBLE_DEVICES. Both usual gates answer "no GPU" under that mask, so selection
+ would fall back to newest-first and hand a cu12 venv a CUDA 13 bundle. No mask touches
+ torch.version.cuda, so it is read without the availability check.
+ """
selection_log: list[str] = []
if host.is_macos:
selection_log.append("torch_cuda_preference: skipped on macOS")
return CudaRuntimePreference(runtime_line = None, selection_log = selection_log)
- if not (host.has_usable_nvidia and (host.is_linux or host.is_windows)):
+ if not ((host.has_usable_nvidia or gpu_hidden_by_mask) and (host.is_linux or host.is_windows)):
selection_log.append(
"torch_cuda_preference: skipped because CUDA host prerequisites were not met"
)
@@ -1533,11 +1542,18 @@ def detect_torch_cuda_runtime_preference(host: Any) -> CudaRuntimePreference:
)
return CudaRuntimePreference(runtime_line = None, selection_log = selection_log)
- try:
- cuda_available = bool(torch.cuda.is_available())
- except Exception as exc:
- selection_log.append(f"torch_cuda_preference: torch.cuda.is_available() failed: {exc}")
- return CudaRuntimePreference(runtime_line = None, selection_log = selection_log)
+ if gpu_hidden_by_mask:
+ cuda_available = True
+ selection_log.append(
+ "torch_cuda_preference: GPU hidden by CUDA_VISIBLE_DEVICES; reading "
+ "torch.version.cuda without the availability check"
+ )
+ else:
+ try:
+ cuda_available = bool(torch.cuda.is_available())
+ except Exception as exc:
+ selection_log.append(f"torch_cuda_preference: torch.cuda.is_available() failed: {exc}")
+ return CudaRuntimePreference(runtime_line = None, selection_log = selection_log)
if not cuda_available:
selection_log.append(
diff --git a/studio/setup.sh b/studio/setup.sh
index 45613f3b4b8..5bcf5f46c20 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -637,10 +637,8 @@ _setup_cvd_hides_nvidia() {
# via CUDA_VISIBLE_DEVICES=""/-1 counts as NOT usable (matches
# install_llama_prebuilt.py has_usable_nvidia), so the AMD probes still run
# and a mixed host steered to its AMD card keeps the ROCm route.
-_setup_has_usable_nvidia_gpu() {
- if _setup_cvd_hides_nvidia; then
- return 1
- fi
+# Present, mask or no mask. The usable probe is this plus the CUDA_VISIBLE_DEVICES check.
+_setup_has_physical_nvidia_gpu() {
_setup_nvsmi=""
if command -v nvidia-smi >/dev/null 2>&1; then
_setup_nvsmi="nvidia-smi"
@@ -660,6 +658,13 @@ _setup_has_usable_nvidia_gpu() {
return 1
}
+_setup_has_usable_nvidia_gpu() {
+ if _setup_cvd_hides_nvidia; then
+ return 1
+ fi
+ _setup_has_physical_nvidia_gpu
+}
+
_cuda_driver_max_version() {
command -v nvidia-smi >/dev/null 2>&1 || return 0
_setup_run_smi nvidia-smi 2>/dev/null \
@@ -2395,6 +2400,7 @@ if ! command -v rocminfo >/dev/null 2>&1 && [ -x /opt/rocm/bin/rocminfo ]; then
fi
_setup_amd_detected=false
_setup_nvidia_usable=false
+_setup_nvidia_physical=false
_setup_gfx_all=""
_setup_gfx=""
_setup_hip_map_missing=0
@@ -2573,6 +2579,9 @@ _setup_supported_gfx_from_name() {
# a usable-NVIDIA host (mirrors _has_rocm_gpu in install_python_stack.py).
# This also keeps a wedged rocminfo/amd-smi from hanging setup before the
# host is classified; the AMD probes themselves run under _setup_run_smi.
+if _setup_has_physical_nvidia_gpu; then
+ _setup_nvidia_physical=true
+fi
if _setup_has_usable_nvidia_gpu; then
_setup_nvidia_usable=true
fi
@@ -3442,13 +3451,12 @@ else
GPU_BACKEND=""
NVCC_PATH=""
- # Gate the CUDA toolkit search on an actually-usable NVIDIA GPU
- # (_setup_nvidia_usable, computed in the GPU summary block above;
- # already false when hidden via CUDA_VISIBLE_DEVICES=""/-1).
- # A CUDA toolkit alone (CPU-only build container, leftover packages)
- # is not proof of a GPU: building with -DGGML_CUDA=ON there yields a
- # binary that fails at runtime, so fall through to the CPU build.
- if [ "$_setup_nvidia_usable" = true ]; then
+ # A CUDA toolkit alone (CPU-only build container, leftover packages) is not
+ # proof of a GPU: -DGGML_CUDA=ON there yields a binary that fails at runtime.
+ # So both callers gate on a real card first.
+ # One search, two callers: the usable-NVIDIA pass below and the masked-NVIDIA
+ # retry after ROCm. Sets NVCC_PATH / GPU_BACKEND, or leaves both untouched.
+ _select_nvcc() {
if command -v nvcc &>/dev/null; then
NVCC_PATH="$(command -v nvcc)"
GPU_BACKEND="cuda"
@@ -3462,6 +3470,10 @@ else
export PATH="$(dirname "$NVCC_PATH"):$PATH"
GPU_BACKEND="cuda"
fi
+ }
+
+ if [ "$_setup_nvidia_usable" = true ]; then
+ _select_nvcc
fi
# Check for ROCm (AMD) only if CUDA was not already selected, and
@@ -3485,6 +3497,16 @@ else
fi
fi
+ # A card hidden by CUDA_VISIBLE_DEVICES is still a card, and the CPU-only binary
+ # built without this is activated over the tree for good. It runs after ROCm on
+ # purpose: on a mixed host the visible AMD GPU is the one the user asked for.
+ # Retrying here rather than gating the pass above on "no AMD detected" also
+ # covers AMD detected with no hipcc anywhere, which sent a GPU host to a CPU
+ # build with nvcc sitting right there.
+ if [ -z "$GPU_BACKEND" ] && [ "$_setup_nvidia_physical" = true ]; then
+ _select_nvcc
+ fi
+
_BUILD_DESC="building"
if [ "$_IS_MACOS_ARM64" = true ]; then
# Metal takes precedence on Apple Silicon (CUDA/ROCm not functional on macOS)
diff --git a/tests/studio/install/test_gpu_detection_followups.py b/tests/studio/install/test_gpu_detection_followups.py
index c98b8c4e74d..2c2ca96bc1a 100644
--- a/tests/studio/install/test_gpu_detection_followups.py
+++ b/tests/studio/install/test_gpu_detection_followups.py
@@ -204,12 +204,18 @@ class TestSetupShHardening:
assert "_setup_has_usable_nvidia_gpu()" in setup_src
def test_helper_uses_proc_fallback(self, setup_src):
- start = setup_src.find("_setup_has_usable_nvidia_gpu()")
+ # The fallback lives in the physical probe, which the usable one delegates to.
+ start = setup_src.find("_setup_has_physical_nvidia_gpu()")
end = setup_src.find("\n}", start)
body = setup_src[start:end]
assert (
"/proc/driver/nvidia/gpus" in body
- ), "_setup_has_usable_nvidia_gpu must fall back to /proc/driver/nvidia/gpus"
+ ), "_setup_has_physical_nvidia_gpu must fall back to /proc/driver/nvidia/gpus"
+ start = setup_src.find("_setup_has_usable_nvidia_gpu() {")
+ end = setup_src.find("\n}", start)
+ assert (
+ "_setup_has_physical_nvidia_gpu" in setup_src[start:end]
+ ), "_setup_has_usable_nvidia_gpu must reach the fallback through the physical probe"
def test_gpu_summary_uses_helper(self, setup_src):
assert "if _setup_has_usable_nvidia_gpu; then" in setup_src
@@ -222,14 +228,24 @@ class TestSetupShHardening:
assert "timeout 10" in body
assert "command -v timeout" in body
- def test_cuda_source_build_gated_on_usable_nvidia(self, setup_src):
- """The nvcc source-build search must be gated on _setup_nvidia_usable."""
- anchor = setup_src.find('NVCC_PATH=""\n')
- assert anchor >= 0
- window = setup_src[anchor : anchor + 700]
+ def test_cuda_source_build_gated_on_a_real_nvidia_gpu(self, setup_src):
+ """The nvcc search runs twice, and neither pass may fire on a toolkit alone.
+
+ First for a usable card, then after ROCm for a masked one. A card hidden by
+ CUDA_VISIBLE_DEVICES is still a card, and a CPU-only binary built here is
+ activated over the tree for good; but on a mixed host the visible AMD GPU gets
+ its turn first. TestSetupShSourceBuildBackendChoice drives the whole sequence.
+ """
+ anchor = setup_src.find("_select_nvcc() {")
+ assert anchor >= 0, "the nvcc search must be one function, not two copies"
+ window = setup_src[anchor : setup_src.find('_BUILD_DESC="building"', anchor)]
+ assert window.count("_select_nvcc\n") == 2, "one pass for usable, one for masked"
+ assert 'if [ "$_setup_nvidia_usable" = true ]; then' in window
assert (
- 'if [ "$_setup_nvidia_usable" = true ]' in window
- ), "CUDA toolkit search must require a usable NVIDIA GPU, not just nvcc"
+ '[ -z "$GPU_BACKEND" ] && [ "$_setup_nvidia_physical" = true ]' in window
+ ), "the masked retry must come after ROCm and require a physically present card"
+ # ROCm gets its turn between the two passes.
+ assert window.index("hipcc") < window.rindex("_select_nvcc")
def test_nvidia_helper_honours_hidden_cvd(self, setup_src):
"""_setup_has_usable_nvidia_gpu must consult the hidden-CVD helper so CVD ""/-1 suppresses NVIDIA before AMD gating."""
@@ -457,12 +473,96 @@ class TestHiddenCvdNotUsable:
out = self._run_sh_helper(
tmp_path,
src,
- ["_setup_run_smi", "_setup_cvd_hides_nvidia", "_setup_has_usable_nvidia_gpu"],
+ [
+ "_setup_run_smi",
+ "_setup_cvd_hides_nvidia",
+ "_setup_has_physical_nvidia_gpu",
+ "_setup_has_usable_nvidia_gpu",
+ ],
cvd,
)
assert out == expected
+class TestSetupShPhysicalNvidiaSurvivesTheMask:
+ """The nvcc source-build search is gated on this probe, so it has to answer true under
+ a mask that makes the usable probe answer false. Gated on usable, a masked host
+ compiled a CPU-only binary and activated it over the tree permanently."""
+
+ @pytest.mark.parametrize("cvd", [None, "", "-1", "0"])
+ def test_the_physical_probe_ignores_every_mask(self, tmp_path, cvd):
+ src = SETUP_SH.read_text(encoding = "utf-8")
+ out = TestHiddenCvdNotUsable()._run_sh_helper(
+ tmp_path,
+ src,
+ ["_setup_run_smi", "_setup_cvd_hides_nvidia", "_setup_has_physical_nvidia_gpu"],
+ cvd,
+ )
+ assert out == "usable"
+
+
+class TestSetupShSourceBuildBackendChoice:
+ """The source-build backend decision, driven as the real sequence rather than one gate.
+
+ Three passes in order: usable NVIDIA takes nvcc, then ROCm, then a masked NVIDIA card
+ retries nvcc. The order is the point. A masked card must not take the build from a
+ visible AMD one, but it must still get it when ROCm cannot actually be built, which is
+ what a CPU source build activated permanently over the tree costs.
+ """
+
+ @staticmethod
+ def _decide(
+ tmp_path,
+ usable,
+ physical,
+ amd,
+ hipcc = "false",
+ nvcc = "true",
+ ):
+ import subprocess as sp
+
+ src = SETUP_SH.read_text(encoding = "utf-8")
+ start = src.index("_select_nvcc() {")
+ end = src.index('_BUILD_DESC="building"', start)
+ body = src[start:end]
+ script = tmp_path / "decide.sh"
+ script.write_text(
+ "#!/bin/bash\n"
+ f"_setup_nvidia_usable={usable}\n"
+ f"_setup_nvidia_physical={physical}\n"
+ f"_setup_amd_detected={amd}\n"
+ 'GPU_BACKEND=""\nNVCC_PATH=""\nROCM_HIPCC=""\n'
+ # Stub the two toolchain lookups; everything else in the block is real.
+ f'command() {{ if [ "$2" = nvcc ]; then {nvcc}; '
+ f'elif [ "$2" = hipcc ]; then {hipcc}; else return 1; fi; }}\n'
+ "ls() { return 1; }\n"
+ f"{body}\n"
+ 'echo "${GPU_BACKEND:-cpu}"\n'
+ )
+ return sp.run(
+ ["bash", str(script)], capture_output = True, text = True, timeout = 30
+ ).stdout.strip()
+
+ @pytest.mark.parametrize(
+ "usable, physical, amd, hipcc, expected",
+ [
+ ("true", "true", "false", "false", "cuda"), # visible NVIDIA, no AMD
+ ("true", "true", "true", "true", "cuda"), # visible NVIDIA wins over AMD
+ ("false", "true", "false", "false", "cuda"), # masked NVIDIA beats a CPU build
+ ("false", "true", "true", "true", "rocm"), # masked NVIDIA yields to a usable AMD
+ ("false", "true", "true", "false", "cuda"), # ... but not when ROCm cannot build
+ ("false", "false", "true", "true", "rocm"), # AMD only
+ ("false", "false", "false", "false", "cpu"), # a toolkit with no GPU is refused
+ ],
+ )
+ def test_the_source_build_backend(self, tmp_path, usable, physical, amd, hipcc, expected):
+ assert self._decide(tmp_path, usable, physical, amd, hipcc) == expected
+
+ def test_a_toolkit_without_any_gpu_never_selects_cuda(self, tmp_path):
+ # The guard the physical gate was written for: nvcc present, no GPU at all.
+ assert self._decide(tmp_path, "false", "false", "false", nvcc = "true") == "cpu"
+
+
class TestRedactInstallOutput:
"""_redact_install_output scrubs index-URL credentials from a captured install log
before it is printed on failure (uv/pip embeds the failing --index-url verbatim)."""
diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.py
index 011a29765bf..372e57ef383 100644
--- a/tests/studio/install/test_selection_logic.py
+++ b/tests/studio/install/test_selection_logic.py
@@ -1,6 +1,7 @@
"""Binary selection logic in install_llama_prebuilt.py; all I/O monkeypatched."""
import importlib.util
+import inspect
import json
import os
import socket
@@ -8,6 +9,7 @@ import subprocess
import sys
import textwrap
import types
+from types import SimpleNamespace
from pathlib import Path
import pytest
@@ -2549,7 +2551,7 @@ class TestDirectUpstreamBlackwellPin:
monkeypatch.setattr(
INSTALL_LLAMA_PREBUILT,
"detect_torch_cuda_runtime_preference",
- lambda host: CudaRuntimePreference(runtime_line = None, selection_log = []),
+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),
)
def test_blackwell_13_1_falls_to_cpu(self, monkeypatch):
@@ -2702,7 +2704,7 @@ class TestLinuxPublishedAttemptsNvidiaCpuGate:
monkeypatch.setattr(
INSTALL_LLAMA_PREBUILT,
"detect_torch_cuda_runtime_preference",
- lambda host: CudaRuntimePreference(runtime_line = None, selection_log = []),
+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),
)
monkeypatch.setattr(
INSTALL_LLAMA_PREBUILT,
@@ -2724,6 +2726,159 @@ class TestLinuxPublishedAttemptsNvidiaCpuGate:
attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(host, self._cpu_only_bundle())
assert [a.install_kind for a in attempts] == ["linux-cpu"]
+ def test_a_masked_nvidia_host_takes_cuda_not_the_cpu_bundle(self, monkeypatch):
+ """A masked host selects CUDA off the physical caps, not the emptied visible ones."""
+ monkeypatch.setattr(
+ INSTALL_LLAMA_PREBUILT,
+ "detect_torch_cuda_runtime_preference",
+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),
+ )
+ monkeypatch.setattr(
+ INSTALL_LLAMA_PREBUILT,
+ "detected_linux_runtime_lines",
+ lambda: (["cuda12"], {"cuda12": ["/usr/local/cuda/lib64"]}),
+ )
+ host = make_host(
+ has_physical_nvidia = True,
+ has_usable_nvidia = False,
+ visible_cuda_devices = "",
+ driver_cuda_version = (12, 8),
+ # As detect_host really leaves a masked host: select_visible_gpu_rows drops
+ # every row, so the VISIBLE caps are empty and only the physical ones survive.
+ compute_caps = [],
+ physical_compute_caps = ["89"],
+ )
+ attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(
+ host, self._cuda_and_cpu_bundle()
+ )
+ assert attempts, "a masked NVIDIA host must still get a CUDA attempt"
+ assert {a.install_kind for a in attempts} == {"linux-cuda"}
+ assert all("cpu" not in a.name for a in attempts)
+
+ def test_a_masked_nvidia_host_with_no_cuda_match_source_builds(self, monkeypatch):
+ # Empty, not the CPU bundle: the caller source-builds with CUDA, as for a visible one.
+ monkeypatch.setattr(
+ INSTALL_LLAMA_PREBUILT,
+ "detect_torch_cuda_runtime_preference",
+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),
+ )
+ monkeypatch.setattr(
+ INSTALL_LLAMA_PREBUILT,
+ "detected_linux_runtime_lines",
+ lambda: (["cuda12"], {"cuda12": ["/usr/local/cuda/lib64"]}),
+ )
+ host = make_host(
+ has_physical_nvidia = True,
+ has_usable_nvidia = False,
+ visible_cuda_devices = "",
+ driver_cuda_version = (12, 8),
+ compute_caps = [],
+ physical_compute_caps = ["89"],
+ )
+ attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(host, self._cpu_only_bundle())
+ assert attempts == []
+
+ def test_a_masked_nvidia_host_is_not_rescued_onto_vulkan_either(self):
+ # An iGPU must not become a second non-CUDA route out of a masked NVIDIA host.
+ host = make_host(
+ has_physical_nvidia = True,
+ has_usable_nvidia = False,
+ visible_cuda_devices = "",
+ has_intel_gpu = True,
+ )
+ attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(
+ host, self._vulkan_and_cpu_bundle()
+ )
+ assert all(a.install_kind not in ("linux-vulkan", "linux-cpu") for a in attempts)
+
+ def test_a_masked_host_below_the_bundle_floor_is_not_handed_it(self, monkeypatch):
+ # Empty compute_caps is the selector's unknown-SM path: it takes a portable
+ # artifact WITHOUT checking min_sm/max_sm, so sm_61 against a floor of sm_70 would
+ # install and then offload nothing once the mask came off.
+ monkeypatch.setattr(
+ INSTALL_LLAMA_PREBUILT,
+ "detect_torch_cuda_runtime_preference",
+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),
+ )
+ monkeypatch.setattr(
+ INSTALL_LLAMA_PREBUILT,
+ "detected_linux_runtime_lines",
+ lambda: (["cuda12"], {"cuda12": ["/usr/local/cuda/lib64"]}),
+ )
+ host = make_host(
+ has_physical_nvidia = True,
+ has_usable_nvidia = False,
+ visible_cuda_devices = "",
+ driver_cuda_version = (12, 8),
+ compute_caps = [],
+ physical_compute_caps = ["61"],
+ )
+ attempts = INSTALL_LLAMA_PREBUILT._linux_published_attempts(
+ host, self._cuda_and_cpu_bundle()
+ )
+ assert all(
+ "portable" not in a.name for a in attempts
+ ), "an sm_61 host must not be handed a bundle whose floor is sm_70"
+ assert all(a.install_kind != "linux-cpu" for a in attempts)
+
+ def test_the_masked_host_keeps_torchs_runtime_preference(self, monkeypatch):
+ """Both of the usual gates answer "no GPU" under the mask.
+
+ has_usable_nvidia is false by definition and torch.cuda.is_available() sees no
+ devices, so the preference was skipped and selection fell back to newest-first:
+ a CUDA 13 bundle for a cu12 venv, which is the stray-runtime mismatch the
+ unmasked path exists to avoid. torch.version.cuda is a build-time constant no
+ mask touches.
+ """
+ fake_torch = SimpleNamespace(
+ version = SimpleNamespace(cuda = "12.8"),
+ cuda = SimpleNamespace(is_available = lambda: False),
+ )
+ monkeypatch.setitem(sys.modules, "torch", fake_torch)
+ host = make_host(
+ has_physical_nvidia = True,
+ has_usable_nvidia = False,
+ visible_cuda_devices = "",
+ )
+
+ skipped = INSTALL_LLAMA_PREBUILT.detect_torch_cuda_runtime_preference(host)
+ assert skipped.runtime_line is None
+
+ preferred = INSTALL_LLAMA_PREBUILT.detect_torch_cuda_runtime_preference(
+ host, gpu_hidden_by_mask = True
+ )
+ assert preferred.runtime_line == "cuda12"
+ assert any("hidden by CUDA_VISIBLE_DEVICES" in line for line in preferred.selection_log)
+
+ def test_the_masked_branch_asks_for_the_masked_preference(self):
+ # The opt-in has to actually be passed, or the branch silently loses the shortcut.
+ source = inspect.getsource(INSTALL_LLAMA_PREBUILT._linux_published_attempts)
+ assert "gpu_hidden_by_mask = True" in source
+
+ def _cuda_and_cpu_bundle(self):
+ """A release carrying both a covering CUDA bundle and the CPU tail."""
+ return make_release(
+ [
+ make_artifact(
+ "app-b8508-linux-x64-cuda12-portable.tar.gz",
+ install_kind = "linux-cuda",
+ runtime_line = "cuda12",
+ coverage_class = "portable",
+ supported_sms = ["70", "75", "80", "86", "89", "90"],
+ min_sm = 70,
+ max_sm = 90,
+ bundle_profile = "cuda12-portable",
+ rank = 30,
+ ),
+ make_cpu_artifact(
+ "app-b8508-linux-x64-cpu.tar.gz",
+ install_kind = "linux-cpu",
+ bundle_profile = None,
+ rank = 1000,
+ ),
+ ]
+ )
+
def _vulkan_and_cpu_bundle(self):
"""What unslothai/llama.cpp publishes: app-<tag>-linux-x64-vulkan.tar.gz and -cpu.tar.gz."""
return make_release(
@@ -2906,7 +3061,7 @@ class TestResolveReleaseAssetChoicePin:
monkeypatch.setattr(
INSTALL_LLAMA_PREBUILT,
"detect_torch_cuda_runtime_preference",
- lambda host: CudaRuntimePreference(runtime_line = None, selection_log = []),
+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),
)
def test_no_cuda_attempt_on_published_path_for_13_1(self, monkeypatch):