okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
92a867be1
main
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 ): 19def pack (self ,d ,* names ): 20p = Path (d )/ "pack" 21p .mkdir () 22for n in names : 23 (p / n ).write_text ("x" ,encoding = "utf-8" ) 24return p 25 26def cfg (self ,p ): 27return {"args" : ["--serve" ,"--pack" ,str (p ),"--native" ,"x.gguf" ],"cwd" :str (p .parent )} 28 29def test_the_avx512_pack_on_an_avx2_cpu_is_named_with_the_next_step (self ): 30with tempfile .TemporaryDirectory ()as d ,mock .patch .object (doctor ,"_cpu_flags" ,return_value = ZEN3 ): 31p = self .pack (d ,"index.txt" ,"experts.bin" ,"dense.bin" ) 32issue = doctor ._cpu_pack_issue (self .cfg (p ),Path (d )/ "run.json" ) 33self .assertEqual (issue ["code" ],"CPU_PACK_NEEDS_AVX512" ) 34self .assertIn ("no native_experts.txt" ,issue ["message" ]) 35self .assertIn ("strata setup" ,issue ["message" ]) 36# a half-built pack (what stopped an Arc A750 on a Ryzen 5 5600X) reads the same way 37q = Path (d )/ "half" 38q .mkdir () 39 (q / "index.txt" ).write_text ("x" ,encoding = "utf-8" ) 40self .assertEqual (doctor ._cpu_pack_issue (self .cfg (q ),Path (d )/ "run.json" )["code" ],"CPU_PACK_NEEDS_AVX512" ) 41 42def test_nothing_is_said_when_the_cpu_has_avx512_the_pack_is_native_or_it_is_another_engine_pack (self ): 43with tempfile .TemporaryDirectory ()as d : 44p = self .pack (d ,"index.txt" ,"experts.bin" ) 45with mock .patch .object (doctor ,"_cpu_flags" ,return_value = ZEN4 ): 46self .assertIsNone (doctor ._cpu_pack_issue (self .cfg (p ),Path (d )/ "run.json" )) 47with mock .patch .object (doctor ,"_cpu_flags" ,return_value = ZEN3 ): 48 (p / "native_experts.txt" ).write_text ("x" ,encoding = "utf-8" ) 49self .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 52self .assertIsNone (doctor ._cpu_pack_issue (self .cfg (p ),Path (d )/ "run.json" )) 53 (p / "ds4.txt" ).unlink () 54self .assertIsNone (doctor ._cpu_pack_issue ({"args" : ["--serve" ]},Path (d )/ "run.json" )) 55with mock .patch .object (doctor ,"_cpu_flags" ,return_value = None ):# flags unreadable: no guess 56self .assertIsNone (doctor ._cpu_pack_issue (self .cfg (p ),Path (d )/ "run.json" )) 57 58def test_cpu_flags_reads_the_flags_line (self ): 59with tempfile .TemporaryDirectory ()as d : 60f = Path (d )/ "cpuinfo" 61f .write_text ("processor\t: 0\nflags\t\t: fpu avx2 avx512f\nbogomips\t: 1\n" ,encoding = "utf-8" ) 62with mock .patch .object (doctor .sys ,"platform" ,"linux" ): 63self .assertEqual (doctor ._cpu_flags (str (f )), {"fpu" ,"avx2" ,"avx512f" }) 64self .assertIsNone (doctor ._cpu_flags (str (Path (d )/ "missing" ))) 65 66 67class EngineStopIsExplained (unittest .TestCase ): 68def test_the_engine_refusal_gets_a_plain_next_step (self ): 69with tempfile .TemporaryDirectory ()as d : 70log = Path (d )/ "engine.log" 71log .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" ) 73cfg = Path (d )/ "run.json" 74cfg .write_text (json .dumps ({"log" :str (log )}),encoding = "utf-8" ) 75text ,nxt = R .explain_engine_exit ({"state" :"failed" ,"error" :"server_exited" ,"engine_exit_code" :1 },cfg ) 76self .assertIn ("cannot run the expert kernel" ,text ) 77self .assertIn ("strata setup" ,nxt ) 78self .assertIn ("AVX2" ,nxt ) 79 80 81if __name__ == "__main__" : 82unittest .main ()