okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
538acd098
main
1"""#3895: STRATA_SH_STREAM=1 (the shared expert on its own stream) together with --kv-resident failed the engine on its first request on one 2Windows RX 6900 XT ("verify: unspecified launch failure"). AMD runs without the fork by default. Calibrate does not measure the combination, the 3tuner never picks it, and a person who set it by hand gets one warning line at the start. Nothing is refused. 4""" 5from __future__import annotations 6 7import sys 8import unittest 9from pathlib import Path 10from unittest import mock 11 12ROOT = Path (__file__ ).resolve ().parents [2 ] 13sys .path .insert (0 ,str (ROOT / "tools" )) 14sys .path .insert (0 ,str (ROOT )) 15import calibrate as CAL # noqa: E402 16from serve import server # noqa: E402 17from strata_control import tune_knobs # noqa: E402 18from tools .test_calibrate import BASE ,FakeEngine # noqa: E402 19 20 21class CalibrateSkipsTheCombination (unittest .TestCase ): 22def measure (self ,platform ,args ): 23starts ,envs ,said = [], [], [] 24 25def start (a ,env = None ): 26envs .append (dict (env or {})) 27return FakeEngine (a ,lambda f ,p ,w :50.0 ,6 ,starts ) 28 29with mock .patch .object (CAL .sys ,"platform" ,platform ): 30res = CAL .measure (args , [[1 ,2 ,3 ]]* 3 ,start ,say = said .append ,hip = True ) 31return res ,envs ,said 32 33def test_windows_with_kv_streaming_does_not_measure_the_fork (self ): 34args = CAL .with_arg (BASE ,"--kv-resident" ,"32768" ) 35res ,envs ,said = self .measure ("win32" ,args ) 36self .assertEqual (res ["env" ], {}) 37self .assertNotIn ("sh_stream" ,res ["report" ]) 38self .assertEqual (res ["report" ]["sh_stream_skipped" ],"windows with --kv-resident" ) 39self .assertTrue (all (CAL .SH_STREAM not in e for e in envs )) 40self .assertTrue (any ("#3895" in line and "STRATA_SH_STREAM=1" in line for line in said )) 41 42def test_linux_with_kv_streaming_and_windows_without_it_still_measure_it (self ): 43for platform ,args in (("linux" ,CAL .with_arg (BASE ,"--kv-resident" ,"32768" )), ("win32" ,BASE )): 44with self .subTest (platform = platform ): 45res ,envs ,_ = self .measure (platform ,args ) 46self .assertEqual (set (res ["report" ]["sh_stream" ]), {"0" ,"1" }) 47self .assertNotIn ("sh_stream_skipped" ,res ["report" ]) 48 49 50class TunerNeverPicksIt (unittest .TestCase ): 51def ctx (self ,platform ,backend = "hip" ,args = ("--kv-resident" ,"32768" )): 52context = tune_knobs .Context (backend = backend ,arch = "gfx1030" ,gpu_count = 1 ,vram_mib = 16384 ,ram_gib = 64 ,model_gib = 40.0 ,base_args = list (args )) 53return context ,mock .patch .object (tune_knobs .sys ,"platform" ,platform ) 54 55def test_windows_amd_with_kv_streaming (self ): 56ctx ,patch = self .ctx ("win32" ) 57with patch : 58problems = tune_knobs .check_setting ({}, {"STRATA_SH_STREAM" :"1" },ctx ) 59self .assertEqual (len (problems ),1 ) 60self .assertIn ("#3895" ,problems [0 ]) 61 62def test_other_cases_stay_allowed (self ): 63for platform ,backend ,args in (("linux" ,"hip" , ("--kv-resident" ,"32768" )), ("win32" ,"hip" , ()), ("win32" ,"cuda" , ("--kv-resident" ,"32768" ))): 64ctx ,patch = self .ctx (platform ,backend ,args ) 65with patch ,self .subTest (platform = platform ,backend = backend ,args = args ): 66self .assertEqual (tune_knobs .check_setting ({}, {"STRATA_SH_STREAM" :"1" },ctx ), []) 67 68 69class StartWarning (unittest .TestCase ): 70CFG = {"backend" :"hip" ,"args" : ["--kv" ,"int8" ,"--kv-resident" ,"32768" ]} 71 72def test_a_hand_set_fork_with_kv_streaming_on_windows_warns_once_per_start (self ): 73with mock .patch .object (server .os ,"name" ,"nt" ): 74note = server .sh_stream_warning ({"STRATA_SH_STREAM" :"1" },self .CFG ) 75self .assertIn ("#3895" ,note ) 76self .assertIn ("WARNING" ,note ) 77self .assertIn ("take STRATA_SH_STREAM out" ,note ) 78 79def test_no_warning_without_the_combination (self ): 80with mock .patch .object (server .os ,"name" ,"nt" ): 81self .assertIsNone (server .sh_stream_warning ({},self .CFG )) 82self .assertIsNone (server .sh_stream_warning ({"STRATA_SH_STREAM" :"0" },self .CFG )) 83self .assertIsNone (server .sh_stream_warning ({"STRATA_SH_STREAM" :"1" }, {"backend" :"hip" ,"args" : ["--kv" ,"int8" ]})) 84with mock .patch .object (server .os ,"name" ,"posix" ): 85self .assertIsNone (server .sh_stream_warning ({"STRATA_SH_STREAM" :"1" },self .CFG )) 86 87def test_child_env_prints_it_and_still_passes_the_variable (self ): 88cfg = {** self .CFG ,"env" : {"STRATA_SH_STREAM" :"1" }} 89with mock .patch .object (server .os ,"name" ,"nt" ),mock .patch ("builtins.print" )as shown , \ 90mock .patch .object (server ,"hip_env_guard" ,return_value = []),mock .patch .object (server ,"hip_auto_devices" ,return_value = None ): 91env = server .child_env (cfg ) 92self .assertEqual (env ["STRATA_SH_STREAM" ],"1" )# nothing is taken away 93self .assertTrue (any ("#3895" in str (call .args [0 ])for call in shown .call_args_list if call .args )) 94 95 96if __name__ == "__main__" : 97unittest .main ()