Slayer1B-1.09-Instruct-26.11: weights, card, notes, training code, manifests and results (history squashed; training data not published)
6071ec5 Download training/code/gsm_chat_eval.py from SlayerLab/Slayer1B-1.09-Instruct-26.11: direct link, hf CLI and curl.
- Browser
- Download file 4.46 kB
-
https://huggingface.co/SlayerLab/Slayer1B-1.09-Instruct-26.11/resolve/main/training/code/gsm_chat_eval.py
- Command line
-
hf download hf://SlayerLab/Slayer1B-1.09-Instruct-26.11/training/code/gsm_chat_eval.py
-
curl -L -o gsm_chat_eval.py https://huggingface.co/SlayerLab/Slayer1B-1.09-Instruct-26.11/resolve/main/training/code/gsm_chat_eval.py
4.46 kB
| """GSM8K in chat format (zero-shot, greedy, the way a user would ask): EN = openai/gsm8k test (1319), PL = the same items | |
| translated by Qwen3-8B (gsm8k_test_pl.jsonl, built by `python gsm_chat_eval.py translate`). Score = exact match of the last | |
| number in the reply (preferring the 'Answer:' / 'Odpowiedź:' line) with the key. Sharded over GPUs like evals.py. | |
| python gsm_chat_eval.py translate --out data/eval/gsm8k_test_pl.jsonl (vLLM venv, 1 GPU) | |
| python gsm_chat_eval.py run <ckpt> --rank r --world w --out results/gsm/<label> (training venv) | |
| """ | |
| import argparse | |
| import json | |
| import re | |
| import sys | |
| from pathlib import Path | |
| GSM = "/workspace/s3src/openai__gsm8k/main/test-00000-of-00001.parquet" | |
| def gold_of(a): | |
| return float(a.split("####")[-1].strip().replace(",", "")) | |
| def pred_of(t): | |
| lines = [l for l in t.strip().splitlines() if re.search(r"(Answer|Odpowied[zź])\s*:", l)] | |
| src = lines[-1].split(":", 1)[1] if lines else t | |
| nums = re.findall(r"-?\d[\d,\s]*(?:[.,]\d+)?", src) | |
| if not nums: | |
| return None | |
| s = nums[-1 if not lines else 0].replace(" ", "").replace(" ", "") | |
| if re.fullmatch(r"-?\d{1,3}(,\d{3})+", s): | |
| s = s.replace(",", "") | |
| s = s.replace(",", ".") | |
| try: | |
| return float(s) | |
| except ValueError: | |
| return None | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("cmd", choices=["translate", "run"]) | |
| ap.add_argument("ckpt", nargs="?") | |
| ap.add_argument("--out", required=True) | |
| ap.add_argument("--rank", type=int, default=0) | |
| ap.add_argument("--world", type=int, default=1) | |
| ap.add_argument("--pl", default="data/eval/gsm8k_test_pl.jsonl") | |
| ap.add_argument("--max-new", type=int, default=512) | |
| ap.add_argument("--n", type=int, default=0, help="first N test items per language (0 = all 1319)") | |
| a = ap.parse_args() | |
| import pyarrow.parquet as pq | |
| rows = pq.read_table(GSM).to_pylist() | |
| cap = int(__import__("os").environ.get("GSM_MAX", "200")) # budget cap per language (set GSM_MAX=0 for no cap) | |
| if cap and a.cmd == "run": | |
| a.n = min(a.n or cap, cap) | |
| if a.n: | |
| rows = rows[: a.n] | |
| if a.cmd == "translate": | |
| from vllm import LLM, SamplingParams | |
| llm = LLM("/workspace/models/Qwen3-8B", dtype="bfloat16", max_model_len=4096, gpu_memory_utilization=0.9) | |
| sysm = ("Przetłumacz poniższe zadanie matematyczne na naturalny, poprawny język polski. Zachowaj wszystkie liczby bez zmian. " | |
| "Zwróć wyłącznie przetłumaczoną treść zadania, bez rozwiązania.") | |
| res = llm.chat([[{"role": "system", "content": sysm}, {"role": "user", "content": r["question"]}] for r in rows], | |
| SamplingParams(temperature=0.0, max_tokens=600), chat_template_kwargs={"enable_thinking": False}) | |
| Path(a.out).parent.mkdir(parents=True, exist_ok=True) | |
| with open(a.out, "w", encoding="utf-8") as f: | |
| for i, (r, o) in enumerate(zip(rows, res)): | |
| f.write(json.dumps({"i": i, "question": o.outputs[0].text.strip(), "gold": gold_of(r["answer"]), | |
| "translated_by": "Qwen/Qwen3-8B@b968826d9c"}, ensure_ascii=False) + "\n") | |
| return | |
| import torch | |
| from tokenizers import Tokenizer | |
| from chatfmt import Fmt | |
| from evals import Runner | |
| from model_io import load | |
| m, cfg, _ = load(a.ckpt, device="cuda", dtype=torch.bfloat16); m.eval() | |
| r = Runner(m, Fmt(Tokenizer.from_file("/workspace/ckpt/tokenizer.json")), a.max_new) | |
| items = [("en", i, x["question"], gold_of(x["answer"])) for i, x in enumerate(rows)] | |
| if Path(a.pl).exists(): | |
| items += [("pl", x["i"], x["question"], x["gold"]) for x in map(json.loads, open(a.pl, encoding="utf-8")) if x["i"] < len(rows)] | |
| items = items[a.rank::a.world] | |
| out = Path(a.out) | |
| out.mkdir(parents=True, exist_ok=True) | |
| with open(out / f"r{a.rank}.jsonl", "w", encoding="utf-8") as f: | |
| for lang, i, q, g in items: | |
| t, why = r.reply([{"role": "user", "content": q}]) | |
| p = pred_of(t) | |
| f.write(json.dumps({"lang": lang, "i": i, "gold": g, "pred": p, "ok": p is not None and abs(p - g) < 1e-6, | |
| "stop": why, "reply": t}, ensure_ascii=False) + "\n") | |
| if __name__ == "__main__": | |
| sys.path.insert(0, str(Path(__file__).parent)) | |
| main() | |