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++

tools/vision: portable by default; setup.py and the Dockerfile ask for native (#411 #412 #419)

Akido8d8e1651486b
diff --git a/Dockerfile b/Dockerfile
index a95d47e5d..1c1d1d037 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -65,7 +65,8 @@ RUN python3 -m venv .venv \
&& chmod +x setup.sh docker-entrypoint.sh
# llama.cpp at the pinned commit, then the engine and the image encoder, built
-# exactly the way setup.py builds them. BUILD.json is what setup.py reads to
+# exactly the way setup.py builds them: native code for the CPU that builds the
+# image, so build it on the PC it runs on. BUILD.json is what setup.py reads to
# decide whether an engine is current: source=local with a matching src hash
# means the first start reuses it instead of recompiling.
RUN .venv/bin/python - <<'PYEOF'
@@ -83,7 +84,7 @@ setup.cmake_build(setup.ROOT, setup.ROOT / "build", "strata",
f"-DSTRATA_GGML_DIR={llama}"], None, "build-strata.bat")
if vision != "none":
setup.cmake_build(setup.ROOT / "tools" / "vision", setup.ROOT / "build-vision", "strata-vision",
- [f"-DLLAMA_DIR={llama}", "-DSTRATA_VISION_CUDA=ON",
+ [f"-DLLAMA_DIR={llama}", "-DSTRATA_VISION_CUDA=ON", "-DSTRATA_PORTABLE=OFF",
f"-DCMAKE_CUDA_ARCHITECTURES={arch}", f"-DCMAKE_CUDA_COMPILER={nvcc}"], None, "build-vision.bat")
eng = setup.ROOT / "engine"
diff --git a/setup.py b/setup.py
index 9c219caa4..acd9cf438 100644
--- a/setup.py
+++ b/setup.py
@@ -2357,7 +2357,8 @@ def build_vision_cpu(eng: Path, stamp: Path, meta: dict, llama, vsrc) -> Path:
if not ((eng / VEXE).exists() and meta.get("vision_src") == vsrc):
say(" Compiling the image encoder (for the CPU) ...")
cmake_build(ROOT / "tools" / "vision", ROOT / "build-vision", "strata-vision",
- [f"-DLLAMA_DIR={llama}", "-DSTRATA_VISION_CUDA=OFF"], find_vcvars() if WIN else None,
+ [f"-DLLAMA_DIR={llama}", "-DSTRATA_VISION_CUDA=OFF", "-DSTRATA_PORTABLE=OFF"],
+ find_vcvars() if WIN else None,
"build-vision-cpu.bat" if WIN else "") # #881: MSVC's environment on Windows, as the CUDA path has
shutil.copy2(ROOT / "build-vision" / "bin" / VEXE, eng / VEXE)
stamp.write_text(json.dumps({**meta, "vision": "cpu", "vision_src": vsrc}, indent=1))
@@ -2822,7 +2823,8 @@ def build_engine(gpu, vision, yes, llama, toolkit=None) -> Path:
shutil.copy2(bdir / EXE, eng / EXE)
if not vision_ok:
say(" Compiling the image encoder" + (" with CUDA (10-20 minutes, once) ..." if vision == "gpu" else " ..."))
- defs = [f"-DLLAMA_DIR={llama}", f"-DSTRATA_VISION_CUDA={'ON' if vision == 'gpu' else 'OFF'}"]
+ defs = [f"-DLLAMA_DIR={llama}", f"-DSTRATA_VISION_CUDA={'ON' if vision == 'gpu' else 'OFF'}",
+ "-DSTRATA_PORTABLE=OFF"] # built here, for this PC: native, like the engine
if vision == "gpu":
defs += [f"-DCMAKE_CUDA_ARCHITECTURES={cuda_archs}", f"-DCMAKE_CUDA_COMPILER={nvcc}"]
cmake_build(ROOT / "tools" / "vision", vdir, "strata-vision", defs, vcvars,
diff --git a/tools/test_setup_choices.py b/tools/test_setup_choices.py
index f7e16f4e0..d5ec830d7 100644
--- a/tools/test_setup_choices.py
+++ b/tools/test_setup_choices.py
@@ -306,6 +306,7 @@ class HipVision(unittest.TestCase):
built, meta, have = self.build({}, "cpu")
self.assertEqual([t for t, _ in built], ["strata-vision"])
self.assertIn("-DSTRATA_VISION_CUDA=OFF", built[0][1])
+ self.assertIn("-DSTRATA_PORTABLE=OFF", built[0][1]) # built for this PC (#411: portable is the default)
self.assertEqual((meta["vision"], meta["vision_src"], have), ("cpu", "V", True))
built, meta, _ = self.build({"vision": "cpu", "vision_src": "V"}, "cpu", vexe=True)
self.assertEqual(built, []) # built and unchanged: nothing to do
@@ -471,5 +472,33 @@ class DesktopReserveTip(unittest.TestCase):
self.assertIn("desktop", tip)
+class CudaVision(unittest.TestCase):
+ """#411: the image encoder setup compiles beside the CUDA engine is built for this PC, not portable."""
+
+ def test_the_encoder_is_built_native(self):
+ for vision in ("gpu", "cpu"):
+ with self.subTest(vision), tempfile.TemporaryDirectory() as d:
+ root = Path(d)
+ eng = root / "engine"
+ eng.mkdir()
+ (eng / setup.EXE).write_bytes(b"engine") # the engine is built: only the encoder
+ (eng / "BUILD.json").write_text(json.dumps({"source": "local", "archs": [86], "src": "S"}))
+ built = []
+
+ def cmake_build(src_dir, bdir, target, defs, vcvars, bat):
+ built.append((target, defs))
+ (bdir / "bin").mkdir(parents=True)
+ (bdir / "bin" / setup.VEXE).write_bytes(b"vision")
+
+ with mock.patch.object(setup, "ROOT", root), mock.patch.object(setup, "cmake_build", cmake_build), \
+ mock.patch.object(setup, "source_hash", lambda p: "V" if p == setup.VISION_SOURCES else "S"), \
+ mock.patch.object(setup, "install_build_tools", lambda gpu, yes: (str(root / "nvcc"), None)), \
+ mock.patch.object(setup, "source_version", lambda: "test"):
+ quiet(setup.build_engine, {"arch": "86"}, vision, True, "llama")
+ self.assertEqual([t for t, _ in built], ["strata-vision"])
+ self.assertIn("-DSTRATA_PORTABLE=OFF", built[0][1])
+ self.assertIn(f"-DSTRATA_VISION_CUDA={'ON' if vision == 'gpu' else 'OFF'}", built[0][1])
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/vision/CMakeLists.txt b/tools/vision/CMakeLists.txt
index 836820373..d6518c71d 100644
--- a/tools/vision/CMakeLists.txt
+++ b/tools/vision/CMakeLists.txt
@@ -2,14 +2,19 @@
# the vision encoder is chosen). Uses llama.cpp's mtmd library at the same pinned commit as the engine's ggml.
#
# cmake -S tools/vision -B build-vision -G Ninja -DCMAKE_BUILD_TYPE=Release -DLLAMA_DIR=third_party/llama.cpp
-# [-DSTRATA_VISION_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native]
+# [-DSTRATA_VISION_CUDA=ON -DCMAKE_CUDA_ARCHITECTURES=native] [-DSTRATA_PORTABLE=OFF]
# cmake --build build-vision --target strata-vision
+#
+# Portable (AVX2 baseline) is the default, so an encoder built without extra flags runs on any AVX2 PC: the 0.1.32
+# release's encoder was built native on an AVX-512 machine and stopped with an illegal instruction elsewhere
+# (#411 #412 #419). setup.py, which builds for the PC it runs on, passes -DSTRATA_PORTABLE=OFF. The option is
+# kept in CMakeCache.txt, so a build folder configured before this default still needs the flag (or a fresh folder).
cmake_minimum_required(VERSION 3.21)
project(strata_vision C CXX)
set(LLAMA_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/llama.cpp" CACHE PATH "llama.cpp checkout")
option(STRATA_VISION_CUDA "run the vision encoder on the GPU (builds ggml-cuda)" OFF)
-option(STRATA_PORTABLE "build for other PCs: AVX2 baseline, static MSVC runtime" OFF)
+option(STRATA_PORTABLE "build for other PCs: AVX2 baseline, static MSVC runtime" ON)
if(STRATA_PORTABLE AND MSVC)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded")
endif()
@@ -30,8 +35,20 @@ if(STRATA_PORTABLE)
foreach(_f GGML_AVX GGML_AVX2 GGML_FMA GGML_F16C GGML_BMI2)
set(${_f} ON CACHE BOOL "" FORCE)
endforeach()
+ # nothing above AVX2 either, even when a -D asks for it (a 9900K or a Zen 3 has neither AVX-512 nor AVX-VNNI)
+ foreach(_f GGML_AVX512 GGML_AVX512_VBMI GGML_AVX512_VNNI GGML_AVX512_BF16 GGML_AVX_VNNI
+ GGML_AMX_TILE GGML_AMX_INT8 GGML_AMX_BF16)
+ set(${_f} OFF CACHE BOOL "" FORCE)
+ endforeach()
+ message(STATUS "strata-vision: portable build (AVX2 baseline, runs on other PCs)")
else()
+ # this PC's instruction set; a build folder that was portable before gets a fresh native build's settings back
set(GGML_NATIVE ON CACHE BOOL "" FORCE)
+ set(GGML_OPENMP ON CACHE BOOL "" FORCE)
+ foreach(_f GGML_AVX GGML_AVX2 GGML_FMA GGML_F16C GGML_BMI2)
+ set(${_f} OFF CACHE BOOL "" FORCE)
+ endforeach()
+ message(STATUS "strata-vision: native build for this CPU (STRATA_PORTABLE=OFF) - not for other PCs")
endif()
set(GGML_BACKEND_DL OFF CACHE BOOL "" FORCE)
set(GGML_CUDA ${STRATA_VISION_CUDA} CACHE BOOL "" FORCE)