okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
1d8d830af
main
1"""0.1.39b (#578): setup recommends --remote-expert-opt for a config on two or more GPUs, never for one, and keeps it 2out when asked (setup's --no-remote-expert-opt, or "remote_expert_opt": false in the config). 3 4python -m unittest tools.test_setup_remote_opt 5""" 6from __future__import annotations 7 8import sys 9import unittest 10from pathlib import Path 11from unittest import mock 12 13ROOT = Path (__file__ ).resolve ().parents [1 ] 14sys .path .insert (0 ,str (ROOT )) 15sys .path .insert (0 ,str (ROOT / "tools" )) 16import setup # noqa: E402 17from test_setup_golden import PROFILES ,install # noqa: E402 18 19FLAG = "--remote-expert-opt" 20HELPER = ["--expert-cache-device1" ,"auto" ] 21 22 23class Rule (unittest .TestCase ): 24def setUp (self ): 25p = mock .patch .object (setup ,"ok" ,lambda * a :None ) 26p .start () 27self .addCleanup (p .stop ) 28 29def test_two_gpus_get_it_once (self ): 30cfg = {"args" : ["--spec" ,"4" ]+ HELPER ,"gpu" : [0 ,1 ]} 31setup .recommend_remote_expert_opt (cfg ) 32setup .recommend_remote_expert_opt (cfg ) 33self .assertEqual (cfg ["args" ], ["--spec" ,"4" ]+ HELPER + [FLAG ]) 34 35def test_no_helper_cache_no_flag (self ): 36"""#1447: on a plain layer split there is no helper cache for the flag to act on, so setup does not write it.""" 37cfg = {"args" : ["--spec" ,"4" ],"gpu" : [0 ,1 ]} 38setup .recommend_remote_expert_opt (cfg ) 39self .assertEqual (cfg ["args" ], ["--spec" ,"4" ]) 40kept = {"args" : [FLAG ],"gpu" : [0 ,1 ]}# a flag already there is the user's: left alone 41setup .recommend_remote_expert_opt (kept ) 42self .assertEqual (kept ["args" ], [FLAG ]) 43eq = {"args" : ["--expert-cache-device2=auto" ],"gpu" : [0 ,1 ,2 ]} 44setup .recommend_remote_expert_opt (eq ) 45self .assertIn (FLAG ,eq ["args" ]) 46 47def test_one_gpu_is_untouched (self ): 48for gpu in (None ,0 , [0 ]): 49cfg = {"args" : ["--spec" ,"4" ]}if gpu is None else {"args" : ["--spec" ,"4" ],"gpu" :gpu } 50setup .recommend_remote_expert_opt (cfg ) 51self .assertEqual (cfg ["args" ], ["--spec" ,"4" ],gpu ) 52 53def test_overrides (self ): 54cfg = {"args" : ["--spec" ,"4" ,FLAG ],"gpu" : [0 ,1 ]} 55setup .recommend_remote_expert_opt (cfg ,off = True ) 56self .assertEqual (cfg ["args" ], ["--spec" ,"4" ]) 57cfg = {"args" : ["--spec" ,"4" ]+ HELPER ,"gpu" : [0 ,1 ,2 ],"remote_expert_opt" :False } 58setup .recommend_remote_expert_opt (cfg ) 59self .assertEqual (cfg ["args" ], ["--spec" ,"4" ]+ HELPER ) 60 61def test_pipeline_windows_wins (self ): 62"""#1352: the two exclude each other (the engine drops the pipeline beside the helper caches), so setup 63does not add the flag to a config that asks for the pipeline, and says so when both are there.""" 64cfg = {"args" : ["--spec" ,"4" ,"--pipeline-windows" ,"2" ]+ HELPER ,"gpu" : [0 ,1 ]} 65setup .recommend_remote_expert_opt (cfg ) 66self .assertEqual (cfg ["args" ], ["--spec" ,"4" ,"--pipeline-windows" ,"2" ]+ HELPER ) 67both = {"args" : [FLAG ,"--pipeline-windows" ,"2" ],"gpu" : [0 ,1 ]} 68with mock .patch .object (setup ,"warn" )as w : 69setup .recommend_remote_expert_opt (both ) 70self .assertEqual (both ["args" ], [FLAG ,"--pipeline-windows" ,"2" ])# a recommendation, never forced 71self .assertEqual (w .call_count ,1 ) 72off = {"args" : ["--pipeline-windows" ,"0" ]+ HELPER ,"gpu" : [0 ,1 ]}# 0: no pipeline asked for 73setup .recommend_remote_expert_opt (off ) 74self .assertIn (FLAG ,off ["args" ]) 75 76def test_the_users_key_is_kept_on_a_rerun (self ): 77self .assertNotIn ("remote_expert_opt" ,setup .SETUP_KEYS )# #629: carried over, so the opt-out survives 78 79 80class Install (unittest .TestCase ): 81def test_install_on_two_gpus (self ): 82"""#1447: a plain two-GPU install has no helper cache, so no --remote-expert-opt is written.""" 83ram ,found = PROFILES ["47GB-2x16GB" ] 84args = ["--family" ,"qwen" ,"--no-start" ,"--model" ,"Q2_0" ,"--gpus" ,"0,1" ]# named: since the fit rule the default is the largest card + RAM 85code ,text ,cfg ,_ = install (ram ,found ,args ) 86self .assertEqual (code ,0 ,text ) 87self .assertIsInstance (cfg .get ("gpu" ),list ) 88self .assertNotIn (FLAG ,cfg ["args" ]) 89 90def test_install_on_one_gpu (self ): 91ram ,found = PROFILES ["96GB-1x16GB" ] 92code ,text ,cfg ,_ = install (ram ,found , ["--family" ,"qwen" ,"--no-start" ,"--model" ,"Q2_0" ]) 93self .assertEqual (code ,0 ,text ) 94self .assertNotIn (FLAG ,cfg ["args" ]) 95 96 97if __name__ == "__main__" : 98unittest .main ()