AsianPlayer/TriDrive / code /weak /run_gpt_calibration.py
AsianPlayer's picture
download
raw
4.07 kB
"""cwm3/weak/run_gpt_calibration.py — chunked driver for a GPT weak-label batch through run_gpt.py (TRAIN-only guard inside),
with the pre-stated spend watch after every chunk (default 20 clips):
abort when mean cost per completed request x (2 passes x n_total) > --abort-usd (calibration: $12),
or needs_reconcile rate > 5 %, or cumulative ledger spend >= --stop-total-usd ($90).
Passes run in order observe_prefix -> ground_relation (each chunk of the second pass needs the first pass's returns).
python run_gpt_calibration.py --clips <txt> --stamp <UTC> [--chunk 20] [--n-total 100] [--model gpt-5 --preset economy --detail high --max-output-tokens 6000]
Exit codes: 0 ok, 2 ledger budget stop (from run_gpt), 3 watch abort, 1 other error. Log: cwm3/weak/logs/gpt_batch_<stamp>.log
"""
import argparse, datetime as dt, subprocess, sys
from pathlib import Path
HERE = Path(__file__).resolve().parent
PY = sys.executable
def log(fh, msg):
line = f"[{dt.datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%SZ')}] {msg}"
print(line, flush=True); fh.write(line + "\n"); fh.flush()
def main():
ap = argparse.ArgumentParser()
ap.add_argument("--clips", required=True); ap.add_argument("--stamp", required=True)
ap.add_argument("--chunk", type=int, default=20); ap.add_argument("--n-total", type=int, default=None)
ap.add_argument("--model", default="gpt-5"); ap.add_argument("--preset", default="economy"); ap.add_argument("--detail", default="high")
ap.add_argument("--max-output-tokens", type=int, default=6000)
ap.add_argument("--passes", default="observe_prefix,ground_relation")
ap.add_argument("--abort-usd", type=float, default=12.0); ap.add_argument("--stop-total-usd", type=float, default=90.0)
a = ap.parse_args()
clips = [l.strip() for l in Path(a.clips).read_text().splitlines() if l.strip() and not l.startswith("#")]
n_total = a.n_total or len(clips)
logs = HERE / "logs"; logs.mkdir(exist_ok=True)
fh = open(logs / f"gpt_batch_{a.stamp}.log", "a")
log(fh, f"START batch stamp={a.stamp} clips={len(clips)} chunk={a.chunk} model={a.model} preset={a.preset} detail={a.detail} "
f"max_out={a.max_output_tokens} passes={a.passes} abort_usd={a.abort_usd} stop_total_usd={a.stop_total_usd}")
chunks = [clips[i:i + a.chunk] for i in range(0, len(clips), a.chunk)]
for p in a.passes.split(","):
for ci, ch in enumerate(chunks, 1):
cf = logs / f"chunk_{a.stamp}_{p}_{ci:02d}.txt"; cf.write_text("".join(f"{c}\n" for c in ch))
cmd = [PY, str(HERE / "run_gpt.py"), "--model", a.model, "--pass", p, "--preset", a.preset, "--detail", a.detail,
"--clips", str(cf), "--mode", "sync", "--max-output-tokens", str(a.max_output_tokens)]
log(fh, f"=== pass {p} chunk {ci}/{len(chunks)} ({len(ch)} clips): {' '.join(cmd[1:])}")
r = subprocess.run(cmd, stdout=fh, stderr=subprocess.STDOUT, text=True)
fh.flush()
log(fh, f"run_gpt exit {r.returncode}")
if r.returncode == 2:
log(fh, "LEDGER BUDGET STOP -> abort"); return 2
if r.returncode not in (0,):
log(fh, f"run_gpt returned {r.returncode}; continuing to the watch step")
w = subprocess.run([PY, str(HERE / "gpt_calibration.py"), "watch", "--clips", a.clips, "--n-total", str(n_total), "--model", a.model,
"--preset", a.preset, "--abort-usd", str(a.abort_usd), "--stop-total-usd", str(a.stop_total_usd)],
capture_output=True, text=True)
log(fh, "WATCH after chunk:\n" + w.stdout.strip() + (("\n" + w.stderr.strip()) if w.stderr.strip() else ""))
if w.returncode == 3:
log(fh, "WATCH ABORT -> stopping the batch"); return 3
if r.returncode not in (0,):
log(fh, f"run_gpt exit {r.returncode} -> stopping the batch for inspection"); return 1
log(fh, "DONE all passes / chunks")
return 0
if __name__ == "__main__":
sys.exit(main())

Xet Storage Details

Size:
4.07 kB
·
Xet hash:
682abd8d877a6ad34985fcb78dee663fe908b9ebdf9c1f4a2638d78be416b4a3

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.