Aleksander22's picture
Slayer1B-1.09-Instruct-26.11: weights, card, notes, training code, manifests and results (history squashed; training data not published)
6071ec5
Raw History Blame Contribute Delete
2.55 kB
"""Release check: the exported package (config.json + tokenizer.json + model.safetensors, the files a HF repo would hold)
must give the same next-token logits as the native training checkpoint. Loads the package with the independent CodeSOTA
loader (research/common/slayer_model.py, fp32) and the checkpoint with model_io (fp32), compares on chat-formatted prompts.
python logit_check.py <ckpt.pt> <package dir> [--out results/logit_check_<label>.json]
"""
import argparse
import hashlib
import json
import sys
from pathlib import Path
import torch
from tokenizers import Tokenizer
sys.path.insert(0, "/workspace/benchrepo/research/common")
import slayer_model # noqa: E402
from chatfmt import Fmt # noqa: E402
from model_io import load # noqa: E402
PROMPTS = [[{"role": "user", "content": "Ile to jest 17 razy 23?"}],
[{"role": "user", "content": "What is the capital of Canada?"}],
[{"role": "user", "content": "Napisz krótki wiersz o jesieni."}],
[{"role": "user", "content": "Mam na imię Ola."}, {"role": "assistant", "content": "Miło mi, Olu!"}, {"role": "user", "content": "Jak mam na imię?"}]]
def main():
ap = argparse.ArgumentParser()
ap.add_argument("ckpt")
ap.add_argument("pkg")
ap.add_argument("--out", default=None)
a = ap.parse_args()
f = Fmt(Tokenizer.from_file(str(Path(a.pkg) / "tokenizer.json")))
nat, cfg, _ = load(a.ckpt, device="cuda", dtype=torch.float32)
nat.eval()
pk = slayer_model.Slayer(a.pkg, device="cuda", dtype=torch.float32)
rows = []
with torch.inference_mode():
for msgs in PROMPTS:
ids = f.prompt_ids(msgs, None)
ln, _ = nat(torch.tensor([ids], device="cuda"))
ln = ln[0].float()
lp = pk.logits(torch.tensor([ids], device="cuda"))
lp = (lp[0] if lp.dim() == 3 else lp).float()
d = (ln - lp).abs()
rows.append({"n_tokens": len(ids), "max_abs_diff": float(d.max()), "mean_abs_diff": float(d.mean()),
"argmax_agree": float((ln.argmax(-1) == lp.argmax(-1)).float().mean()), "logit_scale": float(ln.abs().mean())})
res = {"ckpt": a.ckpt, "pkg": a.pkg, "safetensors_sha256": hashlib.sha256((Path(a.pkg) / "model.safetensors").read_bytes()).hexdigest(),
"rows": rows, "ok": all(r["argmax_agree"] == 1.0 and r["max_abs_diff"] < 1e-2 for r in rows)}
print(json.dumps(res, indent=1))
if a.out:
Path(a.out).write_text(json.dumps(res, indent=1))
if __name__ == "__main__":
main()