okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
326e39118
main
1"""#1445: a vision encoder that cannot start because the GPU is busy/unavailable (compute mode Exclusive_Process) says 2so, with the nvidia-smi check, instead of only the first line of the encoder's output. 3 4python -m serve.test_vision_busy 5""" 6import io 7import tempfile 8import unittest 9from pathlib import Path 10from types import SimpleNamespace 11from unittest import mock 12 13import serve .server as server 14 15 16class Busy (unittest .TestCase ): 17def test_message_names_the_cause_from_the_line (self ): 18m = server .vision_start_error ("ggml_backend_cuda_device_get_memory: cudaMemGetInfo failed " 19"(CUDA-capable device(s) is/are busy or unavailable), returning 0/0" ) 20self .assertIn ("Exclusive_Process" ,m ) 21self .assertIn ("nvidia-smi" ,m ) 22self .assertIn ("did not start" ,m ) 23 24def test_message_names_the_cause_from_the_log_tail (self ): 25with tempfile .NamedTemporaryFile ("w+" ,suffix = ".log" ,delete = False )as f : 26f .write ("x" * 40000 + "\ncudaMalloc failed: CUDA-capable device(s) is/are busy or unavailable\n" ) 27name = f .name 28try : 29with open (name ,"a" )as log : 30m = server .vision_start_error ("load_hparams: something" ,log ) 31self .assertIn ("Exclusive_Process" ,m ) 32finally : 33Path (name ).unlink () 34 35def test_other_failures_are_unchanged (self ): 36self .assertEqual (server .vision_start_error ("ERR no mmproj\n" ),"the vision encoder did not start: ERR no mmproj" ) 37 38def test_start_raises_it (self ): 39line = "cudaMalloc failed: CUDA-capable device(s) is/are busy or unavailable\n" 40proc = SimpleNamespace (stdin = io .StringIO (),stdout = io .StringIO (line ),kill = lambda :None ,wait = lambda timeout = None :0 , 41poll = lambda :None ) 42v = server .Vision .__new__ (server .Vision ) 43v .spawn = (["strata-vision" ],None ,None ) 44v .dir = Path (tempfile .gettempdir ()) 45with mock .patch .object (server ,"popen" ,lambda * a ,** k :proc ): 46with self .assertRaises (RuntimeError )as cm : 47v ._start () 48self .assertIn ("Exclusive_Process" ,str (cm .exception )) 49 50 51if __name__ == "__main__" : 52unittest .main ()