okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
c65b9f8be
main
1"""Two small cards on a layer split (MULTISPILL, round 0212): what the launcher says when a card runs out of memory. 2 3The final line of a failed start is the engine's own reason, not the picture reader's harmless "ggml_cuda_init: ... no CUDA-capable device" that it prints when the 4cards are full and it runs on the processor; the next step does not tell the person to change the context or the number of requests. Nothing here starts an engine.""" 5from __future__import annotations 6 7import json 8import tempfile 9import unittest 10from pathlib import Path 11 12from strata_cli .launch import runner as R 13from strata_control import vram_fit 14 15# the log of the 2 x 8 GB start that failed (HYBRID, srv118, 2 x RTX PRO 6000 held to 8 GB free by hogs, 128K): the engine's reason, then the picture reader's line 16SERVE_STOP = [ 17"strata serve: layer split, CUDA1 prompt path: prefill: device buffers for a chunk of 512 tokens do not fit (5 of 97247 MiB free at the failure; 555 MiB taken, the failing buffer wanted 2 MiB)" , 18"strata serve: the GPU has too little free VRAM for the prompt path: turn images off (setup: --vision no), close other programs using the GPU, use a shorter context, or read prompts in smaller chunks (--prefill 512)" , 19"ggml_cuda_init: failed to initialize CUDA: no CUDA-capable device is detected" , 20] 21CACHE_STOP = [ 22"strata generate: layer split, CUDA1: 0.17 GiB free of 94.97, room for experts 0.00 GiB" , 23"strata generate: layer split, CUDA1 expert cache: no room" , 24"ggml_cuda_init: failed to initialize CUDA: no CUDA-capable device is detected" , 25] 26 27 28class TheEnginesReason (unittest .TestCase ): 29def test_the_reason_is_the_engines_not_the_picture_readers (self ): 30self .assertEqual (vram_fit .engine_stop_reason (SERVE_STOP ), 31"the GPU has too little free VRAM for the prompt path: turn images off (setup: --vision no), close other programs using the GPU, " 32"use a shorter context, or read prompts in smaller chunks (--prefill 512)" ) 33self .assertEqual (vram_fit .engine_stop_reason (CACHE_STOP ),"layer split, CUDA1 expert cache: no room" ) 34 35def test_other_stops_and_the_walks_own_lines_are_not_a_memory_stop (self ): 36self .assertIsNone (vram_fit .engine_stop_reason (["strata generate: something else is wrong" ,"ggml_cuda_init: failed to initialize CUDA" ])) 37self .assertIsNone (vram_fit .engine_stop_reason ([])) 38self .assertIsNone (vram_fit .engine_stop_reason (None )) 39walk = ["strata generate: short of GPU memory: CUDA1 has 2.53 GiB free and a layer split card needs about 9.1 GiB: each later card loads only the dense weights of its own layers" , 40"strata serve: CUDA1: 293 MiB of VRAM free with everything loaded - LOW: its window graphs are captured on first use" ] 41self .assertIsNone (vram_fit .engine_stop_reason (walk ),"what the walk did and a LOW warning say nothing about why a start stopped" ) 42 43def test_the_last_memory_line_wins (self ): 44lines = ["strata generate: layer split, CUDA1 expert cache: no room" ,"strata serve: the GPU has too little free VRAM for the prompt path: x" ] 45self .assertTrue (vram_fit .engine_stop_reason (lines ).startswith ("the GPU has too little free VRAM" )) 46 47 48class TheLastLine (unittest .TestCase ): 49def explain (self ,lines ,** result ): 50with tempfile .TemporaryDirectory ()as tmp : 51log = Path (tmp )/ "engine.log" 52log .write_text ("\n" .join (lines )+ "\n" ,encoding = "utf-8" ) 53cfg = Path (tmp )/ "run.json" 54cfg .write_text (json .dumps ({"exe" :"e" ,"args" : [],"log" :str (log )}),encoding = "utf-8" ) 55return R .explain_engine_exit ({"state" :"failed" ,"error" :"server_exited" ,"engine_exit_code" :1 ,** result },cfg ) 56 57def test_a_prompt_path_stop_shows_the_engines_line_and_a_next_step_that_keeps_the_context (self ): 58text ,nxt = self .explain (SERVE_STOP ) 59self .assertIn ("too little free VRAM for the prompt path" ,text ) 60self .assertNotIn ("ggml_cuda_init" ,text ) 61self .assertNotIn ("no CUDA-capable device" ,text ) 62self .assertIn ("were not changed" ,nxt ,"the context and the requests stay what the person chose" ) 63self .assertIn ("fewer cards" ,nxt ) 64self .assertNotIn ("--context 16k" ,nxt ,"the old advice asked for a smaller context" ) 65 66def test_a_stage_cache_stop_shows_the_engines_line (self ): 67text ,_ = self .explain (CACHE_STOP ) 68self .assertIn ("layer split, CUDA1 expert cache: no room" ,text ) 69self .assertNotIn ("ggml_cuda_init" ,text ) 70 71def test_a_stop_for_another_reason_is_worded_as_before (self ): 72text ,nxt = self .explain (["strata generate: cudaMalloc failed" ,"unsupported quant type 99" ]) 73self .assertIn ("unsupported quant type 99" ,text ) 74self .assertNotIn ("were not changed" ,nxt ) 75 76 77if __name__ == "__main__" : 78unittest .main ()