Qwen3.8-Flash-Next on any consumer hardware: one-click install for Windows / Linux. Strata inference engine, OpenAI/Anthropic API on localhost, optional image input.
C++
setup: warn on a non-Default GPU compute mode; vision encoder start error names the busy/unavailable cause (#1445)
Niko122137338cadf155
diff --git a/serve/server.py b/serve/server.pyindex d3b31c90a..b1cd3d875 100644--- a/serve/server.py+++ b/serve/server.py@@ -1695,6 +1695,31 @@ def network_path(path: str) -> bool:return p.startswith("\\\\") or p.startswith("\\??\\")+def vision_start_error(line: str, log=None) -> str:+ """The message when the image encoder answered something other than READY. #1445: a card in the Exclusive_Process+ compute mode (or one another process holds) refuses the encoder's CUDA context with "busy or unavailable"; that+ cause is named instead of leaving the user the first line of a traceback. `log` is the encoder's stderr file, whose+ tail is searched too (the CUDA error is printed there)."""+ text = line.strip()+ tail = ""+ try:+ name = getattr(log, "name", None)+ if name:+ with open(name, "rb") as f:+ f.seek(0, 2)+ f.seek(max(0, f.tell() - 16384))+ tail = f.read().decode("utf-8", "replace")+ except (OSError, ValueError):+ pass+ if "busy or unavailable" in (text + tail).lower():+ return ("the vision encoder did not start: the GPU refused a second CUDA context (\"CUDA-capable device(s) "+ "is/are busy or unavailable\"). This is usually the compute mode Exclusive_Process: only one process "+ "may use the card, and the engine already holds it. Check with: nvidia-smi --query-gpu=compute_mode "+ "--format=csv; set it back with: sudo nvidia-smi -c DEFAULT (or run the encoder on another card). "+ "First line from the encoder: " + (text or "(none)"))+ return "the vision encoder did not start: " + text++class Vision:"""The resident image encoder: `strata-vision` (llama.cpp mtmd + the mmproj file) reads `ENC <image> <out>`lines and writes each image's embeddings; results are cached by the image's hash, so a conversation that@@ -1760,7 +1785,7 @@ class Vision:proc.wait(timeout=5)except (OSError, subprocess.TimeoutExpired):pass- raise RuntimeError("the vision encoder did not start: " + line.strip())+ raise RuntimeError(vision_start_error(line, self.spawn[1]))self.stopped = Falsedef _readline(self, timeout: float, what: str) -> str:diff --git a/serve/test_vision_busy.py b/serve/test_vision_busy.pynew file mode 100644index 000000000..899a3445c--- /dev/null+++ b/serve/test_vision_busy.py@@ -0,0 +1,52 @@+"""#1445: a vision encoder that cannot start because the GPU is busy/unavailable (compute mode Exclusive_Process) says+so, with the nvidia-smi check, instead of only the first line of the encoder's output.++ python -m serve.test_vision_busy+"""+import io+import tempfile+import unittest+from pathlib import Path+from types import SimpleNamespace+from unittest import mock++import serve.server as server+++class Busy(unittest.TestCase):+ def test_message_names_the_cause_from_the_line(self):+ m = server.vision_start_error("ggml_backend_cuda_device_get_memory: cudaMemGetInfo failed "+ "(CUDA-capable device(s) is/are busy or unavailable), returning 0/0")+ self.assertIn("Exclusive_Process", m)+ self.assertIn("nvidia-smi", m)+ self.assertIn("did not start", m)++ def test_message_names_the_cause_from_the_log_tail(self):+ with tempfile.NamedTemporaryFile("w+", suffix=".log", delete=False) as f:+ f.write("x" * 40000 + "\ncudaMalloc failed: CUDA-capable device(s) is/are busy or unavailable\n")+ name = f.name+ try:+ with open(name, "a") as log:+ m = server.vision_start_error("load_hparams: something", log)+ self.assertIn("Exclusive_Process", m)+ finally:+ Path(name).unlink()++ def test_other_failures_are_unchanged(self):+ self.assertEqual(server.vision_start_error("ERR no mmproj\n"), "the vision encoder did not start: ERR no mmproj")++ def test_start_raises_it(self):+ line = "cudaMalloc failed: CUDA-capable device(s) is/are busy or unavailable\n"+ proc = SimpleNamespace(stdin=io.StringIO(), stdout=io.StringIO(line), kill=lambda: None, wait=lambda timeout=None: 0,+ poll=lambda: None)+ v = server.Vision.__new__(server.Vision)+ v.spawn = (["strata-vision"], None, None)+ v.dir = Path(tempfile.gettempdir())+ with mock.patch.object(server, "popen", lambda *a, **k: proc), mock.patch.object(server, "contain"):+ with self.assertRaises(RuntimeError) as cm:+ v._start()+ self.assertIn("Exclusive_Process", str(cm.exception))+++if __name__ == "__main__":+ unittest.main()diff --git a/setup.py b/setup.pyindex 319a42b5a..d246c9c21 100644--- a/setup.py+++ b/setup.py@@ -748,6 +748,24 @@ def gpu_drives_display(g) -> bool:return text.strip().lower() == "enabled"+def gpu_compute_mode(index: int) -> str:+ """#1445: nvidia-smi's compute mode for this card ("Default", "Exclusive_Process", "Prohibited", ...); "" when it+ does not say."""+ return out(["nvidia-smi", "-i", str(index), "--query-gpu=compute_mode", "--format=csv,noheader"]).strip()+++def compute_mode_warning(index: int, mode: str) -> str | None:+ """#1445: the warning for a card that is not in the Default compute mode, or None. In Exclusive_Process only one+ process may hold a CUDA context, so the engine, the vision encoder and the tuning run cannot share the card+ ("CUDA-capable device(s) is/are busy or unavailable"); Prohibited allows none. A warning only: it is the+ administrator's setting, Strata never changes it."""+ if not mode or mode.lower() == "default" or mode.lower().startswith("n/a") or mode.lower().startswith("[n/a"):+ return None+ return (f"GPU {index} is in the compute mode {mode}, not Default: a second process cannot use the card while "+ "the first holds it, so the vision encoder or the tuning run can fail with \"CUDA-capable device(s) is/are "+ f"busy or unavailable\". If it does, set it back with: sudo nvidia-smi -i {index} -c DEFAULT")++def pcie_link(index: int) -> dict | None:"""The NVIDIA card's PCIe link: {"gen": the generation card and board both run (an idle card drops to a lowerone, so the current generation is not asked), "gpu_gen", "host_gen", "width", "max_width"}; None when nvidia-smi@@ -5399,6 +5417,12 @@ def main() -> int:if not hip and not multi and a.vram_reserve_mib is None and gpu_drives_display(gpu):say(" tip: this card drives a display. If the PC freezes or the screen goes black once the model is loaded "f"(#779), keep more VRAM free: run setup again with --vram-reserve-mib {DISPLAY_RESERVE_MIB}") # a tip only+ if not hip:+ for gi in ([g for g in multi] if multi else [gpu.get("index", 0)]):+ gi = gi["index"] if isinstance(gi, dict) else gi+ w = compute_mode_warning(gi, gpu_compute_mode(gi))+ if w:+ warn(w) # #1445: a warning only, never a refusalif esp is not None:# the package's profile, with llama.cpp's flags (the engine takes the same ones)args += ["--control-vector-scaled", f"{esp}:1.0", "--control-vector-layer-range", "4", "44",diff --git a/tools/test_setup_compute_mode.py b/tools/test_setup_compute_mode.pynew file mode 100644index 000000000..a64938514--- /dev/null+++ b/tools/test_setup_compute_mode.py@@ -0,0 +1,36 @@+"""#1445: setup warns when nvidia-smi reports a compute mode other than Default (never refuses).++ python -m unittest tools.test_setup_compute_mode+"""+from __future__ import annotations++import sys+import unittest+from pathlib import Path+from unittest import mock++ROOT = Path(__file__).resolve().parents[1]+sys.path.insert(0, str(ROOT))+import setup # noqa: E402+++class Mode(unittest.TestCase):+ def test_default_is_silent(self):+ for m in ("Default", "default", "", "[N/A]", "N/A"):+ self.assertIsNone(setup.compute_mode_warning(0, m), m)++ def test_other_modes_warn(self):+ for m in ("Exclusive_Process", "Prohibited", "Exclusive_Thread"):+ w = setup.compute_mode_warning(2, m)+ self.assertIn(m, w)+ self.assertIn("GPU 2", w)+ self.assertIn("nvidia-smi -i 2 -c DEFAULT", w)++ def test_query(self):+ with mock.patch.object(setup, "out", return_value="Exclusive_Process\n") as o:+ self.assertEqual(setup.gpu_compute_mode(1), "Exclusive_Process")+ self.assertIn("compute_mode", " ".join(o.call_args[0][0]))+++if __name__ == "__main__":+ unittest.main()