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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Studio: a Windows host whose NVIDIA GPU is hidden by CUDA_VISIBLE_DEVICES selects the CUDA bundle, not windows-cpu (#10976)
Daniel Han3712a3c6344a
diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.pyindex a822fac973c..0be0ff35d67 100644--- a/studio/install_llama_prebuilt.py+++ b/studio/install_llama_prebuilt.py@@ -1018,6 +1018,33 @@ def synthetic_checksums_for_release()+def _masked_nvidia_selection_host(host: HostInfo) -> HostInfo | None:+ """The host to select CUDA for when CUDA_VISIBLE_DEVICES hides its NVIDIA GPU, else None.++ physical-without-usable means the GPU is there and the mask is empty or -1. The mask is+ per process, the install tree is not, so one masked run left a CUDA machine on the CPU+ bundle for good. Select CUDA against the PHYSICAL caps: the visible ones are empty, the+ selector's unknown-SM path, which would let a masked sm_61 host accept an sm_70 floor.+ A CUDA build under the mask runs on CPU exactly as the CPU bundle would.+ None with usable ROCm (that host keeps ROCm) and for an explicit CPU request, which+ never arrives here because _apply_host_overrides has cleared has_physical_nvidia.+ """+ if host.has_usable_nvidia or not host.has_physical_nvidia or host.has_rocm:+ return None+ 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"+ )+ if host.physical_compute_caps and not host.compute_caps:+ log(+ "selecting against the physical compute caps "+ f"{','.join(host.physical_compute_caps)} the mask hid"+ )+ return dataclasses_replace(host, compute_caps = list(host.physical_compute_caps))+ return host++def direct_upstream_release_plan(release: dict[str, Any], host: HostInfo, repo: str, requested_tag: str) -> InstallReleasePlan | None:@@ -1034,18 +1061,23 @@ def direct_upstream_release_plan(assets = release_asset_map(release)attempts: list[AssetChoice] = []if host.is_windows and host.is_x86_64:- if host.has_usable_nvidia:- torch_preference = detect_torch_cuda_runtime_preference(host)+ # A masked NVIDIA host too, as on Linux: it fell through to the CPU attempt.+ masked_host = _masked_nvidia_selection_host(host)+ if host.has_usable_nvidia or masked_host is not None:+ selection_host = masked_host or host+ torch_preference = detect_torch_cuda_runtime_preference(+ selection_host, gpu_hidden_by_mask = masked_host is not None+ )attempts.extend(windows_cuda_attempts(- host,+ selection_host,release_tag,assets,torch_preference.runtime_line,torch_preference.selection_log,))- attempts[:] = _drop_blackwell_incapable_windows_cuda(host, attempts)+ attempts[:] = _drop_blackwell_incapable_windows_cuda(selection_host, attempts)elif host.has_rocm:hip_asset = f"llama-{release_tag}-bin-win-hip-radeon-x64.zip"hip_url = assets.get(hip_asset)@@ -3758,16 +3790,26 @@ def resolve_release_asset_choice(release: PublishedReleaseBundle,checksums: ApprovedReleaseChecksums,) -> list[AssetChoice]:- if host.is_windows and host.is_x86_64 and host.has_usable_nvidia:- torch_preference = detect_torch_cuda_runtime_preference(host)+ # A masked NVIDIA host too, as on Linux: it fell through to windows-cpu below, and+ # with no CUDA match it source-builds with CUDA (PrebuiltFallback), never CPU.+ masked_host = (+ _masked_nvidia_selection_host(host) if host.is_windows and host.is_x86_64 else None+ )+ if host.is_windows and host.is_x86_64 and (host.has_usable_nvidia or masked_host is not None):+ selection_host = masked_host or host+ torch_preference = detect_torch_cuda_runtime_preference(+ selection_host, gpu_hidden_by_mask = masked_host is not None+ )published_attempts = published_windows_cuda_attempts(- host,+ selection_host,release,torch_preference.runtime_line,torch_preference.selection_log,)if published_attempts:- pin_attempts = _drop_blackwell_incapable_windows_cuda(host, published_attempts)+ pin_attempts = _drop_blackwell_incapable_windows_cuda(+ selection_host, published_attempts+ )try:return apply_approved_hashes(pin_attempts, checksums)except PrebuiltFallback as exc:@@ -3777,8 +3819,8 @@ def resolve_release_asset_choice()upstream_assets = github_release_assets(UPSTREAM_REPO, llama_tag)upstream_attempts = _drop_blackwell_incapable_windows_cuda(- host,- resolve_windows_cuda_choices(host, llama_tag, upstream_assets),+ selection_host,+ resolve_windows_cuda_choices(selection_host, llama_tag, upstream_assets),)return apply_approved_hashes(upstream_attempts, checksums)@@ -6486,33 +6528,9 @@ 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"- )+ # Below ROCm and Vulkan on purpose: a masked NVIDIA host with usable ROCm keeps ROCm.+ selection_host = _masked_nvidia_selection_host(host)+ if selection_host is not None:torch_preference = detect_torch_cuda_runtime_preference(selection_host, gpu_hidden_by_mask = True)diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.pyindex 372e57ef383..332c7123908 100644--- a/tests/studio/install/test_selection_logic.py+++ b/tests/studio/install/test_selection_logic.py@@ -3200,6 +3200,147 @@ class TestWindowsAmdWithoutRocmTakesVulkan:assert result[0].install_kind == "windows-cpu"+class TestWindowsMaskedNvidiaTakesCuda:+ """A Windows host whose NVIDIA GPU is hidden by CUDA_VISIBLE_DEVICES selects CUDA, as Linux does.++ The CUDA branch was gated on has_usable_nvidia alone, so physical-without-usable fell+ into the windows-cpu arm and a masked run (the backend pins GPUs for itself and the+ in-app update inherits that env) installed the CPU bundle over a CUDA machine for good.+ """++ TAG = "b10909"++ def _cuda(self):+ return make_artifact(+ f"app-{self.TAG}-windows-x64-cuda12-newer.zip",+ install_kind = "windows-cuda",+ runtime_line = "cuda12",+ coverage_class = "newer",+ supported_sms = ["86", "89", "90", "100", "120"],+ min_sm = 86,+ max_sm = 120,+ bundle_profile = "cuda12-newer",+ rank = 20,+ )++ def _release(self):+ return make_release(+ [+ self._cuda(),+ make_cpu_artifact(+ f"app-{self.TAG}-windows-x64-cpu.zip", install_kind = "windows-cpu"+ ),+ ],+ upstream_tag = self.TAG,+ )++ def _checksums(self):+ return make_checksums(+ [+ f"app-{self.TAG}-windows-x64-cuda12-newer.zip",+ f"app-{self.TAG}-windows-x64-cpu.zip",+ ]+ )++ def _host(self, **overrides):+ # As detect_host leaves a masked host: every visible row is dropped, so only the+ # physical caps survive.+ defaults = dict(+ system = "Windows",+ machine = "AMD64",+ driver_cuda_version = (12, 8),+ visible_cuda_devices = "",+ has_physical_nvidia = True,+ has_usable_nvidia = False,+ compute_caps = [],+ physical_compute_caps = ["89"],+ )+ defaults.update(overrides)+ return make_host(**defaults)++ def _no_torch(self, monkeypatch):+ monkeypatch.setattr(+ INSTALL_LLAMA_PREBUILT,+ "detect_torch_cuda_runtime_preference",+ lambda host, **_: CudaRuntimePreference(runtime_line = None, selection_log = []),+ )++ def test_a_masked_host_takes_cuda_not_the_cpu_bundle(self, monkeypatch):+ mock_windows_runtime(monkeypatch, ["cuda12"])+ self._no_torch(monkeypatch)+ result = resolve_release_asset_choice(+ self._host(), self.TAG, self._release(), self._checksums()+ )+ assert result, "a masked NVIDIA host must still get a CUDA attempt"+ assert {c.install_kind for c in result} == {"windows-cuda"}++ def test_the_masked_host_keeps_torchs_runtime_preference(self, monkeypatch):+ # Both usual gates answer "no GPU" under the mask, so the preference must be read+ # without the availability check or a cu12 venv gets a CUDA 13 bundle.+ mock_windows_runtime(monkeypatch, ["cuda12"])+ seen = {}++ def _preference(host, **kwargs):+ seen.update(kwargs)+ return CudaRuntimePreference(runtime_line = None, selection_log = [])++ monkeypatch.setattr(+ INSTALL_LLAMA_PREBUILT, "detect_torch_cuda_runtime_preference", _preference+ )+ resolve_release_asset_choice(self._host(), self.TAG, self._release(), self._checksums())+ assert seen == {"gpu_hidden_by_mask": True}++ def test_selection_reads_the_physical_caps(self, monkeypatch):+ # sm_61 against a floor of sm_86: no published match, and the (stubbed, empty)+ # upstream release has none either, so it source-builds with CUDA. Never windows-cpu.+ mock_windows_runtime(monkeypatch, ["cuda12"])+ self._no_torch(monkeypatch)+ monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "github_release_assets", lambda repo, tag: {})+ with pytest.raises(PrebuiltFallback):+ resolve_release_asset_choice(+ self._host(physical_compute_caps = ["61"]),+ self.TAG,+ self._release(),+ self._checksums(),+ )++ def test_a_masked_host_with_usable_rocm_keeps_rocm(self, monkeypatch):+ # The windows-rocm arm still owns that host; the CUDA branch is not entered.+ monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "github_release_assets", lambda repo, tag: {})+ monkeypatch.setattr(+ INSTALL_LLAMA_PREBUILT,+ "detect_torch_cuda_runtime_preference",+ lambda host, **_: pytest.fail("CUDA selection ran on a ROCm host"),+ )+ with pytest.raises(PrebuiltFallback):+ resolve_release_asset_choice(+ self._host(has_rocm = True), self.TAG, self._release(), self._checksums()+ )++ def test_an_explicit_cpu_request_still_takes_the_cpu_bundle(self):+ host = INSTALL_LLAMA_PREBUILT._apply_host_overrides(self._host(), force_cpu = True)+ result = resolve_release_asset_choice(host, self.TAG, self._release(), self._checksums())+ assert [c.install_kind for c in result] == ["windows-cpu"]++ def test_the_direct_upstream_plan_agrees(self, monkeypatch):+ # The pinned --published-repo path has its own Windows arm with the same gate.+ mock_windows_runtime(monkeypatch, ["cuda12"])+ self._no_torch(monkeypatch)+ names = [+ f"llama-{self.TAG}-bin-win-cuda-12.4-x64.zip",+ "cudart-llama-bin-win-cuda-12.4-x64.zip",+ f"llama-{self.TAG}-bin-win-cpu-x64.zip",+ ]+ release = {+ "tag_name": self.TAG,+ "assets": [+ {"name": n, "browser_download_url": f"https://example.com/{n}"} for n in names+ ],+ }+ plan = direct_upstream_release_plan(release, self._host(), UPSTREAM_REPO, "latest")+ assert plan.attempts[0].install_kind == "windows-cuda"++class TestPublishedWindowsCudaAppBundleSmSelection:"""app-named windows-cuda bundles carry no minor, so the driver-minor gate is skipped; selection must filter by SM coverage instead of handing every host the lowest-rank "older" bundle."""