From 9d64b93a0f0f3d4343fdfba4976eb3b559ddb774 Mon Sep 17 00:00:00 2001 From: Niko1221 Date: Fri, 9 Oct 2026 03:13:09 +0200 Subject: [PATCH] docker: warn, not stop, on a host CPU without AVX2 (#1584) --- docker-entrypoint.sh | 10 ++++++++++ tools/test_docker_entrypoint.py | 20 ++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 2950a257..9df74204 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -6,6 +6,16 @@ set -e cd /opt/strata || exit 1 +# #1584: the engine in the image is built with AVX2 CPU kernels. A host CPU without AVX2 (Sandy / Ivy Bridge Xeons, +# Bulldozer) runs it into an illegal instruction. A warning, not a stop: recommend, never force (the flags file +# can be wrong in a VM, and a build made on that host may be fine). STRATA_CPUINFO is for the test. +cpuinfo="${STRATA_CPUINFO:-/proc/cpuinfo}" +if [ -r "$cpuinfo" ] && grep -q '^flags' "$cpuinfo" && ! grep -m1 '^flags' "$cpuinfo" | grep -qw avx2; then + echo "WARNING: this host CPU has no AVX2. The engine in this image is built for CPUs with AVX2, so it may stop" >&2 + echo " with 'illegal instruction' (exit 132). Build the image on this machine (docker build), which compiles the" >&2 + echo " engine for the CPU it runs on, and see docs/INSTALL.md (Older CPUs, experimental) for the older-CPU build." >&2 +fi + STRATA_DATA="${STRATA_DATA:-/data}" FAMILY="${FAMILY:-qwen}" MODEL="${MODEL:-IQ2_XS}" diff --git a/tools/test_docker_entrypoint.py b/tools/test_docker_entrypoint.py index 4953265b..824699ed 100644 --- a/tools/test_docker_entrypoint.py +++ b/tools/test_docker_entrypoint.py @@ -95,6 +95,26 @@ class Entrypoint(unittest.TestCase): self.assertIn("by-model", out) self.assertIn(f"Config: {self.data}/config/strata-iq3_s.json", out) + def warning_for(self, flags): + info = self.tmp / "cpuinfo" + info.write_text(f"processor : 0 +flags : {flags} +") + (self.data / "config" / "strata-iq3_s.json").write_text('{"args": ["x"]} +') + env = dict(os.environ, STRATA_DATA=str(self.data), MODEL="IQ3_S", REINSTALL="0", STRATA_CPUINFO=str(info)) + r = subprocess.run([SH, str(self.script)], env=env, capture_output=True, text=True, timeout=60) + self.assertEqual(r.returncode, 0, r.stderr) # a warning, never a stop (#1584) + return r.stderr + + def test_a_cpu_without_avx2_is_warned_not_stopped(self): + err = self.warning_for("fpu sse4_2 avx aes") + self.assertIn("no AVX2", err) + self.assertIn("docker build", err) + + def test_a_cpu_with_avx2_gets_no_warning(self): + self.assertEqual(self.warning_for("fpu sse4_2 avx avx2 fma"), "") + if __name__ == "__main__": unittest.main()