okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ea9a58d8a
main
1"""Builds the scenario of tools/dflash2/serve_test.py from the prompt id files of the DFlash2 experiments. 2 3python mk_serve_scenario.py <prompt_dir> <tokenizer_dir> <out.json> [max_new=100] 4 5prompt_dir holds <name>.prompt.ids (comma separated token ids of a chat-templated prompt). Conversations: a (three turns), then b (a different conversation, so a's 6live state is replaced), then a's fourth turn (a parked or checkpointed conversation resumes), c (two turns), d (one). 7""" 8import json 9import sys 10from pathlib import Path 11 12REPO = Path (__file__ ).resolve ().parents [2 ] 13sys .path .insert (0 ,str (REPO / "tools" )) 14sys .path .insert (0 ,str (REPO )) 15import strata_tokenizer as ST # noqa: E402 16 17 18def main (): 19pdir ,tdir ,out = Path (sys .argv [1 ]),Path (sys .argv [2 ]),sys .argv [3 ] 20max_new = int (sys .argv [4 ])if len (sys .argv )> 4 else 100 21vocab = json .loads ((tdir / "vocab.json" ).read_text (encoding = "utf-8" )) 22toks = [None ]* len (vocab ) 23for t ,i in vocab .items (): 24toks [i ]= t 25tok = ST .Tokenizer (toks , (tdir / "merges.txt" ).read_text (encoding = "utf-8" ).split ("\n" ),json .loads ((tdir / "token_type.json" ).read_text ())) 26 27def ids (name ): 28return [int (x )for x in (pdir / (name + ".prompt.ids" )).read_text ().strip ().split ("," )] 29 30def follow (text ): 31return tok .encode ("<|im_end|>\n<|im_start|>user\n" + text + "<|im_end|>\n<|im_start|>assistant\n" ,parse_special = True ) 32 33reqs = [ 34 {"name" :"a1" ,"ids" :ids ("chat_explain" )}, 35 {"name" :"a2" ,"after" :"a1" ,"follow" :follow ("Now say the same in two short sentences." )}, 36 {"name" :"a3" ,"after" :"a2" ,"follow" :follow ("Give one concrete example of it." )}, 37 {"name" :"b1" ,"ids" :ids ("code_py" )}, 38 {"name" :"a4" ,"after" :"a3" ,"follow" :follow ("Thanks. Last question: what is the main limit of this idea?" )}, 39 {"name" :"c1" ,"ids" :ids ("json_extract" )}, 40 {"name" :"c2" ,"after" :"c1" ,"follow" :follow ("Now list only the keys." )}, 41 {"name" :"d1" ,"ids" :ids ("tool_call" )}, 42 ] 43json .dump ({"max_new" :max_new ,"requests" :reqs },open (out ,"w" )) 44"scenario with" ,len (reqs ),"requests ->" ,out ) 45 46 47if __name__ == "__main__" : 48main ()