okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6abee7f39
main
1"""Serve-mode checks of the experimental-speed-projection vector (exact mode: fixed experts, no PCIe share). 2 3python esp_serve.py run ARM # ARM = stock | vec; writes esp-serve/<arm>.json 4python esp_serve.py compare 5 6Per arm: the first greedy token after many prefixes of three texts (short ones go through the verify windows, long 7ones through the batched prompt path; the conversation cache reuses the earlier prefix), and three 256-token greedy 8generations. The vec arm runs everything with cvec=1, then cvec=0, then cvec=1 again. 9""" 10import json 11import os 12import sys 13import threading 14 15S = os .path .dirname (os .path .abspath (__file__ )) 16E = r"C:\Users\AI-Server\Desktop\Strata\Public\Engine" 17sys .path .insert (0 ,E ) 18from serve .server import StrataEngine # noqa: E402 19 20EXE = E + r"\build-dev\strata.exe" 21VEC = r"C:\Users\AI-Server\Desktop\Strata\experimental-speed-projection\Qwen3.8-Flash-Next-experimental-speed-projection.gguf" 22TEXTS = {"code" :S + r"\p512.ids" ,"doc" :S + r"\4k-02-long-doc-1k.ids" ,"chat" :S + r"\4k-04-chat-1k.ids" } 23OUT = S + r"\esp-serve" 24VEC_ARGS = ["--control-vector-scaled" ,VEC + ":1.0" ,"--control-vector-layer-range" ,"4" ,"44" , 25"--cvec-mode" ,"project" ,"--cvec-dir" ,"per-layer" ] 26 27 28def ids_of (name ): 29return [int (x )for x in open (TEXTS [name ]).read ().replace ("," ," " ).split ()] 30 31 32def engine (extra ): 33c = json .load (open (S + r"\cfg-rel.json" )) 34a = list (c ["args" ]) 35a [a .index ("--expert-cache" )+ 1 ]= "4000" 36env = dict (os .environ ) 37env ["PATH" ]= os .pathsep .join (c ["lib_dirs" ])+ os .pathsep + env ["PATH" ] 38return StrataEngine (EXE ,a + ["--pcie-frac" ,"0" ,"--adapt-swaps" ,"0" ]+ extra ,cwd = c ["cwd" ], 39log = OUT + r"\engine.log" ,env = env ) 40 41 42def gen (eng ,ids ,n ,sampling ): 43toks = [t for t in eng .generate (ids ,n ,sampling ,threading .Event ())if t is not None ] 44return toks ,dict (eng .last ) 45 46 47def suite (eng ,sampling ): 48out = {"first" : {},"long" : {}} 49for name in TEXTS : 50ids = ids_of (name ) 51# short prefixes growing by 4 (each continues the live session through the verify windows), then long ones 52# SHRINKING (no cached prefix, so each is read from 0 by the batched prompt path) 53lens = list (range (32 ,72 ,4 ))+ list (range (min (len (ids )- 1 ,700 ),95 ,- 48 )) 54out ["first" ][name ]= {L :gen (eng ,ids [:L ],1 ,sampling )[0 ][0 ]for L in lens } 55for name in TEXTS : 56toks ,last = gen (eng ,ids_of (name )[:300 ],256 ,sampling ) 57out ["long" ][name ]= {"tokens" :toks ,"last" :last } 58return out 59 60 61def run (arm ): 62os .makedirs (OUT ,exist_ok = True ) 63eng = engine (VEC_ARGS if arm == "vec" else []) 64res = {"info" :eng .info } 65if arm == "stock" : 66res ["stock" ]= suite (eng , {}) 67else : 68res ["on" ]= suite (eng , {"experimental_speed_projection" :True }) 69res ["off" ]= suite (eng , {"experimental_speed_projection" :False }) 70res ["on2" ]= suite (eng , {"experimental_speed_projection" :True }) 71eng .close () 72json .dump (res ,open (f" { OUT } \\ { arm } .json" ,"w" )) 73arm ,"done" ,eng .info ,flush = True ) 74 75 76def compare (): 77import numpy as np 78sys .path .insert (0 ,S ) 79from esp_kl import load ,OUT as KL 80st = json .load (open (OUT + r"\stock.json" )) 81ve = json .load (open (OUT + r"\vec.json" )) 82"engine INFO (vec):" ,ve ["info" ]) 83 84def eq_first (a ,b ): 85tot = same = 0 86for name in a : 87for L ,t in a [name ].items (): 88tot += 1 89same += int (b [name ][L ]== t ) 90return same ,tot 91 92def eq_long (a ,b ): 93return all (a [n ]["tokens" ]== b [n ]["tokens" ]for n in a ), \ 94 [(n ,next ((i for i , (x ,y )in enumerate (zip (a [n ]["tokens" ],b [n ]["tokens" ]))if x != y ),None ))for n in a ] 95 96"1. vector loaded, switched off == no vector" ) 97" first tokens: %d / %d identical" % eq_first (st ["stock" ]["first" ],ve ["off" ]["first" ])) 98" 256-token generations identical:" ,* eq_long (st ["stock" ]["long" ],ve ["off" ]["long" ])) 99"2. repeatable: on, off, on again" ) 100" first tokens: %d / %d identical" % eq_first (ve ["on" ]["first" ],ve ["on2" ]["first" ])) 101" 256-token generations identical:" ,* eq_long (ve ["on" ]["long" ],ve ["on2" ]["long" ])) 102"3. the prompt paths against the per-token path's teacher-forced argmax (row L-1 predicts token L)" ) 103for arm ,first in (("stock" ,st ["stock" ]["first" ]), ("on" ,ve ["on" ]["first" ])): 104for ref in ("stock" ,"proj" ): 105agree = tot = 0 106for name in first : 107d = load (f" { KL } \\ { name } - { ref } .bin" ) 108for L ,t in first [name ].items (): 109L = int (L ) 110if L - 1 < d .shape [0 ]: 111tot += 1 112agree += int (int (np .argmax (d [L - 1 ]))== t ) 113f" served { arm :<5 } vs per-token { ref :<5 } : { agree } / { tot } " ) 114"4. how different the text is: 256-token generations, on vs stock, first difference" ) 115" " ,eq_long (st ["stock" ]["long" ],ve ["on" ]["long" ])[1 ]) 116"5. decode speed (exact mode: fixed experts, no PCIe share - not the normal setup)" ) 117for label ,r in (("stock" ,st ["stock" ]), ("vec off" ,ve ["off" ]), ("vec on" ,ve ["on" ]), ("vec on 2" ,ve ["on2" ])): 118g = sum (v ["last" ]["generated" ]for v in r ["long" ].values ()) 119ms = sum (v ["last" ]["decode_ms" ]for v in r ["long" ].values ()) 120acc = sum (v ["last" ].get ("drafts_accepted" ,0 )for v in r ["long" ].values ()) 121off = sum (v ["last" ].get ("drafts_offered" ,0 )for v in r ["long" ].values ()) 122f" { label :<9 } { g / ms * 1000 :6.1f } tok/s drafts accepted { acc } / { off } " ) 123 124 125if __name__ == "__main__" : 126if sys .argv [1 ]== "run" : 127run (sys .argv [2 ]) 128else : 129compare ()