okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
5fa30bc8d
main
1"""Setup's recommendations from the community bench data (0.1.40): text only, never a changed default. 2 3python -m unittest tools.test_setup_bench_tips 4""" 5from __future__import annotations 6 7import sys 8import tempfile 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_hybrid import fake_sys # noqa: E402 17 18BASE = ["--expert-cache" ,"auto" ,"--prefill" ,"auto" ,"--max-context" ,"65536" ] 19 20 21def tips (args = BASE ,env = None ,ram = 32.0 ,model = 20.0 ,vram = 12.0 ,vision = "none" ,win = False ,gpu = None ): 22return setup .bench_tips (list (args ),env ,ram ,model ,vram ,vision ,win ,gpu ) 23 24 25class BenchTips (unittest .TestCase ): 26def test_nothing_to_say_on_a_plain_pc (self ): 27self .assertEqual (tips (), []) 28 29def test_explicit_cache_warns_on_windows_only (self ): 30a = ["--expert-cache" ,"2400" ,"--prefill" ,"auto" ] 31self .assertTrue (any ("--expert-cache 2400" in t and "7x" in t for t in tips (a ,win = True ))) 32self .assertEqual (tips (a ,win = False ), []) 33self .assertEqual (tips (BASE ,win = True ), [])# auto: nothing to warn about 34 35def test_the_chunk_tip_is_not_said_on_an_apu (self ): 36tip = next (t for t in tips (ram = 128 )if "auto:32768" in t ) 37self .assertTrue (setup .apu_hides_chunk_tip ({"arch" :"gfx1151" ,"uma" :True },tip ))# Strix Halo 38self .assertFalse (setup .apu_hides_chunk_tip ({"arch" :"gfx1201" },tip ))# a discrete card keeps it 39self .assertFalse (setup .apu_hides_chunk_tip ({"arch" :"gfx1151" ,"uma" :True },"warning: --prefill auto:32768 on 32 GB of RAM" )) 40 41def test_prefill_auto_32768_follows_the_ram (self ): 42self .assertTrue (any ("auto:32768" in t and t .startswith ("tip" )for t in tips (ram = 128 ))) 43self .assertEqual ([t for t in tips (ram = 64 )if "auto:32768" in t ], []) 44big = ["--prefill" ,"auto:32768" ] 45self .assertTrue (any (t .startswith ("warning" )and "auto:32768" in t for t in tips (big ,ram = 32 ))) 46self .assertEqual ([t for t in tips (big ,ram = 96 )if "auto:32768" in t ], []) 47 48def test_the_32768_tip_is_left_out_where_a_bare_auto_already_takes_it (self ): 49# round 0212: one NVIDIA card of compute capability 8.0+ (arch "86", "120", "121") gets a 32768 ceiling from a bare auto; so does 7.0 (Volta, "70"), 50# the engine's own rule (nv_chunk_card_ok in include/strata/core/nv_chunk.hpp) 51tip = lambda ** k : [t for t in tips (ram = 128 ,** k )if "auto:32768" in t ] 52for arch in ("70" ,"80" ,"86" ,"89" ,"90" ,"120" ,"121" ): 53self .assertEqual (tip (gpu = {"arch" :arch }), [],arch ) 54for arch in ("75" ,"60" ,"61" ,"62" ,"52" ,"gfx1201" ,"" ):# Turing, Pascal, older cards, AMD, unknown: the tip stays 55self .assertTrue (tip (gpu = {"arch" :arch }),arch ) 56self .assertTrue (tip ())# no GPU information: as before 57self .assertTrue (tip (gpu = {"arch" :"86" },env = {"STRATA_NV_CHUNK" :"0" })) 58self .assertTrue (tip (gpu = {"arch" :"86" },env = {"STRATA_DEFAULTS" :"026" })) 59self .assertTrue (tip (args = [* BASE ,"--gpus" ,"0,1" ],gpu = {"arch" :"86" }))# a layer split reads 8192-token chunks 60self .assertTrue (tip (args = [* BASE ,"--layer-split" ,"auto" ],gpu = {"arch" :"86" })) 61self .assertTrue (tip (gpu = {"arch" :"70" },env = {"STRATA_NV_CHUNK" :"0" }))# Volta follows the same switches and the same layer-split rule 62self .assertTrue (tip (args = [* BASE ,"--gpus" ,"0,1" ],gpu = {"arch" :"70" })) 63 64def test_resident_headroom_on_small_ram (self ): 65res = [* BASE ,"--resident-experts" ] 66self .assertTrue (any ("STRATA_RESIDENT_HEADROOM_GIB" in t for t in tips (res ,ram = 32 ))) 67self .assertTrue (any ("STRATA_RESIDENT_HEADROOM_GIB" in t for t in tips ([* BASE ,"--resident-budget-gib" ,"40" ],ram = 48 ))) 68self .assertEqual ([t for t in tips (res ,ram = 64 )if "HEADROOM" in t ], []) 69self .assertEqual ([t for t in tips (res , {"STRATA_RESIDENT_HEADROOM_GIB" :"8" },ram = 32 )if "HEADROOM" in t ], []) 70self .assertEqual ([t for t in tips (BASE ,ram = 32 )if "HEADROOM" in t ], [])# not a resident config 71 72def test_no_conversation_cache_tip_the_engine_sizes_it_itself (self ): 73# 0.2.3 (#3493): the engine sizes the conversation cache from the free RAM when no value is given, so setup no longer tips about it 74for ram ,model in ((64 ,40 ), (64 ,41 ), (128 ,40 )): 75self .assertEqual ([t for t in tips (ram = ram ,model = model )if "conversation" in t ], []) 76self .assertEqual ([t for t in tips ([* BASE ,"--conversation-cache-mib" ,"4096" ],ram = 128 )if "conversation" in t ], []) 77 78def test_vision_cpu_on_small_cards (self ): 79self .assertTrue (any ("--vision cpu" in t for t in tips (vision = "gpu" ,vram = 12 ))) 80self .assertEqual ([t for t in tips (vision = "gpu" ,vram = 24 )if "vision" in t ], []) 81self .assertEqual ([t for t in tips (vision = "cpu" ,vram = 12 )if "vision" in t ], []) 82 83def test_tips_never_touch_the_arguments (self ): 84a = ["--expert-cache" ,"2400" ,"--prefill" ,"auto" ,"--resident-experts" ] 85before = list (a ) 86env = {} 87tips (a ,env ,ram = 128 ,vision = "gpu" ,win = True ) 88self .assertEqual (a ,before ) 89self .assertEqual (env , {}) 90 91 92class Sockets (unittest .TestCase ): 93def fake (self ,d ,sockets ,cores ): 94n = 0 95for s in range (sockets ): 96for c in range (cores ): 97t = Path (d )/ "devices" / "system" / "cpu" / f"cpu { n } " / "topology" 98t .mkdir (parents = True ) 99 (t / "physical_package_id" ).write_text (str (s )) 100 (t / "core_id" ).write_text (str (c )) 101n += 1 102 103def test_linux_sockets (self ): 104with tempfile .TemporaryDirectory ()as d : 105self .fake (d ,2 ,18 ) 106self .assertEqual (setup .linux_sockets (d ), (2 ,18 )) 107with tempfile .TemporaryDirectory ()as d : 108self .fake (d ,1 ,8 ) 109self .assertEqual (setup .linux_sockets (d ), (1 ,8 )) 110with tempfile .TemporaryDirectory ()as d : 111self .assertIsNone (setup .linux_sockets (d )) 112 113def test_two_socket_tip (self ): 114t = setup .two_socket_note ((2 ,18 )) 115self .assertEqual (len (t ),1 ) 116self .assertIn ("--pool-workers 17" ,t [0 ]) 117self .assertEqual (setup .two_socket_note ((1 ,18 )), []) 118self .assertEqual (setup .two_socket_note (None ), []) 119 120 121if __name__ == "__main__" : 122unittest .main ()