okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
e28889d12
main
1"""Graphics card roles in setup (strata_control/gpu_roles.py): the best card is Main, the others start as Helper, a card with 8 GB or less 2starts Off; one question, "Use these roles?"; --gpu-roles names them. 3 4python tools/test_setup_gpu_fit.py 5""" 6from __future__import annotations 7 8import sys 9import unittest 10from pathlib import Path 11 12ROOT = Path (__file__ ).resolve ().parents [1 ] 13sys .path .insert (0 ,str (ROOT )) 14sys .path .insert (0 ,str (ROOT / "tools" )) 15import setup # noqa: E402 16from test_setup_golden import card ,install # noqa: E402 17 18 19def run (ram ,found ,model ,answers = None ,extra = ()): 20argv = ["--family" ,"qwen" ,"--no-start" ,"--model" ,model ,"--context" ,"32768" ,* extra ] 21return install (ram ,found ,argv ,answers = answers or {}) 22 23 24class SetupFitRule (unittest .TestCase ): 25def test_one_card_has_no_question (self ): 26code ,out ,cfg ,asked = run (62.0 , [card (0 ,"NVIDIA GeForce RTX 3070 Ti" ,8.0 ,"86" )],"IQ3_XXS" ) 27self .assertEqual (code ,0 ,out ) 28self .assertEqual (cfg ["gpu" ],0 )if "gpu" in cfg else None 29self .assertFalse (any ("Which GPUs" in q for q in asked ),asked ) 30 31def test_two_unequal_cards_the_big_one_is_main_and_a_card_with_8_gb_or_less_starts_off (self ): 32found = [card (0 ,"NVIDIA GeForce RTX 3060 Ti" ,8.0 ,"86" ),card (1 ,"NVIDIA GeForce RTX 3070 Ti" ,16.0 ,"86" )] 33code ,out ,cfg ,asked = run (62.0 ,found ,"IQ3_XXS" ) 34self .assertEqual (code ,0 ,out ) 35self .assertEqual (cfg ["gpu" ],1 )# the 16 GB card, alone 36self .assertEqual (cfg ["gpu_roles" ], {"0" :"off" ,"1" :"main" }) 37self .assertNotIn ("layer_split" ,cfg ) 38self .assertTrue (any ("Use these roles?" in q and "[y]" in q for q in asked ),asked ) 39# one answer away: the 8 GB card as a Helper 40code ,out ,cfg ,_ = run (62.0 ,found ,"IQ3_XXS" ,answers = {"Use these roles?" :"n" ,"Roles, e.g." :"1=main,0=helper" }) 41self .assertEqual (code ,0 ,out ) 42self .assertEqual (cfg ["gpu" ], [0 ,1 ])# Main LAST: the engine's stage order 43self .assertEqual (cfg ["gpu_order" ],"as_given" ) 44self .assertEqual (cfg ["gpu_roles" ], {"0" :"helper" ,"1" :"main" }) 45self .assertEqual (cfg ["layer_split" ],"auto" ) 46 47def test_two_equal_cards_start_with_the_highest_number_as_main (self ): 48found = [card (0 ,"NVIDIA GeForce RTX 3060" ,12.0 ,"86" ),card (1 ,"NVIDIA GeForce RTX 3060" ,12.0 ,"86" )] 49code ,out ,cfg ,asked = run (26.0 ,found ,"IQ3_XXS" ) 50self .assertEqual (code ,0 ,out ) 51self .assertEqual (cfg ["gpu" ], [0 ,1 ]) 52self .assertEqual (cfg ["gpu_roles" ], {"0" :"helper" ,"1" :"main" }) 53self .assertEqual (cfg ["gpu_order" ],"as_given" ) 54self .assertEqual (cfg ["layer_split" ],"auto" ) 55 56def test_gpu_roles_flag (self ): 57found = [card (0 ,"NVIDIA GeForce RTX 3060" ,12.0 ,"86" ),card (1 ,"NVIDIA GeForce RTX 3070 Ti" ,16.0 ,"86" )] 58code ,out ,cfg ,_ = run (62.0 ,found ,"IQ3_XXS" ,extra = ("--gpu-roles" ,"0=main,1=helper" )) 59self .assertEqual (code ,0 ,out ) 60self .assertEqual (cfg ["gpu" ], [1 ,0 ])# the slower card is Main on purpose: it goes last 61self .assertEqual (cfg ["gpu_roles" ], {"0" :"main" ,"1" :"helper" }) 62code ,out ,cfg ,_ = run (62.0 ,found ,"IQ3_XXS" ,extra = ("--gpu-roles" ,"1=main,0=off" )) 63self .assertEqual ((cfg ["gpu" ],cfg ["gpu_roles" ]), (1 , {"0" :"off" ,"1" :"main" })) 64self .assertNotIn ("layer_split" ,cfg ) 65code ,out ,cfg ,_ = run (62.0 ,found ,"IQ3_XXS" ,extra = ("--gpu-roles" ,"0=off,1=off" )) 66self .assertNotEqual (code ,0 ) 67 68def test_naming_the_cards_still_wins (self ): 69found = [card (0 ,"NVIDIA GeForce RTX 3070 Ti" ,16.0 ,"86" ),card (1 ,"NVIDIA GeForce RTX 3060 Ti" ,8.0 ,"86" )] 70code ,out ,cfg ,_ = run (62.0 ,found ,"IQ3_XXS" ,extra = ("--gpus" ,"0,1" )) 71self .assertEqual (code ,0 ,out ) 72self .assertEqual (sorted (cfg ["gpu" ]), [0 ,1 ]) 73code ,out ,cfg ,_ = run (62.0 ,found ,"IQ3_XXS" ,extra = ("--gpu" ,"1" )) 74self .assertEqual (cfg ["gpu" ],1 ) 75 76def test_a_bigger_amd_card_beside_the_nvidia_one_is_said_in_one_line_and_never_mixed (self ): 77"""RTX 5060 Ti (16 GB) + AMD R9700 (32 GB): the question offers the two makes apart, says one engine drives one make and that two 78models at once are not supported, and names the bigger AMD card; the NVIDIA answer runs on the NVIDIA card alone.""" 79from unittest import mock 80found = [card (0 ,"NVIDIA GeForce RTX 5060 Ti" ,16.0 ,"120" )] 81amd = [{"index" :0 ,"name" :"AMD Radeon AI PRO R9700" ,"vram_gb" :32.0 ,"arch" :"gfx1201" ,"vendor" :"amd" }] 82patches = [mock .patch .object (setup ,"amd_gpus" ,lambda * a ,** k : [dict (g )for g in amd ]), 83mock .patch .object (setup ,"amd_problem" ,lambda g :None )] 84argv = ["--family" ,"qwen" ,"--no-start" ,"--model" ,"IQ3_XXS" ,"--context" ,"32768" ] 85code ,out ,cfg ,asked = install (62.0 ,found ,argv ,answers = {"Which cards?" :"1" },extra = patches ) 86self .assertEqual (code ,0 ,out ) 87self .assertIn ("This PC has NVIDIA and AMD cards Strata can use" ,out ) 88self .assertIn ("never split across NVIDIA and AMD cards" ,out ) 89self .assertIn ("two models at the same" ,out ) 90self .assertIn ("not supported yet" ,out ) 91self .assertIn ("This computer also has an AMD AI PRO R9700 (32 GB). The AMD build of Strata can use it" ,out ) 92self .assertNotIn ("Which GPUs?" ," " .join (asked ))# one NVIDIA card: no split question 93self .assertEqual (cfg .get ("gpu" ,0 ),0 ) 94 95 96if __name__ == "__main__" : 97unittest .main ()