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
Unsloth Studio / Desktop (AMD, Windows): install the Vulkan llama.cpp prebuilt when device 0 has no HIP bundle (#13680)
Leo Borcherdingccae5d4d31f6
diff --git a/studio/backend/tests/test_install_resolve_prebuilt.py b/studio/backend/tests/test_install_resolve_prebuilt.pyindex a75e4c09978..6e6af601d88 100644--- a/studio/backend/tests/test_install_resolve_prebuilt.py+++ b/studio/backend/tests/test_install_resolve_prebuilt.py@@ -1380,14 +1380,179 @@ def test_a_lone_rdna1_card_takes_the_vulkan_route(monkeypatch):assert routed.has_rocm is False-def test_rdna1_beside_a_hip_capable_card_keeps_the_hip_bundle(monkeypatch):- # Mixed host keeps the HIP prebuilt: Vulkan would enumerate both cards.- for var in ("HIP_VISIBLE_DEVICES", "ROCR_VISIBLE_DEVICES", "CUDA_VISIBLE_DEVICES"):+def _unpinned_amd_env(monkeypatch):+ for var in (+ "HIP_VISIBLE_DEVICES",+ "ROCR_VISIBLE_DEVICES",+ "CUDA_VISIBLE_DEVICES",+ "UNSLOTH_ROCM_GFX_ARCH",+ "UNSLOTH_LLAMA_CPP_BACKEND",+ "UNSLOTH_FORCE_VULKAN",+ ):monkeypatch.delenv(var, raising = False)+ monkeypatch.setattr(ilp, "_rocm_torch_preferred", lambda: False)+++def _route_mixed(+ targets,+ backend = None,+ cpu_mechanism = False,+ repo = FORK,+):+ host = _windows_amd_host(+ rocm_gfx_target = ilp._pick_rocm_gfx_target(" ".join(targets)),+ rocm_gfx_targets = list(targets),+ )+ return ilp.route_backend_request(+ backend = backend,+ published_repo = repo,+ published_release_tag = "pin",+ cpu_mechanism = cpu_mechanism,+ host = host,+ )+++ "targets",+ [+ ("gfx1010", "gfx1034"), # RX 5700 XT at device 0 beside an RX 6500 XT (#13680)+ ("gfx1010", "gfx1100"),+ ("gfx1103", "gfx1010"), # covered iGPU first, uncovered dGPU active (#7776)+ ],+)+def test_an_uncovered_active_card_beside_a_covered_one_takes_vulkan(targets, _unpinned_amd_env):+ # No HIP prebuilt serves the card HIP runs on, so main found no bundle at all.+ route = _route_mixed(targets)+ assert route.host.has_rocm is False+ assert route.host.has_intel_gpu is True+ assert route.persist_llama_backend == "auto"+ assert route.persist_rocm_gfx == "gfx1010"+ assert route.published_repo == FORK+++ "targets",+ [+ ("gfx1034", "gfx1010"), # covered card active: its bundle, the arch gate pins it+ ("gfx1036", "gfx1200"), # shadowing iGPU first: the gfx1200 decides (#7776)+ ("gfx1100", "gfx1034"),+ ],+)+def test_a_covered_active_card_keeps_the_hip_bundle(targets, _unpinned_amd_env):+ route = _route_mixed(targets)+ assert route.host.has_rocm is True+ assert route.persist_llama_backend is None+++def test_upstream_answers_per_repo_for_the_active_card(_unpinned_amd_env):+ # ggml-org's win-hip build has no gfx1034, so the same host moves on upstream only.+ assert _route_mixed(("gfx1034", "gfx1030")).host.has_rocm is True+ assert _route_mixed(("gfx1034", "gfx1030"), repo = UPSTREAM).host.has_rocm is False+++ "mask_env", ["HIP_VISIBLE_DEVICES", "ROCR_VISIBLE_DEVICES", "CUDA_VISIBLE_DEVICES"]+)[email protected]("mask_value", ["0", "1", "", "-1"])+def test_a_masked_mixed_host_never_moves_to_vulkan(+ mask_env, mask_value, _unpinned_amd_env, monkeypatch+):+ # Vulkan honours none of these masks, so it would hand over the card the user hid.+ monkeypatch.setenv(mask_env, mask_value)+ host = _windows_amd_host(rocm_gfx_target = "gfx1010", rocm_gfx_targets = ["gfx1010", "gfx1034"])+ assert ilp._should_auto_vulkan_for_amd_windows(host, FORK) is False+++def test_a_forwarded_arch_behind_a_probed_igpu_is_not_the_probe_pick(_unpinned_amd_env):+ # Probe saw only the gfx1103 iGPU; setup forwarded gfx1010. Re-picking over the augmented+ # list would skip the iGPU and mistake the forward for the probe's own pick.+ host = _windows_amd_host(rocm_gfx_target = "gfx1103", rocm_gfx_targets = ["gfx1103"])+ host = ilp._apply_host_overrides(host, override_rocm_gfx = "gfx1010")+ assert ilp._active_rocm_gfx_target(host) == "gfx1010"+ assert host.rocm_gfx_forwarded is True+ assert ilp._should_auto_vulkan_for_amd_windows(host, FORK) is False+++def test_a_forward_matching_the_probe_pick_still_takes_vulkan(_unpinned_amd_env):+ host = _windows_amd_host(rocm_gfx_target = "gfx1010", rocm_gfx_targets = ["gfx1010", "gfx1034"])+ host = ilp._apply_host_overrides(host, override_rocm_gfx = "gfx1010")+ assert host.rocm_gfx_forwarded is False+ assert ilp._should_auto_vulkan_for_amd_windows(host, FORK) is True+++def test_a_manual_arch_keeps_the_all_cards_rule(_unpinned_amd_env, monkeypatch):+ monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", "gfx1010")host = _windows_amd_host(rocm_gfx_target = "gfx1010", rocm_gfx_targets = ["gfx1010", "gfx1034"])assert ilp._should_auto_vulkan_for_amd_windows(host, FORK) is False+ "backend, cpu_mechanism", [("hip", False), ("rocm", False), ("cpu", False), (None, True)]+)+def test_an_explicit_backend_or_cpu_flag_still_wins_on_the_mixed_host(+ backend, cpu_mechanism, _unpinned_amd_env+):+ route = _route_mixed(("gfx1010", "gfx1034"), backend = backend, cpu_mechanism = cpu_mechanism)+ assert route.host.has_intel_gpu is False+ assert route.persist_llama_backend is None+++def test_a_physical_nvidia_card_keeps_the_mixed_host_off_vulkan(_unpinned_amd_env):+ host = _windows_amd_host(+ rocm_gfx_target = "gfx1010",+ rocm_gfx_targets = ["gfx1010", "gfx1034"],+ has_physical_nvidia = True,+ )+ assert ilp._should_auto_vulkan_for_amd_windows(host, FORK) is False+++def test_rocm_torch_preference_does_not_hide_nvidia_from_the_mixed_host_rule(+ _unpinned_amd_env, monkeypatch+):+ # Following ROCm torch clears has_physical_nvidia; Vulkan would still enumerate the card.+ host = _windows_amd_host(+ nvidia_smi = r"C:\Windows\System32\nvidia-smi.exe",+ compute_caps = ["89"],+ physical_compute_caps = ["89"],+ has_physical_nvidia = True,+ has_usable_nvidia = True,+ rocm_gfx_target = "gfx1010",+ rocm_gfx_targets = ["gfx1010", "gfx1034"],+ )+ monkeypatch.setattr(ilp, "_rocm_torch_preferred", lambda: True)+ route = ilp.route_backend_request(+ backend = None, published_repo = FORK, published_release_tag = "pin", host = host+ )+ assert route.host.has_rocm is True+ assert route.persist_llama_backend is None+++def test_the_mixed_host_rule_is_windows_only(_unpinned_amd_env):+ host = _windows_amd_host(+ system = "Linux",+ is_windows = False,+ is_linux = True,+ rocm_gfx_target = "gfx1010",+ rocm_gfx_targets = ["gfx1010", "gfx1034"],+ )+ assert ilp._should_auto_vulkan_for_amd_windows(host, FORK) is False+++def test_resolve_prebuilt_reports_vulkan_for_the_mixed_host(monkeypatch, capsys, _unpinned_amd_env):+ monkeypatch.setattr(+ ilp,+ "detect_host",+ lambda **_kw: _windows_amd_host(+ rocm_gfx_target = "gfx1010", rocm_gfx_targets = ["gfx1010", "gfx1034"]+ ),+ )+ seen, _out = _run_resolve_capture_host(monkeypatch, capsys)+ assert seen["host"].has_rocm is False+ assert seen["host"].has_intel_gpu is True+ assert seen["repo"] == FORK++@pytest.mark.parametrize("mask_env", ["HIP_VISIBLE_DEVICES", "ROCR_VISIBLE_DEVICES", "CUDA_VISIBLE_DEVICES"])diff --git a/studio/install_llama_prebuilt.py b/studio/install_llama_prebuilt.pyindex d1deae28d5b..4af087fdc13 100644--- a/studio/install_llama_prebuilt.py+++ b/studio/install_llama_prebuilt.py@@ -424,6 +424,8 @@ class HostInfo:has_amd_gpu_without_rocm: bool = Falserocm_gfx_target: str | None = Nonerocm_gfx_targets: list[str] = field(default_factory = list)+ # rocm_gfx_target is a forwarded arch the probe never reported, not the probe's pick.+ rocm_gfx_forwarded: bool = False# (major, minor) from platform.mac_ver(); None off macOS or if unparseable.# Skips a macos prebuilt whose minimum-OS exceeds this host.macos_version: tuple[int, int] | None = None@@ -3345,6 +3347,7 @@ def _apply_host_overrides(# that card regardless of HIP_VISIBLE_DEVICES. An empty probe still yields# [gfx], so the driver-only host the forward exists for keeps auto-Vulkan.rocm_gfx_targets = list(dict.fromkeys([*_physical, gfx])),+ rocm_gfx_forwarded = gfx not in _physical,)# The arch a previous install recorded, replayed by the updater. A remembered# probe result, not an operator override, so it only fills a gap: a host whose@@ -10170,7 +10173,8 @@ def _host_has_windows_hip_prebuilt_gfx(host: HostInfo, published_repo: str | Nondef _should_auto_vulkan_for_amd_windows(host: HostInfo, published_repo: str | None = None) -> bool:- """True when NO AMD GPU on the host reaches the Windows HIP prebuilt floor."""+ """True when no AMD GPU on the host reaches the Windows HIP prebuilt floor, or the+ unmasked probe's own pick has no Windows HIP bundle."""active = _active_rocm_gfx_target(host)if not active:# ROCm confirmed but gfx unknown (--has-rocm only): keep the HIP / fork / source path.@@ -10188,8 +10192,8 @@ def _should_auto_vulkan_for_amd_windows(host: HostInfo, published_repo: str | No# GGML_VK_VISIBLE_DEVICES and Vulkan ordinals), so masking down to a below-floor card# must not route the install to Vulkan: the installed backend would happily enumerate# the HIP-capable card the user deliberately hid, possibly one reserved for another- # workload. Auto-fall back only when no AMD device on the box can be exposed to HIP; an- # explicit vulkan opt-in is unaffected.+ # workload. Under a mask, auto-fall back only when no AMD device on the box can be exposed+ # to HIP; an explicit vulkan opt-in is unaffected.## Under a mask the probe cannot supply that inventory at all (hipinfo sees only visible# devices), so "no AMD GPU here reaches the floor" is unprovable and guessing wrong is@@ -10200,6 +10204,19 @@ def _should_auto_vulkan_for_amd_windows(host: HostInfo, published_repo: str | Noif _hip_visible_device_mask_set():return Falsetargets = list(dict.fromkeys([*_host_rocm_gfx_targets(host), active]))+ # Mixed host whose active card has no HIP bundle (gfx1010 at device 0 beside a gfx1034):+ # no HIP prebuilt can serve the card HIP runs on, while Vulkan runs on both. Only when the+ # active arch is the unmasked probe's own pick: a forwarded arch the probe never reported,+ # or UNSLOTH_ROCM_GFX_ARCH, keeps the all-cards rule. Any NVIDIA trace also keeps it:+ # following ROCm torch clears has_physical_nvidia, but Vulkan would still see that card.+ if (+ not os.environ.get("UNSLOTH_ROCM_GFX_ARCH")+ and not host.rocm_gfx_forwarded+ and not (host.nvidia_smi or host.physical_compute_caps or host.compute_caps)+ and active == _pick_rocm_gfx_target(" ".join(targets))+ and not _gfx_is_windows_hip_supported(active, published_repo)+ ):+ return Truereturn not any(_gfx_is_windows_hip_supported(target, published_repo) for target in targets)@@ -10756,7 +10773,8 @@ def _route_to_vulkan_prebuilt(else:log("Active AMD GPU arch is not supported by the Windows HIP prebuilt "- f"({active}); installing the Vulkan llama.cpp prebuilt instead"+ f"({active}); installing the Vulkan llama.cpp prebuilt, which runs on "+ "every AMD GPU here")host = _vulkan_only_host(host)persist_backend = "auto"diff --git a/tests/studio/install/test_selection_logic.py b/tests/studio/install/test_selection_logic.pyindex c700cbfb39a..375013ac010 100644--- a/tests/studio/install/test_selection_logic.py+++ b/tests/studio/install/test_selection_logic.py@@ -3697,6 +3697,106 @@ class TestPublishedRocmGfxSelection:assert choice.name == "app-b9457-windows-x64-rocm-gfx120X.zip"+class TestWindowsMixedAmdUncoveredActiveCard:+ """RX 5700 XT (gfx1010) at device 0 beside an RX 6500 XT (gfx1034): no Windows HIP bundle+ covers the card HIP runs on, so the install takes the Vulkan bundle, which runs on both,+ instead of failing with "no compatible published prebuilt"."""++ TAG = "b11541-mix-2500203"+ ROCM = f"app-{TAG}-windows-x64-rocm-gfx103X.zip"+ VULKAN = f"app-{TAG}-windows-x64-vulkan.zip"+ CPU = f"app-{TAG}-windows-x64-cpu.zip"++ def _release(self):+ return make_release(+ [+ make_cpu_artifact(+ self.ROCM,+ install_kind = "windows-rocm",+ rank = 1000,+ gfx_target = "gfx103X",+ mapped_targets = ["gfx1030", "gfx1031", "gfx1032", "gfx1034"],+ ),+ make_cpu_artifact(self.VULKAN, install_kind = "windows-vulkan", rank = 1000),+ make_cpu_artifact(self.CPU, install_kind = "windows-cpu", rank = 1000),+ ],+ release_tag = self.TAG,+ upstream_tag = "b9457",+ )++ def _host(self, targets):+ # What detect_host() returned on the reporter's host, device order kept.+ return make_host(+ system = "Windows",+ machine = "AMD64",+ nvidia_smi = None,+ driver_cuda_version = None,+ compute_caps = [],+ has_physical_nvidia = False,+ has_usable_nvidia = False,+ has_rocm = True,+ rocm_gfx_target = targets[0],+ rocm_gfx_targets = list(targets),+ )++ def _resolve(+ self,+ targets,+ backend = None,+ ):+ route = INSTALL_LLAMA_PREBUILT.route_backend_request(+ backend = backend,+ published_repo = INSTALL_LLAMA_PREBUILT.DEFAULT_PUBLISHED_REPO,+ published_release_tag = self.TAG,+ host = self._host(targets),+ )+ return route, resolve_release_asset_choice(+ route.host,+ self.TAG,+ self._release(),+ make_checksums([self.ROCM, self.VULKAN, self.CPU]),+ )++ @pytest.fixture(autouse = True)+ def _unpinned(self, monkeypatch):+ for var in (+ "HIP_VISIBLE_DEVICES",+ "ROCR_VISIBLE_DEVICES",+ "CUDA_VISIBLE_DEVICES",+ "UNSLOTH_ROCM_GFX_ARCH",+ "UNSLOTH_LLAMA_CPP_BACKEND",+ "UNSLOTH_FORCE_VULKAN",+ ):+ monkeypatch.delenv(var, raising = False)+ monkeypatch.setattr(INSTALL_LLAMA_PREBUILT, "_rocm_torch_preferred", lambda: False)+ monkeypatch.setattr(+ INSTALL_LLAMA_PREBUILT,+ "github_release_assets",+ lambda repo, tag: pytest.fail("listed an upstream release"),+ )++ def test_installs_the_vulkan_bundle(self):+ route, result = self._resolve(("gfx1010", "gfx1034"))+ assert [c.name for c in result] == [self.VULKAN, self.CPU]+ assert route.persist_llama_backend == "auto"+ assert route.persist_rocm_gfx == "gfx1010"++ def test_a_covered_active_card_keeps_its_rocm_bundle(self):+ _route, result = self._resolve(("gfx1034", "gfx1010"))+ assert [c.name for c in result] == [self.ROCM]++ def test_an_explicit_hip_backend_is_not_rerouted(self):+ with pytest.raises(PrebuiltFallback, match = "no compatible published prebuilt"):+ self._resolve(("gfx1010", "gfx1034"), backend = "hip")++ @pytest.mark.parametrize("mask_env", ["HIP_VISIBLE_DEVICES", "CUDA_VISIBLE_DEVICES"])+ def test_a_mask_on_the_uncovered_card_is_never_rerouted(self, monkeypatch, mask_env):+ # hipinfo under the mask sees only that card; Vulkan would ignore the mask.+ monkeypatch.setenv(mask_env, "0")+ with pytest.raises(PrebuiltFallback, match = "no compatible published prebuilt"):+ self._resolve(("gfx1010",))++class TestPublishedRocmBundleCoverage:"""Every arch the installer routes torch for needs a llama.cpp bundle or a KNOWN_GAPS entry. The gap is silent:the GPU trains fine and inference drops to a HIP source build, which is correct but much slower to install."""