REAX-1.4 / engine /bench /karpo_author_run.py
decisionmodels's picture
Engine tree (REAX Engine reax14-release-20261126, 2cccfee) and run instructions
a7e82fd verified
Raw History Blame Contribute Delete
3.14 kB
#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""Baseline: karpo-decision's OWN kit engine (karpo_decision.serve.engine:DecisionIndexEngine, Apache-2.0, pinned commit in
pod_setup.sh) over the same rows, same timing (one request at a time, CUDA-synchronized wall), same output lines as
hfdi_speed.py run. Runs on a disposable rented pod only (third-party code).
python bench/karpo_author_run.py --checkpoint /model/part-karpo --rows lat.jsonl --out runs/author-default.jsonl
python bench/karpo_author_run.py ... --fp8 --triton-attention --graphs # the author's fastest flags
"""
from __future__ import annotations
import argparse
import hashlib
import json
import time
from pathlib import Path
from hfdi_speed import load_rows, probs_of, row_id, stats
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--checkpoint", required=True)
ap.add_argument("--rows", required=True)
ap.add_argument("--out", required=True)
ap.add_argument("--fp8", action="store_true")
ap.add_argument("--triton-attention", action="store_true")
ap.add_argument("--graphs", action="store_true")
ap.add_argument("--limit", type=int, default=0)
a = ap.parse_args()
import torch
from decision_index.engines import Unsupported
from karpo_decision.serve.engine import DecisionIndexEngine
rows = load_rows([a.rows])[: a.limit or None]
t0 = time.perf_counter()
eng = DecisionIndexEngine(checkpoint=a.checkpoint, fp8=a.fp8, triton_attention=a.triton_attention, graphs=a.graphs)
load_s = time.perf_counter() - t0
eng.warmup()
torch.cuda.synchronize()
torch.cuda.reset_peak_memory_stats()
ok = []
out = Path(a.out)
out.parent.mkdir(parents=True, exist_ok=True)
with out.open("w") as f:
for r in rows:
torch.cuda.synchronize()
t = time.perf_counter()
status, answers = "ok", None
try:
resp, _ = eng(r["state"], r["questions"])
answers = {k: probs_of(v) for k, v in resp["answers"].items()}
except Unsupported as exc:
status = "unsupported:" + str(exc)[:120]
torch.cuda.synchronize()
ms = 1000.0 * (time.perf_counter() - t)
if status == "ok":
ok.append(ms)
f.write(json.dumps({"id": row_id(r), "ms": ms, "status": status, "answers": answers,
"n_questions": len(r["questions"])}) + "\n")
summary = {"engine": "karpo-decision author engine", "flags": {"fp8": a.fp8, "triton_attention": a.triton_attention,
"graphs": a.graphs}, "path": getattr(eng, "path", None), "rows_sha256": hashlib.sha256(Path(a.rows).read_bytes()).hexdigest(),
"load_s": round(load_s, 1), "stats": stats(ok), "peak_allocated_bytes": torch.cuda.max_memory_allocated(),
"peak_reserved_bytes": torch.cuda.max_memory_reserved(), "gpu": torch.cuda.get_device_name(0)}
Path(str(out) + ".summary.json").write_text(json.dumps(summary, indent=1))
print(json.dumps(summary, indent=1))
if __name__ == "__main__":
main()