okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Int3 merge f-0291-bw-df2serve (eeb21d0e4); generate.cpp: draft_df2 and draft_long both keptea9a58d8a

main
2.1 KiB48 linesraw
1"""Builds the scenario of tools/dflash2/serve_test.py from the prompt id files of the DFlash2 experiments.
2
3    python 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():
19    pdir, tdir, out = Path(sys.argv[1]), Path(sys.argv[2]), sys.argv[3]
20    max_new = int(sys.argv[4]) if len(sys.argv) > 4 else 100
21    vocab = json.loads((tdir / "vocab.json").read_text(encoding="utf-8"))
22    toks = [None] * len(vocab)
23    for t, i in vocab.items():
24        toks[i] = t
25    tok = ST.Tokenizer(toks, (tdir / "merges.txt").read_text(encoding="utf-8").split("\n"), json.loads((tdir / "token_type.json").read_text()))
26
27    def ids(name):
28        return [int(x) for x in (pdir / (name + ".prompt.ids")).read_text().strip().split(",")]
29
30    def follow(text):
31        return tok.encode("<|im_end|>\n<|im_start|>user\n" + text + "<|im_end|>\n<|im_start|>assistant\n", parse_special=True)
32
33    reqs = [
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    ]
43    json.dump({"max_new": max_new, "requests": reqs}, open(out, "w"))
44    print("scenario with", len(reqs), "requests ->", out)
45
46
47if __name__ == "__main__":
48    main()