okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
54ef8615b
main
1"""A fixed expert cache beside a RAM budget on a Strix Halo (STRIX-2Q, 2026-11-01): UD-Q4_K_XL with --expert-cache 10000 or 5000 ended with 2exit code 1 after 41 s and no error text. The estimate (strata_control/uma_pool.py) is the measured one of the 128 GB box; setup lowers its 3own budget with the person's cache and only warns about a budget the person set; a launch whose engine stopped says what to change. 4No GPU, no network. 5 6python -m unittest tools.test_setup_uma_pool 7""" 8from __future__import annotations 9 10import io 11import json 12import sys 13import tempfile 14import unittest 15from contextlib import redirect_stdout 16from pathlib import Path 17from unittest import mock 18 19ROOT = Path (__file__ ).resolve ().parents [1 ] 20sys .path .insert (0 ,str (ROOT )) 21import setup # noqa: E402 22from strata_control import uma_pool # noqa: E402 23 24Q4_GB = setup .MODELS ["UD-Q4_K_XL" ]["arena_gb" ] 25STRIX = {"uma" :True ,"vram_gb" :96.0 ,"dedicated_gb" :64.0 ,"shared_gb" :32.0 ,"name" :"Radeon 8060S" }# the measured box: 92,058 MiB of pool 26 27 28class Estimate (unittest .TestCase ): 29def test_it_reproduces_the_measured_free_memory (self ): 30# MiB free at the first window (STRIX-2Q-RESULTS): cache 14007 + budget 12 -> 8.6 GiB, 12735 + 12 -> 12.4, 12735 + 10 -> 16.5 31pool = 92058 / 1024 32for cache ,budget ,free in ((14007 ,12 ,8.6 ), (12735 ,12 ,12.4 ), (12735 ,10 ,16.5 ), (15283 ,12 ,4.8 )): 33self .assertAlmostEqual (pool - uma_pool .demand_gib (cache ,budget ,Q4_GB ),free ,delta = 0.7 ,msg = (cache ,budget )) 34 35def test_the_failing_settings_are_too_much_and_the_measured_ones_are_not (self ): 36for cache in (10000 ,5000 ): 37self .assertTrue (uma_pool .too_much (cache ,40 ,Q4_GB ,96.0 ),cache )# exit code 1 after 41 s 38for cache ,budget in ((10000 ,12 ), (12735 ,12 ), (14007 ,12 ), (16223 ,12 ), (12735 ,10 )): 39self .assertFalse (uma_pool .too_much (cache ,budget ,Q4_GB ,96.0 ), (cache ,budget ))# started, no fault in 10+ starts each 40 41def test_the_budget_that_fits_is_below_the_failing_one_and_above_the_floor (self ): 42for cache in (10000 ,5000 ,2000 ): 43fit = uma_pool .safe_budget_gib (cache ,Q4_GB ,96.0 ) 44self .assertLess (fit ,40 ) 45self .assertGreaterEqual (fit ,uma_pool .MIN_BUDGET_GIB ) 46self .assertFalse (uma_pool .too_much (cache ,fit ,Q4_GB ,96.0 )) 47self .assertEqual (uma_pool .safe_budget_gib (24000 ,Q4_GB ,40.0 ),uma_pool .MIN_BUDGET_GIB )# a tiny pool: the floor, never zero or negative 48 49def test_only_a_number_beside_a_budget_counts (self ): 50self .assertEqual (uma_pool .fixed_cache_and_budget (["--expert-cache" ,"10000" ,"--resident-budget-gib" ,"40" ]), (10000 ,40.0 )) 51self .assertIsNone (uma_pool .fixed_cache_and_budget (["--expert-cache" ,"auto" ,"--resident-budget-gib" ,"40" ])) 52self .assertIsNone (uma_pool .fixed_cache_and_budget (["--expert-cache" ,"10000" ])) 53self .assertIsNone (uma_pool .stop_advice (["--expert-cache" ,"auto" ,"--resident-budget-gib" ,"40" ])) 54 55 56def run_guard (args ,user = None ,gpu = None ): 57cfg = {"args" :list (args )} 58if user is not None : 59cfg [setup .user_args .USER_KEY ]= user 60out = io .StringIO () 61with redirect_stdout (out ): 62setup .uma_cache_guard (cfg ,"UD-Q4_K_XL" ,gpu or STRIX ) 63return cfg ,out .getvalue () 64 65 66class SetupGuard (unittest .TestCase ): 67def test_a_smaller_cache_lowers_setups_own_budget_and_says_so (self ): 68cfg ,text = run_guard (["--expert-cache" ,"10000" ,"--resident-budget-gib" ,"40" ,"--vision" ]) 69budget = float (cfg ["args" ][cfg ["args" ].index ("--resident-budget-gib" )+ 1 ]) 70self .assertLess (budget ,40 ) 71self .assertEqual (cfg ["args" ][cfg ["args" ].index ("--expert-cache" )+ 1 ],"10000" ,"the person's cache is kept" ) 72self .assertEqual (cfg ["args" ][- 1 ],"--vision" ,"nothing else moves" ) 73self .assertIn ("10000 slots" ,text ) 74self .assertIn ("instead of 40" ,text ) 75self .assertIn ("--expert-cache auto" ,text ) 76 77def test_a_budget_the_person_set_is_only_warned_about (self ): 78cfg ,text = run_guard (["--expert-cache" ,"10000" ,"--resident-budget-gib" ,"40" ],user = ["--expert-cache" ,"10000" ,"--resident-budget-gib" ,"40" ]) 79self .assertEqual (cfg ["args" ][cfg ["args" ].index ("--resident-budget-gib" )+ 1 ],"40" ) 80self .assertIn ("kept as you chose" ,text ) 81 82def test_what_already_fits_and_other_pcs_are_left_alone (self ): 83for args ,gpu in ((["--expert-cache" ,"10000" ,"--resident-budget-gib" ,"12" ],None ), 84 (["--expert-cache" ,"auto" ,"--resident-budget-gib" ,"40" ],None ), 85 (["--expert-cache" ,"10000" ,"--resident-budget-gib" ,"40" ], {** STRIX ,"uma" :False })): 86cfg ,text = run_guard (args ,gpu = gpu ) 87self .assertEqual (cfg ["args" ],args ) 88self .assertEqual (text ,"" ) 89 90 91class LaunchExplains (unittest .TestCase ): 92def config (self ,d ,args ,user = None ): 93log = Path (d )/ "engine.log" 94log .write_text ("prefill: copy stream\n" ,encoding = "utf-8" ) 95cfg = Path (d )/ "run.json" 96cfg .write_text (json .dumps ({"log" :str (log ),"args" :args ,** ({"user_args" :user }if user else {})}),encoding = "utf-8" ) 97return cfg 98 99def test_a_silent_exit_code_1_gets_a_plain_next_step_on_a_shared_memory_pc (self ): 100from strata_cli .launch import runner as R 101result = {"state" :"failed" ,"error" :"server_exited" ,"engine_exit_code" :1 } 102with tempfile .TemporaryDirectory ()as d : 103cfg = self .config (d , ["--expert-cache" ,"4000" ,"--resident-budget-gib" ,"40" ],user = ["--expert-cache" ,"10000" ]) 104text ,nxt = R .explain_engine_exit (result ,cfg ,shared_memory = True ) 105self .assertNotIn ("copy stream" ,text ,"a progress line is not a reason" ) 106self .assertIn ("exit code 1" ,text ) 107self .assertIn ("10000 slots" ,nxt ,"the person's own value is the one that counts" ) 108self .assertIn ("--resident-budget-gib" ,nxt ) 109self .assertIn ("--expert-cache auto" ,nxt ) 110plain_text ,plain_next = R .explain_engine_exit (result ,cfg ,shared_memory = False )# another PC: the old answer 111self .assertIn ("report the log" ,plain_next ) 112auto = self .config (d , ["--expert-cache" ,"auto" ,"--resident-budget-gib" ,"40" ]) 113self .assertIn ("report the log" ,R .explain_engine_exit (result ,auto ,shared_memory = True )[1 ]) 114 115 116if __name__ == "__main__" : 117unittest .main ()