okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge f-arc-cpumsg92a867be1

main
4.2 KiB82 linesraw
1"""A CPU without AVX-512 (Ryzen 3000-5000, Intel Core 12th-14th generation) and the pack for AVX-512 CPUs: the Terminal says so
2plainly (strata doctor before the start, the launcher after an engine stop), and does not blame the CPU for a pack that is simply
3not the native one."""
4
5import json
6import tempfile
7import unittest
8from pathlib import Path
9from unittest import mock
10
11from strata_cli.launch import runner as R
12from strata_control import doctor
13
14ZEN3 = {"fpu", "avx", "avx2", "fma", "bmi2"}
15ZEN4 = ZEN3 | doctor.AVX512_FULL
16
17
18class CpuPackIssue(unittest.TestCase):
19    def pack(self, d, *names):
20        p = Path(d) / "pack"
21        p.mkdir()
22        for n in names:
23            (p / n).write_text("x", encoding="utf-8")
24        return p
25
26    def cfg(self, p):
27        return {"args": ["--serve", "--pack", str(p), "--native", "x.gguf"], "cwd": str(p.parent)}
28
29    def test_the_avx512_pack_on_an_avx2_cpu_is_named_with_the_next_step(self):
30        with tempfile.TemporaryDirectory() as d, mock.patch.object(doctor, "_cpu_flags", return_value=ZEN3):
31            p = self.pack(d, "index.txt", "experts.bin", "dense.bin")
32            issue = doctor._cpu_pack_issue(self.cfg(p), Path(d) / "run.json")
33            self.assertEqual(issue["code"], "CPU_PACK_NEEDS_AVX512")
34            self.assertIn("no native_experts.txt", issue["message"])
35            self.assertIn("strata setup", issue["message"])
36            # a half-built pack (what stopped an Arc A750 on a Ryzen 5 5600X) reads the same way
37            q = Path(d) / "half"
38            q.mkdir()
39            (q / "index.txt").write_text("x", encoding="utf-8")
40            self.assertEqual(doctor._cpu_pack_issue(self.cfg(q), Path(d) / "run.json")["code"], "CPU_PACK_NEEDS_AVX512")
41
42    def test_nothing_is_said_when_the_cpu_has_avx512_the_pack_is_native_or_it_is_another_engine_pack(self):
43        with tempfile.TemporaryDirectory() as d:
44            p = self.pack(d, "index.txt", "experts.bin")
45            with mock.patch.object(doctor, "_cpu_flags", return_value=ZEN4):
46                self.assertIsNone(doctor._cpu_pack_issue(self.cfg(p), Path(d) / "run.json"))
47            with mock.patch.object(doctor, "_cpu_flags", return_value=ZEN3):
48                (p / "native_experts.txt").write_text("x", encoding="utf-8")
49                self.assertIsNone(doctor._cpu_pack_issue(self.cfg(p), Path(d) / "run.json"))
50                (p / "native_experts.txt").unlink()
51                (p / "ds4.txt").write_text("x", encoding="utf-8")      # a DeepSeek pack: another engine, another kernel
52                self.assertIsNone(doctor._cpu_pack_issue(self.cfg(p), Path(d) / "run.json"))
53                (p / "ds4.txt").unlink()
54                self.assertIsNone(doctor._cpu_pack_issue({"args": ["--serve"]}, Path(d) / "run.json"))
55            with mock.patch.object(doctor, "_cpu_flags", return_value=None):      # flags unreadable: no guess
56                self.assertIsNone(doctor._cpu_pack_issue(self.cfg(p), Path(d) / "run.json"))
57
58    def test_cpu_flags_reads_the_flags_line(self):
59        with tempfile.TemporaryDirectory() as d:
60            f = Path(d) / "cpuinfo"
61            f.write_text("processor\t: 0\nflags\t\t: fpu avx2 avx512f\nbogomips\t: 1\n", encoding="utf-8")
62            with mock.patch.object(doctor.sys, "platform", "linux"):
63                self.assertEqual(doctor._cpu_flags(str(f)), {"fpu", "avx2", "avx512f"})
64                self.assertIsNone(doctor._cpu_flags(str(Path(d) / "missing")))
65
66
67class EngineStopIsExplained(unittest.TestCase):
68    def test_the_engine_refusal_gets_a_plain_next_step(self):
69        with tempfile.TemporaryDirectory() as d:
70            log = Path(d) / "engine.log"
71            log.write_text("strata: this CPU cannot run the expert kernel: missing AVX512F AVX512BW.\n"
72                           "        The pack in --pack is the AVX-512 Q2_0 pack\n", encoding="utf-8")
73            cfg = Path(d) / "run.json"
74            cfg.write_text(json.dumps({"log": str(log)}), encoding="utf-8")
75            text, nxt = R.explain_engine_exit({"state": "failed", "error": "server_exited", "engine_exit_code": 1}, cfg)
76            self.assertIn("cannot run the expert kernel", text)
77            self.assertIn("strata setup", nxt)
78            self.assertIn("AVX2", nxt)
79
80
81if __name__ == "__main__":
82    unittest.main()