#!/usr/bin/env python3 """Request file for one Original `--serve` process of the quality gate (docs/quality-gate.md). usage: q_mkreqs.py CASES_DIR OUT --read SPEC[,SPEC...] [--free N] [--free-keys SET[/SET...]] SPEC is a case name (CASES_DIR/.ids) optionally followed by `:key=value[:key=value]` request keys of the Original's serve protocol (e.g. `O0:pcie_frac=0`). Each becomes `GEN 1 `: the whole sequence (prompt and the tokens another run produced) is read once and, with STRATA_LOGPOS set, every row's log-probabilities are logged (teacher forcing). `--free N` then adds a free greedy request of 128 tokens for each of the first N corpus prompts (O0..O prompts, cut to n_prompt); --free-keys gives one SET of request keys (`k=v,k=v`) per pass over the N prompts, passes separated by '/' (e.g. `spec_min_p=0.5/spec_min_p=0`). OUT.names lists one label per request, in order, for the analysis. """ import json, sys def main(argv): cases, out = argv[0], argv[1] read, free, keysets = [], 0, [[]] i = 2 while i < len(argv): if argv[i] == "--read": read = [s for s in argv[i + 1].split(",") if s]; i += 2 elif argv[i] == "--free": free = int(argv[i + 1]); i += 2 elif argv[i] == "--free-keys": keysets = [[k for k in s.split(",") if k] for s in argv[i + 1].split("/")]; i += 2 else: raise SystemExit("bad option " + argv[i]) meta = json.load(open(cases + "/meta.json")) lines, names = [], [] for spec in read: name, *kv = spec.split(":") ids = open(f"{cases}/{name}.ids").read().strip() lines.append(" ".join(["GEN 1"] + kv + [ids])); names.append("read:" + spec) for rep, keys in enumerate(keysets): for p in range(free): ids = open(f"{cases}/O{p}.ids").read().strip().split(",")[: meta[f"O{p}"]["n_prompt"]] lines.append(" ".join(["GEN 128"] + keys + [",".join(ids)])); names.append(f"free:{p}:{rep}") lines.append("QUIT") open(out, "w").write("\n".join(lines) + "\n") open(out + ".names", "w").write("\n".join(names) + "\n") print(len(names), "requests ->", out) if __name__ == "__main__": main(sys.argv[1:])