okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6e1085c1d
main
1"""Build the bench prompts at exact token counts with Strata's own tokenizer (run in the runner's venv). 2 3usage: gen.py SRC_ROOT TOKENIZER_DIR > prompts.jsonl 4Each prompt is "Run id: <uuid>" + a slice of the repository text (tools/needle_bench.py's haystack) + 5one question. The slice length is binary-searched so that the server-side prompt (content + the chat 6template's 12 tokens) lands on the target. 7""" 8 9import json 10import sys 11import uuid 12from pathlib import Path 13 14src ,tok_dir = Path (sys .argv [1 ]),Path (sys .argv [2 ]) 15sys .path .insert (0 ,str (src / "tools" )) 16import needle_bench # noqa: E402 17import strata_tokenizer as ST # noqa: E402 18 19TEMPLATE_TOKENS = 12 20ASK = "\n\nSummarize the material above: what it is, its main parts, and how they fit together." 21PLAN = [("cold-first-request" ,32768 ,False ), ("warmup-short" ,4096 ,False ), ("warmup-long" ,32768 ,False )] 22PLAN += [(f" { t } -run { i } " ,t ,True )for t in (4096 ,32768 ,128000 )for i in (1 ,2 ,3 )] 23 24vocab = json .loads ((tok_dir / "vocab.json" ).read_text (encoding = "utf-8" )) 25tokens = [None ]* len (vocab ) 26for t ,i in vocab .items (): 27tokens [i ]= t 28tk = ST .Tokenizer (tokens , (tok_dir / "merges.txt" ).read_text (encoding = "utf-8" ).split ("\n" ), 29json .loads ((tok_dir / "token_type.json" ).read_text ())) 30text = needle_bench .haystack (1_000_000 ) 31 32for n , (label ,target ,counted )in enumerate (PLAN ): 33head = f"Run id: { uuid . uuid4 () } \n\n" 34offset = n * 7919 35goal = target - TEMPLATE_TOKENS 36 37def count (c :int )-> int : 38return len (tk .encode (head + text [offset :offset + c ]+ ASK )) 39 40lo ,hi = 0 ,len (text )- offset 41while lo < hi :# largest slice whose prompt is <= goal tokens 42mid = (lo + hi + 1 )// 2 43if count (mid )<= goal : 44lo = mid 45else : 46hi = mid - 1 47content = head + text [offset :offset + lo ]+ ASK 48json .dumps ({"label" :label ,"target" :target ,"counted" :counted ,"offset" :offset , 49"content_tokens" :len (tk .encode (content )),"content" :content }),flush = True )