okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1#!/usr/bin/env python3 2"""Does the engine hold a context past the installed 64K? Copy the shipped config, raise the context to 128K, and send a 3100K-token prompt with a hidden code. Success = an answer that recalls it; failure is recorded as a limit. 4 5python dgx_128k.py CONFIG OUT.json [--tokens 100000] [--ctx 131072] 6""" 7import json 8import random 9import subprocess 10import sys 11import time 12import urllib .request 13from pathlib import Path 14 15ROOT = Path (__file__ ).resolve ().parents [3 ] 16WORDS = ("river stone market lantern copper winter garden signal harbor needle orbit velvet canyon ember ledger quartz " 17"meadow anchor violet thunder cedar marble piston ribbon cobalt falcon glacier hollow ivory juniper kernel " 18"lattice mirror nectar oasis pepper quarry raven saddle tundra umber vessel willow xenon yellow zephyr" ).split () 19 20 21def build (tokens ,code ,rng ): 22body = [rng .choice (WORDS )for _ in range (int (tokens / 1.35 ))] 23at = rng .randrange (len (body )// 3 ,2 * len (body )// 3 ) 24body [at :at ]= [f"The access code for the harbor gate is { code } ." ] 25return ("Read the following log carefully, then answer the question at the end.\n\n" + " " .join (body )+ 26"\n\nQuestion: what is the access code for the harbor gate? Answer with the code only." ) 27 28 29def main (): 30cfg_path ,out_path = sys .argv [1 ],sys .argv [2 ] 31tokens = int (sys .argv [3 ])if len (sys .argv )> 3 else 100000 32ctx = int (sys .argv [4 ])if len (sys .argv )> 4 else 131072 33port = 8091 34cfg = json .loads (Path (cfg_path ).read_text ()) 35a = cfg ["args" ] 36if "--max-context" in a : 37a [a .index ("--max-context" )+ 1 ]= str (ctx ) 38if "--kv-resident" in a : 39a [a .index ("--kv-resident" )+ 1 ]= "32768" 40cfg ["port" ]= port 41cfg ["log" ]= "/tmp/long-128k.log" 42tmp = Path ("/tmp/long-128k.json" ) 43tmp .write_text (json .dumps (cfg ,indent = 1 )) 44proc = subprocess .Popen ([sys .executable ,str (ROOT / "serve" / "server.py" ),"--engine" ,"strata" ,"--config" , 45str (tmp ),"--port" ,str (port )],cwd = str (ROOT ), 46stdout = subprocess .DEVNULL ,stderr = subprocess .DEVNULL ) 47try : 48t0 = time .time () 49while time .time ()- t0 < 1800 : 50if proc .poll ()is not None : 51raise SystemExit (f"server exited { proc . returncode } " ) 52try : 53with urllib .request .urlopen (f"http://127.0.0.1: { port } /v1/models" ,timeout = 5 )as r : 54if r .status == 200 : 55break 56except Exception : 57pass 58time .sleep (3 ) 59f"ready in { time . time () - t0 :.0f } s" ,flush = True ) 60rng = random .Random (11 ) 61code = "271828" 62prompt = build (tokens ,code ,rng ) 63body = json .dumps ({"messages" : [{"role" :"user" ,"content" :prompt }],"max_tokens" :32 ,"temperature" :0 , 64"chat_template_kwargs" : {"enable_thinking" :False }}).encode () 65req = urllib .request .Request (f"http://127.0.0.1: { port } /v1/chat/completions" ,data = body , 66headers = {"Content-Type" :"application/json" }) 67t1 = time .time () 68with urllib .request .urlopen (req ,timeout = 5400 )as r : 69out = json .loads (r .read ()) 70wall = time .time ()- t1 71t = out .get ("timings" )or {} 72answer = out ["choices" ][0 ]["message" ].get ("content" ,"" ) 73row = {"tokens" :tokens ,"ctx" :ctx ,"prompt_n" :t .get ("prompt_n" ), 74"prompt_per_second" :t .get ("prompt_per_second" ), 75"predicted_per_second" :t .get ("predicted_per_second" ),"wall_s" :round (wall ,1 ), 76"answer" :answer [:80 ],"recalled" :code in answer } 77Path (out_path ).write_text (json .dumps (row ,indent = 1 )) 78json .dumps (row )) 79finally : 80proc .terminate () 81try : 82proc .wait (180 ) 83except subprocess .TimeoutExpired : 84proc .kill () 85 86 87if __name__ == "__main__" : 88main ()