Skip to content

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: the CPU image encoder when the ready-made encoder has no code for the card (#331)

Niko1221354212421e4c
diff --git a/setup.py b/setup.py
index d8e112f89..1d0156b26 100644
--- a/setup.py
+++ b/setup.py
@@ -1284,6 +1284,20 @@ def source_hash(parts) -> str:
return h.hexdigest()[:16]
+def prebuilt_vision(meta: dict, gpu: dict, vision: str) -> str:
+ """The image encoder to use with a ready-made engine (`meta`: its BUILD.json). The encoder can cover fewer cards
+ than the engine (0.1.30/0.1.31: no RTX 20 code, #331): such a card gets the CPU encoder - the same program - instead
+ of compiling one, which fails on most Windows PCs (no Visual Studio / CUDA toolkit); --build compiles it."""
+ if vision != "gpu":
+ return vision
+ va = [int(x) for x in meta.get("vision_archs", meta.get("archs", []))]
+ if va and int(gpu["arch"]) not in va and not (meta.get("ptx") and int(gpu["arch"]) > max(va)):
+ warn(f"the ready-made image encoder has no code for your GPU (sm_{gpu['arch']}): it runs on the CPU instead "
+ "(images take longer; setup --build compiles one for your GPU)")
+ return "cpu"
+ return vision
+
+
def build_engine(gpu, vision, yes, llama) -> Path:
"""Compile the engine (and, for images, the encoder) for this GPU; the results go to engine/. A compiled
engine whose source files changed since (a `git pull`) is compiled again: only the changed files, a few minutes."""
@@ -2334,12 +2348,8 @@ def main() -> int:
if vision != "none" and not (eng / VEXE).exists():
warn("the ready-made engine has no image encoder: compiling it")
eng = None
- elif vision == "gpu": # the encoder can cover fewer cards than the engine (RTX 20)
- m = json.loads((eng / "BUILD.json").read_text())
- va = [int(x) for x in m.get("vision_archs", m.get("archs", []))]
- if va and int(gpu["arch"]) not in va and not (m.get("ptx") and int(gpu["arch"]) > max(va)):
- warn(f"the ready-made image encoder has no code for your GPU (sm_{gpu['arch']}): compiling it")
- eng = None
+ else:
+ vision = prebuilt_vision(json.loads((eng / "BUILD.json").read_text()), gpu, vision)
if eng is None:
eng = build_engine_hip(gpu, llama) if hip else build_engine(gpu, vision, a.yes, llama)
meta = json.loads((eng / "BUILD.json").read_text())
diff --git a/tools/test_setup_choices.py b/tools/test_setup_choices.py
new file mode 100644
index 000000000..aa32d2db2
--- /dev/null
+++ b/tools/test_setup_choices.py
@@ -0,0 +1,55 @@
+"""Tests for setup.py's choices that depend on the PC (no GPU, no network, nothing installed): the image encoder of a
+ready-made engine that has no code for the card (#331).
+
+ python -m unittest tools.test_setup_choices
+"""
+from __future__ import annotations
+
+import contextlib
+import io
+import sys
+import unittest
+from pathlib import Path
+
+ROOT = Path(__file__).resolve().parents[1]
+sys.path.insert(0, str(ROOT))
+sys.path.insert(0, str(ROOT / "tools"))
+import setup # noqa: E402
+
+
+def quiet(fn, *args, **kw):
+ out = io.StringIO()
+ with contextlib.redirect_stdout(out):
+ return fn(*args, **kw), out.getvalue()
+
+
+class PrebuiltVision(unittest.TestCase):
+ """#331: the 0.1.30/0.1.31 zip's encoder has no sm_75 code: an RTX 20 card gets the CPU encoder, not a compile."""
+ META = {"version": "0.1.31", "archs": [75, 86, 89, 120], "ptx": True, "vision_archs": [86, 89, 120]}
+
+ def test_a_card_the_encoder_has_no_code_for_gets_the_cpu_encoder(self):
+ got, out = quiet(setup.prebuilt_vision, self.META, {"arch": 75}, "gpu")
+ self.assertEqual(got, "cpu")
+ self.assertIn("runs on the CPU instead", out)
+
+ def test_covered_cards_keep_the_gpu_encoder(self):
+ for arch in (86, 89, 120):
+ self.assertEqual(quiet(setup.prebuilt_vision, self.META, {"arch": arch}, "gpu")[0], "gpu")
+ # a newer card than the newest encoder code: only with PTX in the zip
+ self.assertEqual(quiet(setup.prebuilt_vision, {**self.META, "vision_archs": [86, 89]}, {"arch": 120}, "gpu")[0],
+ "gpu")
+ self.assertEqual(quiet(setup.prebuilt_vision, {**self.META, "vision_archs": [86, 89], "ptx": False},
+ {"arch": 120}, "gpu")[0], "cpu")
+ # 0.1.32's zip: the encoder built with 75-real too
+ self.assertEqual(quiet(setup.prebuilt_vision, {**self.META, "vision_archs": [75, 86, 89, 120]},
+ {"arch": 75}, "gpu")[0], "gpu")
+
+ def test_other_choices_are_left_alone(self):
+ for v in ("cpu", "none"):
+ self.assertEqual(quiet(setup.prebuilt_vision, self.META, {"arch": 75}, v), (v, ""))
+ # an older BUILD.json without vision_archs: the engine's archs
+ self.assertEqual(quiet(setup.prebuilt_vision, {"archs": [75, 86]}, {"arch": 75}, "gpu")[0], "gpu")
+
+
+if __name__ == "__main__":
+ unittest.main()