okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6e1085c1d
main
1"""Two arms on the same box, same prompts and image: the five STRATA_* opt-ins off, then on (the live runner). 2 3Arm "optins-off": the live runner container is stopped (not removed) and a clone is started from its own 4`docker inspect` config with only those five variables dropped. Arm "optins-on": the live container itself, 5restarted. Each arm: fresh engine process, cold first request, two warm-ups, 3x 4,096 / 32,768 / 128,000 6(bench.py), then the needle checks. VRAM per card is sampled every second. Whatever happens, the clone is 7removed and the live container is left running. 8""" 9 10import json 11import signal 12import subprocess 13import threading 14import time 15import urllib .request 16from pathlib import Path 17 18C = "local-llm-runner-cluster-7900s-strata-bca809cd" 19CLONE = C + "-optins-off" 20D = Path .home ()/ "scratch/strata_bench2" 21OPT_INS = ("STRATA_SPLIT_OWN" ,"STRATA_STAGE_TRIM" ,"STRATA_PF_FUSED" ,"STRATA_PF_GEMM" ,"STRATA_PF_SWITCH_MIN_T" ) 22 23 24def sh (* args ,check = True ): 25return subprocess .run (args ,capture_output = True ,text = True ,check = check ) 26 27 28def say (* a ): 29time .strftime ("%H:%M:%S" ),* a ,flush = True ) 30 31 32def status (): 33try : 34with urllib .request .urlopen ("http://127.0.0.1:8086/v1/status" ,timeout = 5 )as r : 35return json .load (r ) 36except OSError : 37return None 38 39 40def wait_loaded (t0 ,label ): 41deadline = time .time ()+ 900 42while True : 43s = status () 44if s and s .get ("loaded" )and s .get ("uptime_s" ,1e9 )<= time .time ()- t0 + 5 : 45say (label ,"loaded after" ,round (time .time ()- t0 ),"s" ) 46return s 47if time .time ()> deadline : 48raise SystemExit (f" { label } : not loaded after 15 min" ) 49time .sleep (2 ) 50 51 52stop = threading .Event () 53 54 55def sampler (): 56with (D / "vram.jsonl" ).open ("a" )as f : 57while not stop .is_set (): 58out = sh ("rocm-smi" ,"--showmeminfo" ,"vram" ,"--json" ,check = False ).stdout 59try : 60used = {k :int (v ["VRAM Total Used Memory (B)" ])for k ,v in json .loads (out ).items ()} 61except (ValueError ,KeyError ): 62used = None 63f .write (json .dumps ({"t" :round (time .time (),2 ),"used_b" :used })+ "\n" ) 64f .flush () 65stop .wait (1 ) 66 67 68def bench (arm ,container ,t0 ): 69s = wait_loaded (t0 ,arm ) 70 (D / f"status_after_load- { arm } .json" ).write_text (json .dumps (s ,indent = 1 )) 71env = json .loads (sh ("docker" ,"inspect" ,container ).stdout )[0 ]["Config" ]["Env" ] 72 (D / f"container_env- { arm } .txt" ).write_text ("" .join (e + "\n" for e in env if e .startswith (("STRATA_" ,"HIP_" )))) 73time .sleep (5 ) 74subprocess .run (["python3" ,"bench.py" ,"prompts.jsonl" ,f"matrix- { arm } .jsonl" ],cwd = D ,check = True ) 75say (arm ,"matrix done" ) 76with (D / f"needles- { arm } .log" ).open ("w" )as log : 77subprocess .run (["python3" ,str (D / "src/tools/needle_bench.py" ),"--url" ,"http://127.0.0.1:8086" , 78"--lengths" ,"32k,128k" ,"--depths" ,"10,50,90" ,"--out" ,str (D / f"needles- { arm } .json" )], 79cwd = D ,stdout = log ,stderr = subprocess .STDOUT ,check = True ) 80say (arm ,"needles done" ) 81since = time .strftime ("%Y-%m-%dT%H:%M:%SZ" ,time .gmtime (t0 - 1 )) 82logs = sh ("docker" ,"logs" ,"--since" ,since ,container ,check = False ) 83 (D / f"engine- { arm } .log" ).write_text (logs .stdout + logs .stderr ) 84 85 86def handler (signum ,frame ): 87raise SystemExit (f"signal { signum } " ) 88 89 90signal .signal (signal .SIGTERM ,handler ) 91signal .signal (signal .SIGINT ,handler ) 92 93orig = json .loads (sh ("docker" ,"inspect" ,C ).stdout )[0 ] 94cfg ,host = orig ["Config" ],orig ["HostConfig" ] 95assert not any (k in " " .join (cfg ["Cmd" ])for k in OPT_INS ),"opt-ins in the command line" 96assert all (any (e .startswith (k + "=" )for e in cfg ["Env" ])for k in OPT_INS ),"live env lacks the opt-ins" 97run = ["docker" ,"run" ,"-d" ,"--name" ,CLONE ,"--network" ,host ["NetworkMode" ],"--ipc" ,host ["IpcMode" ], 98"--shm-size" ,str (host ["ShmSize" ])] 99for g in host .get ("GroupAdd" )or []: 100run += ["--group-add" ,g ] 101for d in host .get ("Devices" )or []: 102run += ["--device" ,f" { d [ 'PathOnHost' ] } : { d [ 'PathInContainer' ] } " ] 103for b in host .get ("Binds" )or []: 104run += ["-v" ,b ] 105for e in cfg ["Env" ]: 106if e .split ("=" ,1 )[0 ]not in OPT_INS : 107run += ["-e" ,e ] 108run += [cfg ["Image" ],* cfg ["Cmd" ]] 109 110(D / "vram.jsonl" ).unlink (missing_ok = True ) 111threading .Thread (target = sampler ,daemon = True ).start () 112try : 113t0 = time .time () 114say ("optins-off: stop live container, start clone without" ,"," .join (OPT_INS )) 115sh ("docker" ,"stop" ,C ) 116sh (* run ) 117bench ("optins-off" ,CLONE ,t0 ) 118sh ("docker" ,"rm" ,"-f" ,CLONE ) 119say ("optins-off: clone removed" ) 120 121t0 = time .time () 122say ("optins-on: start live container (fresh process)" ) 123sh ("docker" ,"start" ,C ) 124bench ("optins-on" ,C ,t0 ) 125finally : 126stop .set () 127sh ("docker" ,"rm" ,"-f" ,CLONE ,check = False ) 128if json .loads (sh ("docker" ,"inspect" ,C ).stdout )[0 ]["State" ]["Running" ]is not True : 129sh ("docker" ,"start" ,C ,check = False ) 130say ("live container started again" ) 131say ("live container running:" ,json .loads (sh ("docker" ,"inspect" ,C ).stdout )[0 ]["State" ]["Running" ]) 132"ALL_DONE" ,flush = True )