Download mail/decide_speed.py from luokelabs/luoke-bench: direct link, hf CLI and curl.
- Browser
- Download file 3.28 kB
-
https://huggingface.co/datasets/luokelabs/luoke-bench/resolve/main/mail/decide_speed.py
- Command line
-
hf download hf://datasets/luokelabs/luoke-bench/mail/decide_speed.py
-
curl -L -o decide_speed.py https://huggingface.co/datasets/luokelabs/luoke-bench/resolve/main/mail/decide_speed.py
3.28 kB
| #!/usr/bin/env python3 | |
| """Speed across repeated run_decide passes: per mail, the fastest of the passes that ran it, then the median. | |
| Passes are result folders laid out like run_decide's --out (<dir>/<set>/<label>.json). A pass that shared the GPU | |
| with another job is slow on some mails; taking each mail's minimum keeps the uncontended timing. | |
| python3 mail/decide_speed.py # results/decide, decide-pass2, decide-idle | |
| python3 mail/decide_speed.py --passes a=dir1 b=dir2 | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import statistics as st | |
| HERE = os.path.dirname(os.path.abspath(__file__)) | |
| R = os.path.join(HERE, "results") | |
| SETS = ("rewrite", "samples", "real") | |
| def load(d, label, s): | |
| p = os.path.join(d, s, label + ".json") | |
| return json.load(open(p)) if os.path.exists(p) else None | |
| def labels(passes, s): | |
| seen = [] | |
| for _, d in passes: | |
| if os.path.isdir(os.path.join(d, s)): | |
| seen += [f[:-5] for f in sorted(os.listdir(os.path.join(d, s))) if f.endswith(".json") and f[:-5] not in seen] | |
| return seen | |
| def row(passes, label, s): | |
| runs = [(n, load(d, label, s)) for n, d in passes] | |
| runs = [(n, r) for n, r in runs if r] | |
| if not runs: | |
| return None | |
| per = {} | |
| for _, r in runs: | |
| for x in r["results"]: | |
| if x.get("seconds") is not None and "error" not in x: | |
| per.setdefault(x["tag"], []).append(x["seconds"]) | |
| mins = [min(v) for v in per.values()] | |
| return { | |
| "passes": {n: round(st.median([x["seconds"] for x in r["results"] if x.get("seconds") is not None]), 3) for n, r in runs}, | |
| "min_median": round(st.median(mins), 3), | |
| "n": len(mins), | |
| "peak_gb": {n: r.get("peak_gb") for n, r in runs}, | |
| } | |
| def main(): | |
| ap = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| ap.add_argument("--passes", nargs="+", default=[f"1={R}/decide", f"2={R}/decide-pass2", f"idle={R}/decide-idle"], | |
| help="name=dir, in order") | |
| ap.add_argument("--baseline", default="g9", help="label the ratio column compares against") | |
| ap.add_argument("--json", help="also write the rows here") | |
| a = ap.parse_args() | |
| passes = [tuple(p.split("=", 1)) for p in a.passes] | |
| names = [n for n, _ in passes] | |
| out = {} | |
| for s in SETS: | |
| for label in labels(passes, s): | |
| r = row(passes, label, s) | |
| if r: | |
| out[f"{label}/{s}"] = r | |
| print("| group | set | " + " | ".join(f"pass {n}" for n in names) + f" | per-mail min, median | vs {a.baseline} | peak GB |") | |
| print("|---|---|" + "---|" * len(names) + "---|---|---|") | |
| for k, r in out.items(): | |
| label, s = k.split("/") | |
| base = out.get(f"{a.baseline}/{s}") | |
| ratio = f"{r['min_median'] / base['min_median']:.0%}" if base else "—" | |
| peaks = sorted({v for v in r["peak_gb"].values() if v is not None}) | |
| print(f"| {label} | {s} | " + " | ".join(str(r["passes"].get(n, "—")) for n in names) | |
| + f" | {r['min_median']} | {ratio} | {'–'.join(str(p) for p in (peaks[:1] + peaks[-1:] if len(peaks) > 1 else peaks))} |") | |
| if a.json: | |
| json.dump(out, open(a.json, "w"), indent=1) | |
| if __name__ == "__main__": | |
| main() | |