okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1#!/usr/bin/env python3 2"""Quality check for a numerically different path (the fused IQ prompt kernels): run the same greedy prompts through 3two configs and compare the answers. 4 5python quality_fused.py strata-iq3s-nofused.json strata-iq3s-best.json out.json 6""" 7import json 8import subprocess 9import sys 10import time 11import urllib .request 12from pathlib import Path 13 14ROOT = Path (__file__ ).resolve ().parents [3 ] 15PROMPTS = [ 16"Write a Python function that merges two sorted lists into one sorted list, with a docstring and two tests." , 17"Explain in two short paragraphs how a heat pump moves heat from outside to inside a house." , 18"A train leaves at 09:15 and travels 210 km at 84 km/h. At what time does it arrive? Show the arithmetic." , 19"Summarize the main trade-offs between 4-bit and 8-bit weight quantization for LLM inference." , 20"List five concrete steps to debug a CUDA kernel that returns wrong results, one sentence each." , 21] 22 23 24def post (port ,prompt ,max_tokens = 160 ): 25body = json .dumps ({"messages" : [{"role" :"user" ,"content" :prompt }],"max_tokens" :max_tokens , 26"temperature" :0 ,"chat_template_kwargs" : {"enable_thinking" :False }}).encode () 27req = urllib .request .Request (f"http://127.0.0.1: { port } /v1/chat/completions" ,data = body , 28headers = {"Content-Type" :"application/json" }) 29with urllib .request .urlopen (req ,timeout = 1800 )as r : 30out = json .loads (r .read ()) 31return out ["choices" ][0 ]["message" ].get ("content" ,"" ),out .get ("timings" )or {} 32 33 34def run (cfg ,port ,tag ): 35cpath = Path (f"/tmp/quality- { tag } .json" ) 36c = json .loads (Path (cfg ).read_text ()) 37c ["port" ]= port 38c ["log" ]= f"/tmp/quality- { tag } .log" 39cpath .write_text (json .dumps (c ,indent = 1 )) 40proc = subprocess .Popen ([sys .executable ,str (ROOT / "serve" / "server.py" ),"--engine" ,"strata" ,"--config" , 41str (cpath ),"--port" ,str (port )],cwd = str (ROOT ), 42stdout = subprocess .DEVNULL ,stderr = subprocess .DEVNULL ) 43try : 44for _ in range (600 ): 45try : 46with urllib .request .urlopen (f"http://127.0.0.1: { port } /v1/models" ,timeout = 5 )as r : 47if r .status == 200 : 48break 49except Exception : 50pass 51time .sleep (2 ) 52post (port ,"Say hi." ,8 ) 53out = [] 54for p in PROMPTS : 55txt ,t = post (port ,p ) 56out .append (txt ) 57f" { tag } : { t . get ( 'prompt_per_second' ) } tok/s prompt, { t . get ( 'predicted_per_second' ) } tok/s decode" ) 58return out 59finally : 60proc .terminate () 61try : 62proc .wait (60 ) 63except subprocess .TimeoutExpired : 64proc .kill () 65time .sleep (5 ) 66 67 68a = run (sys .argv [1 ],8097 ,"a" ) 69b = run (sys .argv [2 ],8097 ,"b" ) 70res = [] 71same = 0 72for i , (x ,y )in enumerate (zip (a ,b )): 73eq = x == y 74same += eq 75pre = 0 76while pre < min (len (x ),len (y ))and x [pre ]== y [pre ]: 77pre += 1 78res .append ({"prompt" :PROMPTS [i ],"identical" :eq ,"common_prefix_chars" :pre , 79"len_a" :len (x ),"len_b" :len (y ),"a" :x ,"b" :y }) 80f"prompt { i } : { 'IDENTICAL' if eq else 'differs' } (prefix { pre } chars, { len ( x ) } vs { len ( y ) } chars)" ) 81Path (sys .argv [3 ]).write_text (json .dumps ({"identical" :same ,"of" :len (PROMPTS ),"items" :res },indent = 1 )) 82f" { same } of { len ( PROMPTS ) } answers identical" )