okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
7025a9979
main
1"""The Linux AMD (HIP) engines hang under WSL (/dev/dxg present, /dev/kfd absent: librocdxg never completes a barrier-AND packet). 2Setup and launch say so in plain words with one next step, as a warning, and never refuse.""" 3 4from __future__import annotations 5 6import tempfile 7import unittest 8from pathlib import Path 9from unittest import mock 10 11from strata_cli .launch import settings as S 12from strata_cli .launch .runner import Runner 13from strata_control import engine_component as ec 14 15 16def dev (root :str ,dxg :bool = True ,kfd :bool = False )-> str : 17for name ,on in (("dxg" ,dxg ), ("kfd" ,kfd )): 18if on : 19Path (root ,name ).write_text ("" ,encoding = "utf-8" ) 20return root 21 22 23class WslAmdNote (unittest .TestCase ): 24def test_wsl_with_dxg_and_no_kfd_on_hip_gets_one_plain_sentence_with_a_next_step (self ): 25with tempfile .TemporaryDirectory ()as d : 26note = ec .wsl_amd_note ("hip" ,dev (d ),wsl = True ) 27self .assertIn ("do not run under WSL yet" ,note ) 28self .assertIn ("Windows" ,note )# the one next step: the Windows app or Terminal 29 30def test_nothing_to_say_elsewhere (self ): 31with tempfile .TemporaryDirectory ()as d : 32self .assertIsNone (ec .wsl_amd_note ("hip" ,dev (d ),wsl = False ))# a real Linux box 33self .assertIsNone (ec .wsl_amd_note ("cuda" ,dev (d ),wsl = True ))# NVIDIA works under WSL 34self .assertIsNone (ec .wsl_amd_note (None ,dev (d ),wsl = True )) 35with tempfile .TemporaryDirectory ()as d : 36self .assertIsNone (ec .wsl_amd_note ("hip" ,dev (d ,dxg = True ,kfd = True ),wsl = True ))# a /dev/kfd means the native driver 37with tempfile .TemporaryDirectory ()as d : 38self .assertIsNone (ec .wsl_amd_note ("hip" ,dev (d ,dxg = False ),wsl = True ))# no /dev/dxg: not the WSL GPU bridge 39 40def test_launch_warns_and_goes_on (self ): 41events = [] 42r = Runner (S .LaunchSettings (family = "qwen" ,model = "Q2_0" ,context = 32768 ),catalog = mock .Mock (),emit = events .append ) 43with mock .patch .object (ec ,"wsl_amd_note" ,side_effect = lambda backend ,* a ,** k :"WSL note" if backend == "hip" else None ), \ 44mock .patch .object (ec ,"detect_backend" ,return_value = ("hip" ,"test" )): 45r .warn_wsl_amd () 46self .assertEqual ([(e .level ,e .text )for e in events ], [("warn" ,"WSL note" )]) 47self .assertIn ("WSL note" ,r .notices ) 48 49def test_launch_is_silent_when_the_backend_is_not_hip (self ): 50events = [] 51r = Runner (S .LaunchSettings (family = "qwen" ,model = "Q2_0" ,context = 32768 ),catalog = mock .Mock (),emit = events .append ) 52with mock .patch .object (ec ,"wsl_amd_note" ,side_effect = lambda backend ,* a ,** k :"WSL note" if backend == "hip" else None ), \ 53mock .patch .object (ec ,"detect_backend" ,return_value = ("cuda" ,"test" )): 54r .warn_wsl_amd () 55self .assertEqual (events , []) 56 57def test_setup_warns_in_the_hip_branch_and_does_not_fail_on_its_own (self ): 58text = (Path (__file__ ).resolve ().parents [2 ]/ "setup.py" ).read_text (encoding = "utf-8" ) 59i = text .index ("wsl_amd_note(\"hip\", wsl=is_wsl())" ) 60self .assertIn ("warn(wsl_note)" ,text [i :i + 200 ]) 61self .assertLess (i ,text .index ("no AMD GPU Strata can use" )) 62 63 64if __name__ == "__main__" : 65unittest .main ()