#!/usr/bin/env python3 """Second distinct long prompt: real prefill rate, no graph-capture cost.""" import json, time, urllib.request URL = "http://127.0.0.1:8001/v1/chat/completions" def make_prompt(seed): facts = [ "A ring buffer owns its storage and never reallocates during operation. ", "The backpressure policy drops oldest frames when the watermark is exceeded. ", "Lock-free slots are handed off via acquire/release fences on two indices. ", "The telemetry sink batches spans and flushes on size or interval bounds. ", ] body_txt = "".join(facts[(i + seed) % 4] for i in range(40)) system = ("You are a senior systems engineer. Technical context: " + body_txt + "Answer concisely with code only, no prose.") return [ {"role": "system", "content": system}, {"role": "user", "content": "Write the flush function in Rust."}, ] def run(seed): body = {"messages": make_prompt(seed), "max_tokens": 8, "temperature": 0, "stream": True, "chat_template_kwargs": {"enable_thinking": False}} req = urllib.request.Request(URL, data=json.dumps(body).encode(), headers={"Content-Type": "application/json"}) timings = None with urllib.request.urlopen(req, timeout=300) as resp: for raw in resp: line = raw.decode(errors="replace").strip() if not line.startswith("data:"): continue p = line[5:].strip() if p == "[DONE]": break try: j = json.loads(p) except Exception: continue if "timings" in j: timings = j["timings"] return timings # two distinct prompts: first pays any capture, second is the clean measurement t1 = run(0) print("warmup:", t1["prompt_n"], "tokens @", round(t1["prompt_per_second"], 1), "t/s") t2 = run(2) print("measured:", t2["prompt_n"], "tokens @", round(t2["prompt_per_second"], 1), "t/s")