File size: 1,272 Bytes
53d5fc6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""GSM8K test (1319, EN) zero-shot in the chat template, greedy; exact match of the final number (same parser as gsm_chat_eval.py).
  python gsm_en.py CKPT OUTDIR RANK WORLD"""
import json, os, sys
from pathlib import Path
import torch
import pyarrow.parquet as pq
from huggingface_hub import hf_hub_download
from tokenizers import Tokenizer
from chatfmt import Fmt
from gsm_chat_eval import gold_of, pred_of
from model_io import generate, load
ck, out, r, w = sys.argv[1], Path(sys.argv[2]), int(sys.argv[3]), int(sys.argv[4])
out.mkdir(parents=True, exist_ok=True)
rows = pq.read_table(hf_hub_download("openai/gsm8k", "main/test-00000-of-00001.parquet", repo_type="dataset", revision="740312add88f")).to_pylist()[r::w]
f = Fmt(Tokenizer.from_file(os.environ["SLAYER_TOKENIZER"])); m, _, _ = load(ck, device="cuda", dtype=torch.bfloat16); m.eval()
with open(out / f"r{r}.jsonl", "w", encoding="utf-8") as fo:
    for x in rows:
        o, stop = generate(m, f.prompt_ids([{"role": "user", "content": x["question"]}]), stop_ids={f.ime, f.bos}, max_new_tokens=512)
        t = f.tok.decode(o); g, p = gold_of(x["answer"]), pred_of(t)
        print(json.dumps({"ok": p is not None and abs(p - g) < 1e-6, "gold": g, "pred": p, "stop": stop, "text": t}), file=fo, flush=True)