okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
6a74320ca
main
1#!/usr/bin/env python3 2"""chat_tokens.py REPO TOKENIZER_DIR "question" : the token ids of a one-turn chat prompt (thinking off), comma 3separated, for `strata generate --tokens` (the same template as the gates' rbench.py). 4With --decode IDS instead of the question: the text of comma-separated ids.""" 5import json ,sys 6from pathlib import Path 7 8repo ,tdir = Path (sys .argv [1 ]),Path (sys .argv [2 ]) 9sys .path .insert (0 ,str (repo / "tools" )) 10import strata_tokenizer as ST 11 12vocab = json .loads ((tdir / "vocab.json" ).read_text (encoding = "utf-8" )) 13toks = [None ]* len (vocab ) 14for t ,i in vocab .items (): 15toks [i ]= t 16tok = ST .Tokenizer (toks , (tdir / "merges.txt" ).read_text (encoding = "utf-8" ).split ("\n" ), 17json .loads ((tdir / "token_type.json" ).read_text ())) 18if sys .argv [3 ]== "--decode" : 19tok .decode ([int (x )for x in sys .argv [4 ].replace (" " ,"" ).split ("," )if x ])) 20else : 21ids = tok .encode ("<|im_start|>user\n%s<|im_end|>\n<|im_start|>assistant\n<think>\n\n</think>\n\n" % sys .argv [3 ], 22parse_special = True ) 23"," .join (str (i )for i in ids ))