Slayer1B-1.09-Instruct-26.11: weights, card, notes, training code, manifests and results (history squashed; training data not published)
6071ec5 Download training/code/gen_settings.py from SlayerLab/Slayer1B-1.09-Instruct-26.11: direct link, hf CLI and curl.
- Browser
- Download file 4.57 kB
-
https://huggingface.co/SlayerLab/Slayer1B-1.09-Instruct-26.11/resolve/main/training/code/gen_settings.py
- Command line
-
hf download hf://SlayerLab/Slayer1B-1.09-Instruct-26.11/training/code/gen_settings.py
-
curl -L -o gen_settings.py https://huggingface.co/SlayerLab/Slayer1B-1.09-Instruct-26.11/resolve/main/training/code/gen_settings.py
4.57 kB
| """Decoding-settings sweep for a checkpoint: the same prompts (behaviour probes, 20+20 GSM8K chat, 12 tool-loop cases) | |
| under several decoding settings, with cheap automatic metrics (expected keyword, 6-gram loop, token limit hit, GSM exact | |
| match, tool loop end-to-end). Outputs kept for reading. | |
| python gen_settings.py <ckpt> <label> [--settings A,B,C,D,E] -> results/settings/<label>.json + .jsonl | |
| """ | |
| import argparse | |
| import json | |
| import re | |
| from pathlib import Path | |
| import pyarrow.parquet as pq | |
| import torch | |
| from tokenizers import Tokenizer | |
| import probe_suite as PS | |
| import tools_suite as T | |
| from chatfmt import Fmt | |
| from evals import Runner, run_loop | |
| from gsm_chat_eval import gold_of, pred_of | |
| from model_io import generate, load | |
| SETTINGS = {"A_greedy": dict(temperature=0.0, top_p=1.0, repetition_penalty=1.0), | |
| "B_greedy_rep1.1": dict(temperature=0.0, top_p=1.0, repetition_penalty=1.1), | |
| "C_t0.3_p0.9_rep1.1": dict(temperature=0.3, top_p=0.9, repetition_penalty=1.1), | |
| "D_t0.7_p0.9_rep1.05": dict(temperature=0.7, top_p=0.9, repetition_penalty=1.05), | |
| "E_t0.7_p0.9": dict(temperature=0.7, top_p=0.9, repetition_penalty=1.0)} | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("ckpt") | |
| ap.add_argument("label") | |
| ap.add_argument("--settings", default=",".join(SETTINGS)) | |
| ap.add_argument("--max-new", type=int, default=400) | |
| a = ap.parse_args() | |
| m, cfg, _ = load(a.ckpt, device="cuda", dtype=torch.bfloat16) | |
| m.eval() | |
| f = Fmt(Tokenizer.from_file("/workspace/ckpt/tokenizer.json")) | |
| r = Runner(m, f, a.max_new) | |
| gsm = pq.read_table("/workspace/s3src/openai__gsm8k/main/test-00000-of-00001.parquet").to_pylist() | |
| gsm_items = [("en", x["question"], gold_of(x["answer"])) for x in gsm[200:220]] | |
| pl = [json.loads(l) for l in open("data/eval/gsm8k_test_pl.jsonl", encoding="utf-8")] | |
| gsm_items += [("pl", x["question"], x["gold"]) for x in pl[:20]] | |
| cases = T.cases() | |
| tool_cases = [c for c in cases if c["expect_tool"]][1::5][:10] + [c for c in cases if not c["expect_tool"]][:2] | |
| out_dir = Path("results/settings") | |
| out_dir.mkdir(parents=True, exist_ok=True) | |
| fo = open(out_dir / f"{a.label}.jsonl", "w", encoding="utf-8") | |
| summary = {} | |
| for name in a.settings.split(","): | |
| kw = SETTINGS[name] | |
| g = torch.Generator(device="cuda").manual_seed(0) | |
| def reply(messages, tools=None, prefill="", max_new=None, kw=kw, g=g): | |
| ids = f.prompt_ids(messages, tools) + f.enc(prefill) | |
| o, why = generate(m, ids, stop_ids=r.stop, max_new_tokens=max_new or a.max_new, generator=g, device="cuda", **kw) | |
| return prefill + f.tok.decode(o, skip_special_tokens=False), why | |
| r.reply = reply | |
| st = {"probe_key": [], "loop": [], "limit": [], "gsm": [], "tool_e2e": [], "no_tool_ok": []} | |
| for cat, lang, msgs, keys, note in PS.P: | |
| t, why = r.reply(msgs) | |
| k = any(x in t.lower() for x in keys) if keys else None | |
| if k is not None: | |
| st["probe_key"].append(k) | |
| st["loop"].append(PS.rep_loop(t)) | |
| st["limit"].append(why != "stop") | |
| fo.write(json.dumps({"setting": name, "kind": "probe", "cat": cat, "prompt": msgs[-1]["content"], "reply": t, "key_ok": k}, ensure_ascii=False) + "\n") | |
| for lang, q, gold in gsm_items: | |
| t, why = r.reply([{"role": "user", "content": q}]) | |
| p = pred_of(t) | |
| ok = p is not None and abs(p - gold) < 1e-6 | |
| st["gsm"].append(ok) | |
| st["loop"].append(PS.rep_loop(t)) | |
| st["limit"].append(why != "stop") | |
| fo.write(json.dumps({"setting": name, "kind": "gsm", "lang": lang, "prompt": q, "reply": t, "ok": ok}, ensure_ascii=False) + "\n") | |
| for c in tool_cases: | |
| o = run_loop(r, c, forced=False) | |
| if c["expect_tool"]: | |
| fin = o.get("final", "") | |
| ok = bool(o["called"]) and o["valid_args"] and bool(fin) and o.get("note") is None | |
| st["tool_e2e"].append(bool(ok)) | |
| else: | |
| st["no_tool_ok"].append(not o["called"]) | |
| fo.write(json.dumps({"setting": name, "kind": "tool", "prompt": c["prompt"], **o}, ensure_ascii=False) + "\n") | |
| summary[name] = {k: (round(sum(v) / len(v), 3) if v else None) for k, v in st.items()} | {"params": kw} | |
| print(name, json.dumps(summary[name]), flush=True) | |
| (out_dir / f"{a.label}.json").write_text(json.dumps(summary, indent=1)) | |
| if __name__ == "__main__": | |
| main() | |