okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
8ea5361bf
main
1"""Two Intel Arc Pro B65 cards (device id 0xe222): the Terminal must see both and name both for a launch that names none (fake sysfs, no hardware).""" 2from __future__import annotations 3 4import sys 5import tempfile 6import unittest 7from pathlib import Path 8 9ROOT = Path (__file__ ).resolve ().parents [2 ] 10sys .path .insert (0 ,str (ROOT )) 11 12from strata_cli .launch import catalog as C ,runner as R ,settings as S # noqa: E402 13 14 15def fake_drm (root :Path ,ids :list [str ])-> None : 16for i ,did in enumerate (ids ): 17dev = root / f"card { i } " / "device" 18dev .mkdir (parents = True ) 19 (dev / "vendor" ).write_text ("0x8086\n" ) 20 (dev / "device" ).write_text (did + "\n" ) 21 22 23class IntelCards (unittest .TestCase ): 24def cards (self ,ids ): 25with tempfile .TemporaryDirectory ()as d : 26fake_drm (Path (d ),ids ) 27return C .intel_arc_cards (d ) 28 29def test_two_b65_are_two_cards_of_32_gb (self ): 30cards = self .cards (["0xe222" ,"0xe222" ]) 31self .assertEqual ([(c ["index" ],c ["vram_gb" ])for c in cards ], [(0 ,32.0 ), (1 ,32.0 )]) 32self .assertTrue (all ("B65" in c ["name" ]for c in cards )) 33 34def test_the_other_battlemage_ids_are_listed (self ): 35for did in ("0xe221" ,"0xe211" ,"0xe212" ,"0xe20b" ,"0xe223" ): 36self .assertEqual (len (self .cards ([did ])),1 ,did ) 37 38def test_an_integrated_intel_gpu_is_never_a_card (self ): 39for did in ("0x46a6" ,"0x7d55" ,"0xa7a0" ,"0x9a49" ,"0x4680" ,"0x64a0" ): 40self .assertEqual (self .cards ([did ]), [],did ) 41self .assertEqual (len (self .cards (["0x7d55" ,"0xe222" ])),1 )# an iGPU beside a B65: one card 42 43def test_both_tables_list_the_same_discrete_ids (self ): 44import ast 45src = (ROOT / "sycl" / "setup_intel.py" ).read_text (encoding = "utf-8" ) 46node = next (n for n in ast .parse (src ).body if isinstance (n ,ast .Assign )and getattr (n .targets [0 ],"id" ,"" )== "INTEL_ARC" ) 47theirs = {"0x" + k :v [0 ].replace ("Arc " ,"" )for k ,v in ast .literal_eval (node .value ).items ()} 48ours = {k :v [0 ].replace ("Arc " ,"" )for k ,v in C .INTEL_ARC .items ()} 49self .assertEqual (set (theirs ),set (ours )) 50self .assertEqual ({k :v .replace (" " ,"" )for k ,v in theirs .items ()}, {k :v .replace (" " ,"" )for k ,v in ours .items ()}) 51 52def test_mixed_sizes_get_roles_like_any_other_pair (self ): 53cards = self .cards (["0xe222" ,"0xe20b" ])# 32 GB + 12 GB 54hw = {"ram_gb" :128.0 ,"os" :"Linux" ,"cpu" : {"avx2" :True },"gpus" :cards } 55cat = C .Catalog (root = Path (tempfile .mkdtemp ()),hardware = hw ) 56cat .installed_backend = lambda :"sycl" 57got = R .cards_for_launch (S .LaunchSettings (family = "qwen" ,model = "IQ3_S" ),cat ,base = {}) 58self .assertEqual (sorted (got ), [0 ,1 ]) 59 60def test_one_card_names_nothing (self ): 61hw = {"ram_gb" :128.0 ,"os" :"Linux" ,"cpu" : {"avx2" :True },"gpus" :self .cards (["0xe222" ])} 62cat = C .Catalog (root = Path (tempfile .mkdtemp ()),hardware = hw ) 63cat .installed_backend = lambda :"sycl" 64self .assertIsNone (R .cards_for_launch (S .LaunchSettings (family = "qwen" ,model = "IQ3_S" ),cat ,base = {})) 65 66def test_a_launch_that_names_no_card_gets_both_b65 (self ): 67hw = {"ram_gb" :128.0 ,"os" :"Linux" ,"cpu" : {"avx2" :True },"gpus" :self .cards (["0xe222" ,"0xe222" ])} 68cat = C .Catalog (root = Path (tempfile .mkdtemp ()),hardware = hw ) 69cat .installed_backend = lambda :"sycl" 70s = S .LaunchSettings (family = "qwen" ,model = "IQ3_S" ) 71got = R .cards_for_launch (s ,cat ,base = {}) 72self .assertEqual (sorted (got ), [0 ,1 ]) 73cfg = {} 74R .apply_cards (cfg ,got ) 75self .assertEqual (sorted (cfg ["gpu" ]), [0 ,1 ]) 76self .assertEqual (cfg ["layer_split" ],"auto" ) 77 78 79if __name__ == "__main__" : 80unittest .main ()