okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
fcb0c2d0e
main
1#!/usr/bin/env python3 2"""Metal serve regression probe (owner round 9, G6): one request of the first N token ids of a prompt through serve/server.py on the 3config in STRATA_CFG, with its default flags (expert cache auto, prefill auto). 95, 569, 1500 and 8213 ids used to end in 4"prefill: relayout needs borrowed buffers and a chunk of at most 0" or in a copy into device allocations that were given back. 5 6STRATA_REPO=<checkout> STRATA_CFG=<run config json> STRATA_PROMPTS=<dir with agent.prompt.ids> python3 serve_probe.py EXE 95:agent 8 7 8Needs the Gyro-S (or any Flash-Next) model on the Mac; it is not part of the unit tests.""" 9import os 10import sys 11import threading 12import time 13from pathlib import Path 14 15REPO = Path (os .environ ["STRATA_REPO" ]) 16sys .path .insert (0 ,str (REPO / "tools" )) 17sys .path .insert (0 ,str (REPO )) 18import strata_tokenizer as ST # noqa: E402 19from serve .server import StrataEngine ,child_env # noqa: E402 20 21EXE = sys .argv [1 ] 22NAME = sys .argv [2 ]if len (sys .argv )> 2 else "agent" 23MAX_NEW = int (sys .argv [3 ])if len (sys .argv )> 3 else 8 24S = os .environ .get ("STRATA_OUT" ,os .path .expanduser ("~/strata-mac/g023/out" )) 25cfg = json .load (open (os .environ ["STRATA_CFG" ],encoding = "utf-8-sig" )) 26tp = Path (cfg ["tokenizer" ]) 27vocab = json .loads ((tp / "vocab.json" ).read_text (encoding = "utf-8" )) 28toks = [None ]* len (vocab ) 29for t ,i in vocab .items (): 30toks [i ]= t 31tok = ST .Tokenizer (toks , (tp / "merges.txt" ).read_text (encoding = "utf-8" ).split ("\n" ), 32json .loads ((tp / "token_type.json" ).read_text ())) 33if NAME .split (":" )[0 ].isdigit ():# "4096" / "4096:agent": the first N ids of the agent prompt 34parts = NAME .split (":" ) 35n = int (parts [0 ]) 36src = parts [1 ]if len (parts )> 1 else "agent" 37raw = (Path (os .environ .get ("STRATA_PROMPTS" ,os .path .expanduser ("~/owner-t9/bundle/prompts" )))/ f" { src } .prompt.ids" ).read_text () 38try : 39ids = json .loads (raw )[:n ] 40except Exception : 41ids = [int (x )for x in raw .replace ("," ," " ).split ()][:n ] 42else : 43raw = (Path (os .environ .get ("STRATA_PROMPTS" ,os .path .expanduser ("~/owner-t9/bundle/prompts" )))/ f" { NAME } .prompt.ids" ).read_text () 44try : 45ids = json .loads (raw ) 46except Exception : 47ids = [int (x )for x in raw .replace ("," ," " ).split ()] 48args = list (cfg ["args" ])+ os .environ .get ("STRATA_EXTRA_ARGS" ,"" ).split () 49log = os .path .join (S ,f"probe- { NAME } .log" ) 50t0 = time .time () 51eng = StrataEngine (EXE ,args ,cwd = cfg .get ("cwd" ),log = log ,env = child_env (cfg )) 52f"READY after { time . time () - t0 :.1f } s, prompt { len ( ids ) } tokens" ,flush = True ) 53t1 = time .time () 54out = [t for t in eng .generate (ids ,MAX_NEW , {"temperature" :0 },threading .Event ())if t is not None ] 55last = dict (eng .last ) 56f" { NAME } : { len ( out ) } out in { time . time () - t1 :.1f } s; prompt { last . get ( 'prompt_tokens' ) } tok in " 57f" { last . get ( 'prompt_ms' ) } ms = { last . get ( 'prompt_tokens' , 0 ) / ( last . get ( 'prompt_ms' , 1 ) / 1000 ):.1f } tok/s; " 58f"decode { last . get ( 'decode_ms' ) } ms = { len ( out ) / ( last [ 'decode_ms' ] / 1000 ) if last . get ( 'decode_ms' ) else 0 :.2f } tok/s; " 59f"drafts { last . get ( 'drafts_accepted' ) } / { last . get ( 'drafts_offered' ) } " ,flush = True ) 60"text:" ,tok .decode (out )[:120 ].replace ("\n" ," " ),flush = True ) 61eng .proc .stdin .close () 62try : 63eng .proc .wait (60 ) 64except Exception : 65eng .proc .kill () 66"PROBE_DONE" ,flush = True )