okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ef8071303
main
1#!/usr/bin/env python3 2import json ,os ,subprocess ,time ,urllib .request ,statistics 3 4# Set STRATA_API_KEY in the environment; nothing is committed. 5 6URL = "http://127.0.0.1:8080/v1/chat/completions" 7KEY = os .environ .get ("STRATA_API_KEY" ,"" ) 8OUT = "/mnt/1TB/src/Strata/bench-titan" 9os .makedirs (OUT ,exist_ok = True ) 10 11def pcie (): 12o = subprocess .run (["nvidia-smi" ,"--query-gpu=index,pcie.link.gen.current,pcie.link.width.current" , 13"--format=csv,noheader,nounits" ],capture_output = True ,text = True ).stdout .strip () 14return o .replace ("\n" ,"; " ) 15 16def req (prompt ,max_tokens = 256 ): 17body = json .dumps ({"model" :"strata" ,"messages" :[{"role" :"user" ,"content" :prompt }], 18"max_tokens" :max_tokens ,"temperature" :0 ,"stream" :False }).encode () 19r = urllib .request .Request (URL ,data = body ,headers = {"Content-Type" :"application/json" , 20"Authorization" :"Bearer " + KEY }) 21t0 = time .time () 22with urllib .request .urlopen (r ,timeout = 900 )as f : 23d = json .loads (f .read ()) 24wall = time .time ()- t0 25tm = d .get ("timings" ,{});u = d .get ("usage" ,{}) 26return {"prompt_n" :tm .get ("prompt_n" ),"prompt_ms" :tm .get ("prompt_ms" ), 27"prompt_tps" :tm .get ("prompt_per_second" ),"gen_n" :tm .get ("predicted_n" ), 28"gen_ms" :tm .get ("predicted_ms" ),"gen_tps" :tm .get ("predicted_per_second" ), 29"ttft_s" :round (wall - (tm .get ("predicted_ms" ,0 )or 0 )/ 1000 ,2 ), 30"total_s" :round (wall ,2 ),"usage_prompt" :u .get ("prompt_tokens" ), 31"usage_completion" :u .get ("completion_tokens" ), 32"finish" :d ["choices" ][0 ].get ("finish_reason" )} 33 34BASE = ("Sparse mixture-of-experts routing sends each token through a small subset of " 35"feed-forward experts. The gate projects hidden states into per-expert scores, applies a " 36"top-k mask and renormalizes the surviving weights. Recurrent delta layers maintain linear " 37"state across the sequence while sparse attention indexes only a subset of keys. " 38"Quantized weights trade numerical precision for memory bandwidth at every matmul. " ) 39 40def make (n_tokens ,variant ): 41s = BASE + (" Document revision marker %d. " % variant ) 42per = len (s )// 4 43reps = max (1 ,n_tokens // per ) 44return s * reps 45 46results = {} 47for length in (4096 ,32768 ,128000 ): 48runs = [] 49for v in range (3 ): 50p = make (length ,v ) 51r = req (p ) 52r ["variant" ]= v ;r ["pcie_during" ]= pcie () 53runs .append (r ) 54length ,"run" ,v + 1 ,"prompt_tps" ,round (r ["prompt_tps" ]or 0 ,1 ), 55"gen_tps" ,round (r ["gen_tps" ]or 0 ,2 ),"ttft" ,r ["ttft_s" ],flush = True ) 56results [str (length )]= runs 57 58summary = {} 59for k ,v in results .items (): 60pt = [x ["prompt_tps" ]for x in v if x ["prompt_tps" ]] 61gt = [x ["gen_tps" ]for x in v if x ["gen_tps" ]] 62tt = [x ["ttft_s" ]for x in v ] 63summary [k ]= {"prompt_tps" :{"runs" :[round (x ,1 )for x in pt ], 64"median" :round (statistics .median (pt ),1 )if pt else None , 65"min" :round (min (pt ),1 )if pt else None ,"max" :round (max (pt ),1 )if pt else None }, 66"decode_tps" :{"runs" :[round (x ,2 )for x in gt ], 67"median" :round (statistics .median (gt ),2 )if gt else None , 68"min" :round (min (gt ),2 )if gt else None ,"max" :round (max (gt ),2 )if gt else None }, 69"ttft_s" :{"runs" :tt ,"median" :round (statistics .median (tt ),2 )if tt else None }} 70 71json .dump ({"summary" :summary ,"runs" :results },open (OUT + "/titan-results.json" ,"w" ),indent = 1 ) 72"=== SUMMARY ===" ) 73json .dumps (summary ,indent = 1 ))