okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c23a78694
main
1"""Owner rule 2026-10-18: pictures are on by default wherever the model and the engine package can read them; the reader runs on the 2CPU under 24 GB of VRAM and on the GPU from 24 GB, on every make of card. Checks setup.images_default and the shared rule. 3 4python -m unittest tools.test_picture_defaults 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 strata_control import vision_reader as VR # noqa: E402 17 18 19class PictureDefaults (unittest .TestCase ): 20def test_unsloth_default_is_on_for_every_make_and_size (self ): 21models = [m for m ,d in setup .MODELS .items ()if d .get ("budget" )and d .get ("vision" )is not False ] 22self .assertTrue (models ) 23for m in models : 24for gpu in ({"vram_gb" :10.0 }, {"vram_gb" :12.0 }, {"vram_gb" :16.0 }, {"vram_gb" :32.0 }, 25 {"vram_gb" :16.0 ,"arch" :"gfx1201" }, {"vram_gb" :24.0 ,"arch" :"gfx1100" }, {}): 26for win in (False ,True ): 27old = setup .WIN 28setup .WIN = win 29try : 30self .assertTrue (setup .images_default (m ,"unsloth" ,64.0 ,gpu ), (m ,gpu ,win )) 31self .assertTrue (setup .images_default (m ,"unsloth" ,512.0 ,gpu ), (m ,gpu ,win )) 32finally : 33setup .WIN = old 34 35def test_yes_means_pictures_on_for_qwen_swift_and_coder (self ): 36"""setup --yes (and Enter at the question) on the original Flash-Next, Swift and Coder files: pictures on, the reader by the 24 GB rule, 37and no VRAM reserve for the CPU reader.""" 38from test_setup_golden import PROFILES ,install 39for key ,gpu in (("64GB-1x32GB" ,True ), ("96GB-1x16GB" ,False )):# 31.8 GB: the GPU reader; 15.9 GB: the CPU reader 40ram ,found = PROFILES [key ] 41for fam ,model in (("qwen" ,"Q2_0" ), ("swift" ,"IQ3_S" ), ("coder" ,"IQ1_M" )): 42for answers in (None ,"" ): 43code ,out ,cfg ,_ = install (ram ,found , ["--family" ,fam ,"--model" ,model ,"--no-start" ],answers = answers ) 44where = (key ,fam ,model ,answers ) 45self .assertEqual (code ,0 , (where ,out [- 1500 :])) 46self .assertIn ("--vision" ,cfg ["args" ],where ) 47self .assertEqual (cfg ["vision" ]["gpu" ],gpu ,where ) 48self .assertEqual ("--vram-reserve-mib" in cfg ["args" ],gpu ,where )# only the GPU reader keeps VRAM free 49self .assertIn ("images: on" ,out ,where ) 50 51def test_pictures_off_stays_available (self ): 52from test_setup_golden import PROFILES ,install 53ram ,found = PROFILES ["64GB-1x32GB" ] 54for fam ,model in (("qwen" ,"Q2_0" ), ("swift" ,"IQ3_S" ), ("coder" ,"IQ1_M" )): 55code ,out ,cfg ,_ = install (ram ,found , ["--family" ,fam ,"--model" ,model ,"--no-start" ,"--vision" ,"no" ]) 56self .assertEqual (code ,0 ,out [- 1500 :]) 57self .assertNotIn ("--vision" ,cfg ["args" ]) 58self .assertNotIn ("vision" ,cfg ) 59 60def test_the_cpu_reader_takes_no_vram_reserve (self ): 61"""So a card of 8 GB is no exception: the reserve is only for the GPU reader.""" 62self .assertEqual (setup .VISION ["cpu" ]["reserve_mib" ],0 ) 63self .assertEqual (setup .VISION ["gpu" ]["reserve_mib" ],700 ) 64 65def test_one_rule_for_the_reader (self ): 66self .assertEqual (setup .IMAGES_GPU_ENCODER_MIN_VRAM_GB ,VR .GPU_MIN_VRAM_GB ) 67for vram ,want in ((8 ,"cpu" ), (16 ,"cpu" ), (23.0 ,"cpu" ), (24 ,"gpu" ), (32 ,"gpu" ), (None ,"gpu" )): 68self .assertEqual (VR .default_mode (vram ),want ) 69self .assertEqual (VR .wanted ("yes" ,vram ),want ) 70self .assertEqual (setup .hip_vision ("yes" ,vram or 0.0 ),want if vram else "gpu" ) 71self .assertEqual (setup .hip_vision (None ,16.0 ),"cpu" ) 72self .assertEqual (setup .hip_vision ("gpu" ,16.0 ),"gpu" ) 73 74class MacPictureDefaults (unittest .TestCase ): 75"""setup.py on a Mac: pictures on by default, on the Metal reader (strata_control/vision_reader.py).""" 76 77def test_nothing_asked_means_the_gpu_reader_for_every_mac_size (self ): 78from strata_control import mac_fit as MF 79for model in MF .MAC_MODELS : 80for ram in (32.0 ,64.0 ,128.0 ): 81self .assertEqual (setup .mac_vision (None ,model ,ram ),"gpu" , (model ,ram )) 82self .assertEqual (setup .mac_vision ("yes" ,model ,ram ),"gpu" , (model ,ram )) 83 84def test_off_and_cpu_are_kept_as_asked (self ): 85for off in ("no" ,"none" ,"off" ): 86self .assertEqual (setup .mac_vision (off ,"Q2_0" ,32.0 ),"none" ) 87self .assertEqual (setup .mac_vision ("cpu" ,"Q2_0" ,32.0 ),"cpu" ) 88 89def test_a_folder_without_the_reader_turns_pictures_off (self ): 90import tempfile 91d = Path (tempfile .mkdtemp (prefix = "macvis-" )) 92 (d / "strata" ).write_bytes (b"x" ) 93self .assertEqual (setup .mac_reader (d ,"gpu" ).mode ,"none" ) 94 (d / "strata-vision" ).write_bytes (b"x" ) 95r = setup .mac_reader (d ,"gpu" ) 96self .assertEqual ((r .mode ,r .exe .name ), ("gpu" ,"strata-vision" )) 97 98 99if __name__ == "__main__" : 100unittest .main ()