okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
407ea8192
main
1#!/usr/bin/env python3 2"""Create a private, pretokenized input for comparable IQ2_XS benchmarking. 3 4This script does NOT upload, distribute or print the input text. It uses the 5tokenizer of the published Strata source checkout and makes exactly 28,912 6tokens. A different text is a comparable test workload, not an exact replay 7of the historical medical prompt. 8""" 9from __future__import annotations 10 11import argparse 12import hashlib 13from pathlib import Path 14import sys 15 16 17def main ()-> int : 18ap = argparse .ArgumentParser (description = __doc__ ) 19ap .add_argument ("--source-root" ,type = Path ,required = True , 20help = "Checkout of pinned benchmark source commit" ) 21ap .add_argument ("--gguf" ,type = Path ,required = True , 22help = "IQ2_XS model GGUF shard 1" ) 23ap .add_argument ("--text" ,type = Path ,required = True , 24help = "Local UTF-8 text of your choice; never uploaded" ) 25ap .add_argument ("--out" ,type = Path ,required = True , 26help = "New output file containing integer token IDs" ) 27ap .add_argument ("--tokens" ,type = int ,default = 28912 ) 28args = ap .parse_args () 29if args .tokens < 2 : 30ap .error ("--tokens must be >= 2" ) 31source = args .source_root .resolve () 32sys .path .insert (0 ,str (source / "tools" )) 33from strata_tokenizer import Tokenizer 34 35text = args .text .read_text (encoding = "utf-8" ).strip () 36if not text : 37ap .error ("--text input is empty" ) 38tokenizer = Tokenizer .from_gguf (args .gguf .resolve ()) 39ids = tokenizer .encode (text ) 40if not ids : 41ap .error ("Tokenizer returned zero tokens" ) 42# Repeat a user's locally chosen document if it is shorter than the target. 43# Re-tokenize the concatenation to preserve BPE boundaries. 44if len (ids )< args .tokens : 45chunk = text + "\n\n" 46count = max (2 ,args .tokens // len (ids )+ 2 ) 47while True : 48ids = tokenizer .encode (chunk * count ) 49if len (ids )>= args .tokens : 50break 51count *= 2 52ids = ids [:args .tokens ] 53target = args .out .resolve () 54target .parent .mkdir (parents = True ,exist_ok = True ) 55data = (" " .join (str (i )for i in ids )+ "\n" ).encode ("utf-8" ) 56with target .open ("xb" )as f : 57f .write (data ) 58f"Wrote { len ( ids ) } tokens to { target } " ) 59f"SHA256: { hashlib . sha256 ( data ). hexdigest (). upper () } " ) 60"Input is local and differs from historical benchmark workload." ) 61return 0 62 63 64if __name__ == "__main__" : 65raise SystemExit (main ())