okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
2b36e8a02
main
1#!/usr/bin/env python3 2"""Live parity check for STRATA_SPLIT_MTP_BATCH (needs a running engine; no model on the build box). 3 4split_mtp_batch_parity.py dump OUT.json [--url URL] [--key-file FILE] [--long-words N] 5split_mtp_batch_parity.py compare A.json B.json 6 7`dump` sends 5 fixed greedy prompts x 256 tokens and one long prompt (default ~25k tokens) x 256 tokens to a 8server started WITHOUT the env (A) or WITH STRATA_SPLIT_MTP_BATCH=1 (B), and stores the texts. `compare` exits 0 9when every text is identical, 1 otherwise, printing PASS/FAIL lines. The drafter's K/V is not bit-identical 10(Q8_1 x Q8_0 MMQ instead of mmvq), so only the target's tokens are compared here; read `drafts accepted X of Y` 11from the engine log for each arm (expect within +-3 points). 12""" 13import json 14import sys 15import urllib .request 16 17PROMPTS = [ 18"Write a 200 word story about a lighthouse keeper who finds a message in a bottle." , 19"Explain how a binary search tree stays balanced, with a short Python example." , 20"List the planets of the solar system with one fact each." , 21"Translate to French and then explain the grammar: 'The quick brown fox jumps over the lazy dog.'" , 22"Write a C function that reverses a singly linked list and explain its complexity." , 23] 24 25 26def haystack (n_entries ): 27w = ["amber" ,"birch" ,"cedar" ,"delta" ,"ember" ,"fjord" ,"grove" ,"harbor" ,"iris" ,"juniper" ] 28return "\n" .join ( 29f"Entry { i } : the { w [( i * 3 ) % 10 ] } station { ( i * 7 ) % 997 } logged a reading of { ( i * 31 ) % 1009 } ." 30for i in range (n_entries ) 31 ) 32 33 34def ask (url ,key ,content ,n ): 35body = json .dumps ({"model" :"qwen3.8-flash-next-ud-q4_k_xl" ,"messages" : [{"role" :"user" ,"content" :content }], 36"max_tokens" :n ,"temperature" :0.0 ,"chat_template_kwargs" : {"enable_thinking" :False }}).encode () 37hdr = {"Content-Type" :"application/json" } 38if key : 39hdr ["Authorization" ]= "Bearer " + key 40d = json .load (urllib .request .urlopen (urllib .request .Request (url ,body ,hdr ),timeout = 3600 )) 41return d ["choices" ][0 ]["message" ]["content" ],d ["usage" ] 42 43 44def main (argv ): 45if len (argv )>= 3 and argv [0 ]== "compare" : 46a ,b = (json .load (open (p ))for p in argv [1 :3 ]) 47bad = 0 48for k in a : 49same = a [k ]["text" ]== b .get (k , {}).get ("text" ) 50"PASS" if same else "FAIL" ),k ,f"( { a [ k ][ 'completion_tokens' ] } vs { b . get ( k , {}). get ( 'completion_tokens' ) } tokens)" ) 51bad += not same 52"PARITY" ,"OK" if not bad else f"BROKEN ( { bad } differ)" ) 53return 1 if bad else 0 54if len (argv )>= 2 and argv [0 ]== "dump" : 55url = "http://127.0.0.1:8000/v1/chat/completions" 56key = None 57words = 1100 58i = 2 59while i < len (argv ): 60if argv [i ]== "--url" : 61url = argv [i + 1 ] 62elif argv [i ]== "--key-file" : 63key = open (argv [i + 1 ]).read ().strip () 64elif argv [i ]== "--long-words" : 65words = int (argv [i + 1 ]) 66i += 2 67out = {} 68for n ,p in enumerate (PROMPTS ): 69t ,u = ask (url ,key ,p ,256 ) 70out [f"short { n } " ]= {"text" :t ,"completion_tokens" :u ["completion_tokens" ],"prompt_tokens" :u ["prompt_tokens" ]} 71t ,u = ask (url ,key ,"Summarise the log below in three sentences.\n" + haystack (words ),256 ) 72out ["long" ]= {"text" :t ,"completion_tokens" :u ["completion_tokens" ],"prompt_tokens" :u ["prompt_tokens" ]} 73json .dump (out ,open (argv [1 ],"w" ),indent = 1 ) 74k :v ["prompt_tokens" ]for k ,v in out .items ()}) 75return 0 76__doc__ ) 77return 2 78 79 80if __name__ == "__main__" : 81sys .exit (main (sys .argv [1 :]))