Download training/code/gsm_en.py from SlayerLab/Slayer1B-1.10-Instruct-30.11: direct link, hf CLI and curl.
- Browser
- Download file 1.27 kB
-
https://huggingface.co/SlayerLab/Slayer1B-1.10-Instruct-30.11/resolve/main/training/code/gsm_en.py
- Command line
-
hf download hf://SlayerLab/Slayer1B-1.10-Instruct-30.11/training/code/gsm_en.py
-
curl -L -o gsm_en.py https://huggingface.co/SlayerLab/Slayer1B-1.10-Instruct-30.11/resolve/main/training/code/gsm_en.py
1.27 kB
| """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) | |