Slayer1B-1.09-Instruct-26.11: weights, card, notes, training code, manifests and results (history squashed; training data not published)
6071ec5 Download training/code/make_s2.py from SlayerLab/Slayer1B-1.09-Instruct-26.11: direct link, hf CLI and curl.
- Browser
- Download file 5.53 kB
-
https://huggingface.co/SlayerLab/Slayer1B-1.09-Instruct-26.11/resolve/main/training/code/make_s2.py
- Command line
-
hf download hf://SlayerLab/Slayer1B-1.09-Instruct-26.11/training/code/make_s2.py
-
curl -L -o make_s2.py https://huggingface.co/SlayerLab/Slayer1B-1.09-Instruct-26.11/resolve/main/training/code/make_s2.py
5.53 kB
| """s2 = s1 with three changes aimed at the E1 failure modes (see PLAN.md): | |
| 1. agentic tool rows limited to <= 3 calls (long call chains taught "keep calling"); | |
| 2. + programmatic tool-loop examples (synth_tools.py; tools disjoint from the eval suite), PL-weighted; | |
| 3. 12k chat rows (no system turn) get a tool list in a system turn and keep their direct answer (no call), so | |
| tools being available no longer implies calling one. | |
| Token-level insertion of the system turn is exact: segments are tokenised at special-token boundaries (chatfmt). | |
| python make_s2.py data/s1_toolcall data/s2_toolcall [--synth 30000 --chat-with-tools 12000] | |
| """ | |
| from __future__ import annotations | |
| import argparse | |
| import hashlib | |
| import json | |
| import random | |
| import shutil | |
| from collections import Counter | |
| from pathlib import Path | |
| import numpy as np | |
| import pyarrow as pa | |
| import pyarrow.parquet as pq | |
| from tokenizers import Tokenizer | |
| from chatfmt import Fmt | |
| import synth_tools as S | |
| TOK = __import__("os").environ.get("SLAYER_TOKENIZER", "tokenizer.json") | |
| SCHEMA = pa.schema([("id", pa.string()), ("input_ids", pa.binary()), ("loss_mask", pa.binary()), ("n_tokens", pa.int64()), | |
| ("source", pa.string()), ("comp", pa.string()), ("language", pa.string()), ("is_tool", pa.bool_()), | |
| ("n_target", pa.int64()), ("n_calls", pa.int64())]) | |
| def rec(id_, ids, lab, source, comp, lang, is_tool, n_calls): | |
| return {"id": id_, "input_ids": np.array(ids, dtype=np.uint16).tobytes(), | |
| "loss_mask": np.array([x != -100 for x in lab], dtype=np.uint8).tobytes(), "n_tokens": len(ids), | |
| "source": source, "comp": comp, "language": lang, "is_tool": is_tool, "n_target": sum(1 for x in lab if x != -100), | |
| "n_calls": n_calls} | |
| def main(): | |
| ap = argparse.ArgumentParser() | |
| ap.add_argument("src") | |
| ap.add_argument("dst") | |
| ap.add_argument("--synth", type=int, default=30000) | |
| ap.add_argument("--synth-val", type=int, default=1500) | |
| ap.add_argument("--chat-with-tools", type=int, default=12000) | |
| ap.add_argument("--max-agentic-calls", type=int, default=3) | |
| a = ap.parse_args() | |
| src, dst = Path(a.src), Path(a.dst) | |
| (dst / "eval").mkdir(parents=True, exist_ok=True) | |
| f = Fmt(Tokenizer.from_file(TOK)) | |
| sys_head = [f.ims] + f.enc("system\n") | |
| stats = Counter() | |
| for split, n_synth, seed in (("train", a.synth, 20261125), ("val", a.synth_val, 777)): | |
| rows = pq.read_table(src / f"{split}.parquet").to_pylist() | |
| out = [] | |
| rnd = random.Random(f"s2|{split}") | |
| chat_idx = [i for i, r in enumerate(rows) if not r["is_tool"]] | |
| rnd.shuffle(chat_idx) | |
| want = a.chat_with_tools if split == "train" else a.chat_with_tools // 50 | |
| convert = set() | |
| for i in chat_idx: | |
| ids = np.frombuffer(rows[i]["input_ids"], dtype=np.uint16) | |
| if list(ids[1:1 + len(sys_head)]) != sys_head: # only rows without a system turn | |
| convert.add(i) | |
| if len(convert) >= want: | |
| break | |
| for i, r in enumerate(rows): | |
| if r["is_tool"] and r["n_calls"] > a.max_agentic_calls: | |
| stats[f"{split}:dropped_long_chain"] += 1 | |
| continue | |
| if i in convert: | |
| names = rnd.sample(list(S.TOOLS), rnd.randint(2, 4)) | |
| block = f.tools_block([{"name": n, **S.TOOLS[n]} for n in names]) | |
| ins = sys_head + f.enc(block) + [f.ime] + f.nl | |
| ids = np.frombuffer(r["input_ids"], dtype=np.uint16).tolist() | |
| m = np.frombuffer(r["loss_mask"], dtype=np.uint8).tolist() | |
| ids2, m2 = ids[:1] + ins + ids[1:], m[:1] + [0] * len(ins) + m[1:] | |
| if len(ids2) <= 4096: | |
| r = {**r, "id": r["id"] + "+tools", "input_ids": np.array(ids2, dtype=np.uint16).tobytes(), | |
| "loss_mask": np.array(m2, dtype=np.uint8).tobytes(), "n_tokens": len(ids2), "comp": r["comp"] + "+tools_no_call"} | |
| stats[f"{split}:chat_with_tools"] += 1 | |
| out.append(r) | |
| for j, x in enumerate(S.generate(n_synth, seed=seed)): | |
| ids, lab = f.render(x["messages"], x["tools"]) | |
| n_calls = sum(len(m.get("tool_calls") or []) for m in x["messages"]) | |
| sid = "synth-" + hashlib.sha1(f"{split}|{j}".encode()).hexdigest()[:16] | |
| out.append(rec(sid, ids, lab, "synth_tools", "tool" if n_calls else "tool_no_call", x["lang"], bool(n_calls), n_calls)) | |
| stats[f"{split}:synth_{x['kind']}"] += 1 | |
| pq.write_table(pa.Table.from_pylist(out, schema=SCHEMA), dst / f"{split}.parquet", compression="zstd") | |
| stats[f"{split}:records"] = len(out) | |
| stats[f"{split}:tokens"] = sum(r["n_tokens"] for r in out) | |
| stats[f"{split}:target_tokens"] = sum(r["n_target"] for r in out) | |
| stats[f"{split}:tool_records"] = sum(r["is_tool"] for r in out) | |
| for fn in ("chat_prompts.jsonl", "tool_replay.jsonl"): | |
| shutil.copy(src / "eval" / fn, dst / "eval" / fn) | |
| def sha(p): | |
| return hashlib.sha256(Path(p).read_bytes()).hexdigest() | |
| man = {"derived_from": str(src), "args": vars(a), "stats": dict(stats), | |
| "files": {p.name: sha(p) for p in [dst / "train.parquet", dst / "val.parquet", dst / "eval/chat_prompts.jsonl", dst / "eval/tool_replay.jsonl"]}} | |
| (dst / "manifest.json").write_text(json.dumps(man, indent=1), encoding="utf-8") | |
| print(json.dumps(man["stats"], indent=1)) | |
| if __name__ == "__main__": | |
| main() | |