okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6e1085c1d
main
1import json ,os ,re ,subprocess ,sys ,threading ,time ,traceback 2from pathlib import Path 3ROOT = Path (os .environ .get ('ROOF_ROOT' ,'/home/bench/src/strata-pr1656-parent-p4-20261009' )) 4OUT = Path (os .environ .get ('ROOF_OUT' ,'/home/bench/fleet-downloads/issue1670-p4-roofline' )) 5OUT .mkdir (parents = True ,exist_ok = True ) 6sys .path [:0 ]= [str (ROOT ),str (ROOT / 'tools' )] 7from serve .server import StrataEngine ,child_env ,engine_args 8from strata_tokenizer import Tokenizer 9from serve .frontend import ChatTemplate 10 11def save (data ): 12p = OUT / 'results.tmp' ;p .write_text (json .dumps (data ,indent = 2 ));p .replace (OUT / 'results.json' ) 13 14cfg = json .loads (Path (os .environ ['ROOF_CONFIG' ]).read_text ()) 15cfg .update (exe = str (ROOT / 'build/strata' ),cwd = str (ROOT ),gpu = 0 ,log = str (OUT / 'engine.log' ),model_name = 'qwen3.8-flash-next-gsq-rco-iq3_xxs' ) 16cfg .pop ('layer_split' ,None ) 17a = cfg ['args' ] 18for flag in ['--shared-expert-arena' ,'--pipeline-windows' ]: 19if flag in a :i = a .index (flag );del a [i :i + 2 ] 20if '--trim-stage-weights' in a :a .remove ('--trim-stage-weights' ) 21for flag ,value in {'--max-context' :'16384' ,'--kv-resident' :'16384' ,'--prefill' :'512' }.items ():a [a .index (flag )+ 1 ]= value 22if '--mmap-experts' not in a :a += ['--mmap-experts' ] 23cfg ['env' ]= {'STRATA_PREFILL_TIMING' :'1' ,'STRATA_IQ_MT_MIN' :'1' ,'OMP_NUM_THREADS' :'1' ,'OPENBLAS_NUM_THREADS' :'1' ,'STRATA_ATTN_MERGE_V2' :'1' } 24if os .environ .get ('ROOF_CONTROL' ): 25cfg ['env' ].update (STRATA_PREFILL_ROOFLINE = '1' ,STRATA_PREFILL_CPU_SHARE = '0' ) 26if os .environ .get ('ROOF_PREFILL' ): 27a [a .index ('--prefill' )+ 1 ]= os .environ ['ROOF_PREFILL' ] 28(OUT / 'config.json' ).write_text (json .dumps (cfg ,indent = 2 )) 29args = engine_args (cfg );env = child_env (cfg ) 30tok = Tokenizer .from_gguf (Path (a [a .index ('--native' )+ 1 ])) 31template = ChatTemplate (Path (cfg ['tokenizer' ])/ 'chat_template.jinja' ) 32pre ,post = template .render ([{'role' :'user' ,'content' :'Background notes:\nFILLER_HERE\nEnd of notes.\nTask: Explain how a Linux administrator diagnoses CPU, memory, disk and network bottlenecks.' }],enable_thinking = False ).split ('FILLER_HERE' ) 33aa ,bb = tok .encode (pre ,parse_special = True ),tok .encode (post ,parse_special = True ) 34filler = tok .encode ('Archived maintenance notes contain background information about ordinary testing and documentation.\n' ) 35prompts = {str (n ):aa + (filler * ((n - len (aa )- len (bb )+ len (filler )- 1 )// len (filler )))[:n - len (aa )- len (bb )]+ bb for n in [512 ,4096 ,8192 ]} 36plan = [dict (tokens = 512 ,phase = 'warmup' ,repeat =- 1 )]+ [dict (tokens = n ,phase = 'measured' ,repeat = i )for n in [512 ,4096 ,8192 ]for i in range (3 )] 37if os .environ .get ('ROOF_CONTROL' ): 38plan = [dict (tokens = 512 ,phase = 'warmup' ,repeat =- 1 )]+ [dict (tokens = n ,phase = 'measured' ,repeat = 0 )for n in [4096 ,8192 ]] 39report = {'config' :cfg ,'args' :args ,'prompts' :prompts ,'plan' :plan ,'runs' :[],'complete' :False ,'commit' :subprocess .check_output (['git' ,'-C' ,str (ROOT ),'rev-parse' ,'HEAD' ],text = True ).strip ()} 40engine = None 41try : 42save (report );engine = StrataEngine (cfg ['exe' ],args ,cfg ['cwd' ],cfg ['log' ],env );report ['engine_info' ]= engine .info ;save (report ) 43for entry in plan : 44'START' ,entry ,flush = True );offset = Path (cfg ['log' ]).stat ().st_size ;start = time .monotonic ();tokens = [] 45timer = threading .Timer (900 ,engine .proc .kill );timer .start () 46try : 47for token in engine .generate (prompts [str (entry ['tokens' ])],1 ,{'temperature' :0 },threading .Event ()): 48if token is not None :tokens .append (token ) 49finally :timer .cancel () 50row = dict (entry ,output = tokens ,wall_s = time .monotonic ()- start ,timing = dict (engine .last ),log = Path (cfg ['log' ]).read_bytes ()[offset :].decode (errors = 'replace' )) 51report ['runs' ].append (row );save (report );'RESULT' ,json .dumps ({k :v for k ,v in row .items ()if k != 'log' }),flush = True ) 52assert row ['timing' ].get ('reused' ,0 )== 0 and tokens 53report ['complete' ]= True 54except BaseException : 55report ['error' ]= traceback .format_exc ();raise 56finally : 57if engine :engine .close () 58save (report )