interplane.Get Omega
Read in your language

gpu-head-to-head

aien-dev/gpu-head-to-head

Brought by drakestapleton

branch main Branches Tags History

gpu-head-to-head / bench / make_prompts.py

72 lines · 3177 bytes Raw Blame History
1#!/usr/bin/env python3
2"""Generate prompts/decode.jsonl and prompts/prefill.jsonl deterministically.
3
4Needs the `tokenizers` package (run inside the pinned vLLM container, see bench/README) and the
5checkpoint's tokenizer.json. Prefill documents are calibrated so that the chat-rendered prompt
6(Qwen3.6 template, thinking off) lands on the target token count.
7"""
8import json
9import random
10import sys
11
12from tokenizers import Tokenizer
13
14MODEL = sys.argv[1]
15OUT = sys.argv[2]
16tok = Tokenizer.from_file(MODEL + "/tokenizer.json")
17
18TOPICS = [
19 "the history of the printing press", "how a river delta forms", "the life cycle of a star",
20 "building a wooden boat by hand", "the first transatlantic telegraph cable",
21 "how bees choose a new hive site", "a day in a medieval market town", "the physics of a bicycle",
22 "how glaciers shape valleys", "the invention of the mechanical clock",
23 "a lighthouse keeper's winter", "how coral reefs grow", "the design of Roman aqueducts",
24 "a journey along the Silk Road", "how volcanoes create new islands", "the story of paper money",
25]
26
27
28def chat_len(text):
29 # Qwen3.6 chat template, thinking off: user turn, assistant header, empty think block.
30 rendered = ("<|im_start|>user\n" + text + "<|im_end|>\n<|im_start|>assistant\n"
31 "<think>\n\n</think>\n\n")
32 return len(tok.encode(rendered, add_special_tokens=False).ids)
33
34
35WORDS = ("river stone light market harbor engine winter garden letter mountain bridge village "
36 "signal window forest copper lantern season voyage archive canal meadow orchard tower "
37 "compass ledger quarry furnace beacon cellar harvest pilgrim chapel mill granary").split()
38VERBS = "carried crossed watched built opened measured repaired followed recorded traded".split()
39
40
41def sentence(rng):
42 return "The %s near the %s %s the %s before the %s %s again." % (
43 rng.choice(WORDS), rng.choice(WORDS), rng.choice(VERBS), rng.choice(WORDS),
44 rng.choice(WORDS), rng.choice(VERBS))
45
46
47def document(target, seed):
48 rng = random.Random(seed)
49 question = "\n\nQuestion: in one sentence, what is the document above about?"
50 sents = []
51 while True:
52 sents.append(sentence(rng))
53 if chat_len(" ".join(sents) + question) >= target:
54 break
55 # trim back to the closest count not above the target
56 while chat_len(" ".join(sents) + question) > target and len(sents) > 1:
57 sents.pop()
58 text = " ".join(sents) + question
59 return text, chat_len(text)
60
61
62with open(OUT + "/decode.jsonl", "w") as f:
63 for i, t in enumerate(TOPICS):
64 text = ("Write a long, detailed essay of at least 600 words about %s. "
65 "Use several paragraphs and do not stop early." % t)
66 f.write(json.dumps({"id": "d%02d" % i, "text": text, "chat_tokens": chat_len(text)}) + "\n")
67
68with open(OUT + "/prefill.jsonl", "w") as f:
69 for name, target in (("p256", 256), ("p512", 512), ("p2k", 2048), ("p8k", 8192)):
70 text, n = document(target, seed=target)
71 f.write(json.dumps({"id": name, "text": text, "chat_tokens": n, "target": target}) + "\n")
72 print(name, target, n, file=sys.stderr)