okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
407ea8192
main
1#!/usr/bin/env python3 2"""Serial, fresh-prompt Strata benchmark — adapted for the Radeon Pro VII (gfx906), no container. 3 4Same harness as bench/results/2026-10-04-community-mi50/benchmark_mi50.py (itself 5bench/results/2026-09-30-community-rtx-5090/benchmark.py); the only changes are the 6default paths and port: the engine and the pack sit in a normal checkout on this 7host, not in a container, and the server listens on 8080 without an API key. 8Runs on the HOST (imports strata_tokenizer and serve.frontend from --root). 9""" 10import argparse 11import hashlib 12import json 13import statistics 14import sys 15import time 16import urllib .request 17from pathlib import Path 18 19 20def main (): 21parser = argparse .ArgumentParser (description = __doc__ ) 22parser .add_argument ("--root" ,type = Path ,default = Path ("/home/user/Strata" )) 23parser .add_argument ("--pack" ,type = Path ,default = Path ("/home/user/Strata-data/packs/iq2_xs" )) 24parser .add_argument ("--url" ,default = "http://127.0.0.1:8080" ) 25parser .add_argument ("--api-key" ,default = "" ) 26parser .add_argument ("--out" ,type = Path , 27default = Path ("/home/user/Strata/bench/results/2026-10-09-community-radeon-pro-vii-16gb" )) 28parser .add_argument ("--targets" ,default = "4096,32768" ) 29parser .add_argument ("--runs" ,type = int ,default = 3 ) 30args = parser .parse_args () 31args .out .mkdir (parents = True ,exist_ok = True ) 32sys .path [:0 ]= [str (args .root ),str (args .root / "tools" )] 33from strata_tokenizer import Tokenizer 34from serve .frontend import ChatTemplate ,openai_to_messages 35 36auth = {"Content-Type" :"application/json" } 37if args .api_key : 38auth ["Authorization" ]= "Bearer " + args .api_key 39 40def get (url ): 41request = urllib .request .Request (url ,headers = auth ) 42with urllib .request .urlopen (request ,timeout = 30 )as response : 43return json .load (response ) 44 45directory = args .pack / "tokenizer" 46vocab = json .loads ((directory / "vocab.json" ).read_text ()) 47tokens = [None ]* len (vocab ) 48for token ,number in vocab .items (): 49tokens [number ]= token 50tokenizer = Tokenizer (tokens , (directory / "merges.txt" ).read_text ().splitlines (), 51json .loads ((directory / "token_type.json" ).read_text ())) 52template = ChatTemplate (directory / "chat_template.jinja" ) 53initial = get (args .url + "/v1/status" ) 54 (args .out / "initial-status.json" ).write_text (json .dumps (initial ,indent = 2 )+ "\n" ) 55rows = [] 56 57def request (content ,maximum = 256 ): 58return {"model" :"strata" ,"messages" : [{"role" :"user" ,"content" :content }], 59"temperature" :0 ,"reasoning_effort" :"none" ,"max_tokens" :maximum , 60"stream" :True ,"stream_options" : {"include_usage" :True }} 61 62def count (req ): 63messages ,tools ,kwargs = openai_to_messages (req ) 64return len (tokenizer .encode (template .render (messages ,tools ,** kwargs ),parse_special = True )) 65 66def perform (label ,req ,expected = None ): 67body = json .dumps (req ).encode () 68 (args .out / (label + "-request.json" )).write_bytes (body + b"\n" ) 69"start" ,label ,"tokens" ,expected ,flush = True ) 70chunks ,texts ,first ,finish = [], [],None ,None 71started = time .perf_counter () 72wire = urllib .request .Request (args .url + "/v1/chat/completions" ,data = body ,headers = auth ) 73with urllib .request .urlopen (wire ,timeout = 1800 )as response : 74for line in response : 75if not line .startswith (b"data: " ): 76continue 77payload = line [6 :].strip () 78if payload == b"[DONE]" : 79break 80chunk = json .loads (payload ) 81chunks .append (chunk ) 82for choice in chunk .get ("choices" , []): 83delta = choice .get ("delta" , {}) 84text = (delta .get ("content" )or "" )+ (delta .get ("reasoning_content" )or "" ) 85if text : 86first = first if first is not None else time .perf_counter ()- started 87texts .append (text ) 88finish = choice .get ("finish_reason" )or finish 89elapsed = time .perf_counter ()- started 90metrics = get (args .url + "/metrics" ) 91engine = metrics ["requests" ][0 ] 92usage = next ((chunk ["usage" ]for chunk in reversed (chunks )if "usage" in chunk ), {}) 93row = {"label" :label ,"expected_prompt_tokens" :expected , 94"request_sha256" :hashlib .sha256 (body ).hexdigest (), 95"client_ttft_s" :first ,"client_elapsed_s" :elapsed ,"finish_reason" :finish , 96"usage" :usage ,"engine" :engine ,"text" :"" .join (texts )} 97if expected is not None and engine ["prompt_tokens" ]!= expected : 98raise RuntimeError (f"token count mismatch: { expected } vs { engine [ 'prompt_tokens' ] } " ) 99if not texts : 100raise RuntimeError (f"no text received for { label } " ) 101 (args .out / (label + "-raw.json" )).write_text (json .dumps ({"chunks" :chunks ,"row" :row },indent = 2 )+ "\n" ) 102rows .append (row ) 103 (args .out / "results.json" ).write_text (json .dumps (rows ,indent = 2 )+ "\n" ) 104"done" ,label ,json .dumps ({"ttft_s" :first ,"elapsed_s" :elapsed ,"engine" :engine }),flush = True ) 105return row 106 107perform ("warmup" ,request ("Reply with exactly the word READY." ,16 )) 108filler = "\n" .join (f"def task_ { i :05d } (value: int) -> int: return (value * { ( i % 97 ) + 1 } + { i } ) % 100003" 109for i in range (12000 )) 110ending = ("\n\nWrite a detailed explanation of the code above. Discuss deterministic integer transforms, " 111"modulo arithmetic, testing, naming, complexity, and maintainability. Write at least 600 words." ) 112for target in map (int ,args .targets .split ("," )): 113for run in range (1 ,args .runs + 1 ): 114prefix = f"Benchmark nonce: series- { target } -trial- { run } .\nReview this synthetic Python module:\n" 115lo ,hi = 0 ,len (filler ) 116while lo < hi : 117middle = (lo + hi + 1 )// 2 118if count (request (prefix + filler [:middle ]+ ending ))<= target : 119lo = middle 120else : 121hi = middle - 1 122req = request (prefix + filler [:lo ]+ ending ) 123actual = count (req ) 124if actual < target - 20 or actual > target : 125raise RuntimeError (f"could not construct target { target } : { actual } " ) 126perform (f"tokens- { target } -run- { run } " ,req ,actual ) 127measured = [row for row in rows if row ["label" ]!= "warmup" ] 128groups = {} 129for target in map (int ,args .targets .split ("," )): 130subset = [r for r in measured if r ["label" ].startswith (f"tokens- { target } -" )] 131values = { 132"prompt_tokens" : [r ["engine" ]["prompt_tokens" ]for r in subset ], 133"cached_tokens" : [r ["engine" ].get ("reused" ,0 )for r in subset ], 134"output_tokens" : [r ["engine" ]["engine_generated" ]for r in subset ], 135"client_ttft_s" : [r ["client_ttft_s" ]for r in subset ], 136"client_elapsed_s" : [r ["client_elapsed_s" ]for r in subset ], 137"prefill_tok_s" : [(r ["engine" ]["prompt_tokens" ]- (r ["engine" ].get ("reused" )or 0 ))/ (r ["engine" ]["prompt_ms" ]/ 1000 )for r in subset ], 138"decode_tok_s" : [r ["engine" ]["engine_generated" ]/ (r ["engine" ]["decode_ms" ]/ 1000 )for r in subset ], 139 } 140groups [str (target )]= {key : {"median" :statistics .median (v ),"min" :min (v ),"max" :max (v )} 141for key ,v in values .items ()} 142 (args .out / "summary.json" ).write_text (json .dumps (groups ,indent = 2 )+ "\n" ) 143"summary" ,json .dumps (groups ),flush = True ) 144 145 146if __name__ == "__main__" : 147main ()