okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f129082f0
main
1#!/usr/bin/env python3 2"""Community benchmark: Strata at 1M context under an agent-like workload. 3 4Follows docs/COMMUNITY_BENCHMARKS.md conventions: 5- prompt and decode throughput come from the server's own `timings` block, 6never from dividing tokens by wall time; 7- time to first token (TTFT) is measured at the client on the first 8non-empty streamed delta (reasoning or answer text — flagged per run); 9- each size runs three fresh prompts plus one immediate repeat (warm prefix 10reuse), plus one greedy no-thinking run; 11- actual prompt token counts are reported from the server, since the 12synthetic prompt length is only approximate. 13 14Writes one JSON record per run to the file given as argv[1] 15(default: agent_bench.jsonl). Contains no credentials. 16 17Requires a running server on 127.0.0.1:8080 (edit SERVER_URL if needed). 18""" 19 20import json 21import sys 22import time 23import urllib .request 24 25SERVER_URL = "http://127.0.0.1:8080/v1/chat/completions" 26MODEL = "qwen3.8-flash-next-iq3_s" 27 28# A paragraph of plain English; repeated to build synthetic prompts. 29PARAGRAPH = ( 30"The lighthouse keeper recorded the weather each hour: " 31"wind from the northwest, sea moderate, visibility good. " 32) 33# Rough paragraphs-per-token for this text; the real count is reported by 34# the server in `prompt_n`, so this only sizes the request. 35PARAGRAPHS_PER_TOKEN = 22 36 37TASK_SUFFIX = "\n\nSummarize the pattern in these records in two sentences." 38 39 40def build_prompt (target_tokens :int )-> str : 41paragraphs = target_tokens // PARAGRAPHS_PER_TOKEN + 2 42return PARAGRAPH * paragraphs + TASK_SUFFIX 43 44 45def _first_delta (chunk :dict )-> dict : 46"""The streamed delta of a chunk, defensively typed (malformed chunks 47simply yield {}, which the caller treats as 'no token yet').""" 48choices = chunk .get ("choices" ) 49if isinstance (choices ,list )and choices and isinstance (choices [0 ],dict ): 50delta = choices [0 ].get ("delta" ) 51return delta if isinstance (delta ,dict )else {} 52return {} 53 54 55def run_once (prompt :str ,* ,max_tokens :int ,temperature :float | None , 56top_p :float | None ,thinking :bool )-> dict : 57"""Stream one chat completion; return the server's timings plus client TTFT.""" 58payload = { 59"model" :MODEL , 60"messages" : [{"role" :"user" ,"content" :prompt }], 61"max_tokens" :max_tokens , 62"stream" :True , 63 } 64if temperature is not None : 65payload ["temperature" ]= temperature 66if top_p is not None : 67payload ["top_p" ]= top_p 68if not thinking : 69payload ["chat_template_kwargs" ]= {"enable_thinking" :False } 70 71request = urllib .request .Request ( 72SERVER_URL , 73data = json .dumps (payload ).encode ("utf-8" ), 74headers = {"Content-Type" :"application/json" }, 75 ) 76 77started = time .monotonic () 78ttft_s = None 79last_chunk :dict = {} 80with urllib .request .urlopen (request ,timeout = 900 )as response : 81for line in response : 82if not line .startswith (b"data: " ): 83continue 84data = line [len (b"data: " ):].strip () 85if data == b"[DONE]" : 86break 87chunk = json .loads (data ) 88if isinstance (chunk ,dict ): 89last_chunk = chunk 90if ttft_s is None : 91delta = _first_delta (chunk if isinstance (chunk ,dict )else last_chunk ) 92if delta .get ("content" )or delta .get ("reasoning_content" ): 93ttft_s = time .monotonic ()- started 94 95if not last_chunk : 96raise RuntimeError ("server streamed no completion chunks" ) 97timings = last_chunk .get ("timings" )or {} 98 99record = { 100"t_wall_s" :round (time .monotonic ()- started ,3 ), 101"ttft_s" :round (ttft_s ,3 )if ttft_s is not None else None , 102"thinking" :thinking , 103"temperature" :temperature , 104"prompt_n" :timings .get ("prompt_n" ), 105"prompt_ms" :timings .get ("prompt_ms" ), 106"predicted_n" :timings .get ("predicted_n" ), 107"predicted_ms" :timings .get ("predicted_ms" ), 108"cache_n" :timings .get ("cache_n" ), 109"prompt_per_second" :timings .get ("prompt_per_second" ), 110"predicted_per_second" :timings .get ("predicted_per_second" ), 111 } 112return record 113 114 115def main ()-> None : 116out_path = sys .argv [1 ]if len (sys .argv )> 1 else "agent_bench.jsonl" 117sizes = (4096 ,32768 ,131072 ,524288 ) 118with open (out_path ,"w" ,encoding = "utf-8" )as out : 119for size in sizes : 120prompt = build_prompt (size ) 121for run_index in range (1 ,4 ): 122record = run_once (prompt ,max_tokens = 256 , 123temperature = 1.0 ,top_p = 0.95 ,thinking = True ) 124record ["tag" ]= f"think_ { size } _run { run_index } " 125out .write (json .dumps (record )+ "\n" ) 126out .flush () 127# Immediate repeat: exercises prefix reuse (see cache_n / prompt_n). 128record = run_once (prompt ,max_tokens = 256 , 129temperature = 1.0 ,top_p = 0.95 ,thinking = True ) 130record ["tag" ]= f"think_ { size } _warm_repeat" 131out .write (json .dumps (record )+ "\n" ) 132out .flush () 133# Instruct mode: greedy, thinking suppressed at the template. 134record = run_once (prompt ,max_tokens = 256 , 135temperature = 0.0 ,top_p = None ,thinking = False ) 136record ["tag" ]= f"instruct_ { size } _greedy" 137out .write (json .dumps (record )+ "\n" ) 138out .flush () 139f"wrote { out_path } " ) 140 141 142if __name__ == "__main__" : 143main ()