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 tests: pin the empty-version torch probe distinction at the repair paths (#8803)

Daniel Hana0c1723bd1f2
diff --git a/tests/studio/install/test_torch_probe_memoization.py b/tests/studio/install/test_torch_probe_memoization.py
index 19b9fa4c942..55aaca15437 100644
--- a/tests/studio/install/test_torch_probe_memoization.py
+++ b/tests/studio/install/test_torch_probe_memoization.py
@@ -325,3 +325,87 @@ class TestConsumersShareTheProbe:
boom = subprocess.TimeoutExpired(cmd = "python", timeout = 90)
with patch.object(stack_mod.subprocess, "run", side_effect = boom):
assert stack_mod._probe_installed_torch_version() is None
+
+
+class TestVersionlessBuildsStillClassify:
+ """An empty version field is not the same as no answer, at the repair paths.
+
+ _probe_torch_runtime draws that line deliberately: "" is a torch whose
+ __version__ is missing, which the pins repair, and None is a probe that told us
+ nothing, which must leave the venv alone. TestProbeParsing pins it at the probe.
+ These pin it where it decides something, since the per-path probes classified
+ from torch.version.cuda / .hip as well as the version string and a consumer
+ gating on the version alone would silently skip the repair.
+ """
+
+ @patch.object(stack_mod, "NO_TORCH", False)
+ @patch.object(stack_mod, "pip_install")
+ def test_cpu_pin_still_replaces_a_versionless_cuda_build(self, mock_pip):
+ out = _probe_result("||12.8") # version "", hip "", cuda "12.8"
+ with patch.object(
+ stack_mod,
+ "_explicit_cpu_torch_index_url",
+ return_value = "https://download.pytorch.org/whl/cpu",
+ ):
+ with patch.object(stack_mod.subprocess, "run", return_value = out):
+ stack_mod._ensure_cpu_torch()
+ assert mock_pip.called, "a CUDA build under an explicit CPU pin must be replaced"
+
+ @patch.object(stack_mod, "NO_TORCH", False)
+ @patch.object(stack_mod, "pip_install")
+ def test_cpu_pin_still_replaces_a_versionless_rocm_build(self, mock_pip):
+ out = _probe_result("|7.1.12345|") # version "", hip set
+ with patch.object(
+ stack_mod,
+ "_explicit_cpu_torch_index_url",
+ return_value = "https://download.pytorch.org/whl/cpu",
+ ):
+ with patch.object(stack_mod.subprocess, "run", return_value = out):
+ stack_mod._ensure_cpu_torch()
+ assert mock_pip.called, "a ROCm build under an explicit CPU pin must be replaced"
+
+ @patch.object(stack_mod, "NO_TORCH", False)
+ @patch.object(stack_mod, "pip_install")
+ def test_cpu_pin_leaves_a_cpu_build_with_no_version_alone(self, mock_pip):
+ # Every field empty is a CPU build with an unreadable version, which the old
+ # probe reported as "cpu": nothing to repair under a CPU pin.
+ with patch.object(
+ stack_mod,
+ "_explicit_cpu_torch_index_url",
+ return_value = "https://download.pytorch.org/whl/cpu",
+ ):
+ with patch.object(stack_mod.subprocess, "run", return_value = _probe_result("||")):
+ stack_mod._ensure_cpu_torch()
+ mock_pip.assert_not_called()
+
+ @patch.object(stack_mod, "NO_TORCH", False)
+ @patch.object(stack_mod, "pip_install")
+ def test_cpu_pin_leaves_the_venv_alone_when_the_probe_said_nothing(self, mock_pip):
+ # Exit 0 with no line of ours: we learned nothing, so we touch nothing. The
+ # other side of the ""/None distinction from the two cases above.
+ with patch.object(
+ stack_mod,
+ "_explicit_cpu_torch_index_url",
+ return_value = "https://download.pytorch.org/whl/cpu",
+ ):
+ with patch.object(
+ stack_mod.subprocess, "run", return_value = _probe_result(raw = "unrelated chatter\n")
+ ):
+ stack_mod._ensure_cpu_torch()
+ mock_pip.assert_not_called()
+
+ @patch.object(stack_mod, "NO_TORCH", False)
+ @patch.object(stack_mod, "IS_MACOS", False)
+ @patch.object(stack_mod, "IS_WINDOWS", False)
+ @patch.object(stack_mod, "pip_install")
+ def test_xpu_pin_still_repairs_a_versionless_build(self, mock_pip):
+ # An unreadable version is not a supported +xpu build, and the pin is there to
+ # force the family, which is what the old "repair" verdict did.
+ with patch.object(
+ stack_mod,
+ "_explicit_xpu_torch_index_url",
+ return_value = "https://download.pytorch.org/whl/xpu",
+ ):
+ with patch.object(stack_mod.subprocess, "run", return_value = _probe_result("||")):
+ stack_mod._ensure_xpu_torch()
+ assert mock_pip.called, "an unidentifiable build under an explicit XPU pin must be repaired"