Download code/tests/test_release.py from Lucasgitguy-co/Turbo-Kev-Dictate-1.4B: direct link, hf CLI and curl.
- Browser
- Download file 6 kB
-
https://huggingface.co/Lucasgitguy-co/Turbo-Kev-Dictate-1.4B/resolve/main/code/tests/test_release.py
- Command line
-
hf download hf://Lucasgitguy-co/Turbo-Kev-Dictate-1.4B/code/tests/test_release.py
-
curl -L -o test_release.py https://huggingface.co/Lucasgitguy-co/Turbo-Kev-Dictate-1.4B/resolve/main/code/tests/test_release.py
6 kB
| """tk.release on a tiny fake tree: cards render, every number comes from results/, the check passes, and a stale or | |
| failing result makes it fail. ~/.venvs/turbo-kev-train/bin/python -m pytest tests/test_release.py (or run it)""" | |
| import json | |
| import sys | |
| import tempfile | |
| from pathlib import Path | |
| import torch | |
| from safetensors.torch import save_file | |
| sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) | |
| from tk import release # noqa: E402 | |
| N = release.NAME | |
| def w(p: Path, obj) -> None: | |
| p.parent.mkdir(parents=True, exist_ok=True) | |
| if isinstance(obj, list): | |
| p.write_text("".join(json.dumps(r) + "\n" for r in obj)) | |
| elif isinstance(obj, (bytes, bytearray)): | |
| p.write_bytes(obj) | |
| else: | |
| p.write_text(json.dumps(obj)) | |
| def fake_tree(root: Path, fused_pass: bool = True) -> None: | |
| out = root / "out" / "turbo-kev" | |
| save_file({"audio_tower.w": torch.zeros(640, 1000), "multi_modal_projector.linear_1.weight": torch.zeros(44, 1000)}, | |
| out / "model.safetensors" if out.mkdir(parents=True) is None else None) | |
| (out / "text").mkdir() | |
| save_file({"model.language_model.w": torch.zeros(750, 1000), "model.visual.w": torch.zeros(10, 10)}, | |
| out / "text" / "model.safetensors-00001-of-00001.safetensors") | |
| w(out / "config.json", {"model_type": "ultravox"}) | |
| w(out / "text" / "config.json", {}) | |
| G = root / "out" / "turbo-kev-gguf" | |
| for f in (f"{N}-BF16.gguf", f"{N}-Q8_0.gguf", f"{N}-Q6_K.gguf", f"mmproj-{N}-f16.gguf", f"mmproj-{N}-q8_0.gguf", | |
| f"{N}-bundle.gguf"): | |
| w(G / f, b"GGUF" + bytes(1000)) | |
| sc = lambda g1, fl, ls, kept: {"G1_dis_wer_vs_clean": g1, "G2_fleurs-en-test_wer": fl, "G2_ls-clean-300_wer": ls, | |
| "G3_prompts_kept_pct": kept, "G3_prompts_longer_than_1.3x": 0, "G5_long_wer": 6.1, | |
| "info_multi_wer": 97.3} | |
| fused = {**sc(7.1, 5.9, 2.4, 99.48), "G1_rel_improvement": 31.2, "pass": fused_pass, | |
| "gates": {"G1": True, "G2_fleurs-en-test": True, "G2_ls-clean-300": True, "G3": True, "G5": fused_pass}} | |
| R = root / "results" | |
| w(R / "eval-whisper.json", {"scores": sc(10.31, 5.2, 2.0, 100.0)}) | |
| w(R / "eval-cascade.json", {"scores": sc(7.5, 5.4, 2.1, 99.0)}) | |
| w(R / "eval-fused.json", {"scores": fused}) | |
| w(R / "parity-trained.json", {"pass": True}) | |
| w(R / "teacher-quant.json", {"wer": {"q8_0": 5.211, "q4_k": 5.539}}) | |
| q = lambda p: {"pass": p, "size_mb": 1, **sc(7.2, 6.0, 2.5, 99.0)} | |
| w(R / "quants.json", {"bf16": sc(7.1, 5.9, 2.4, 99.48), "text": {"Q8_0": q(True), "Q6_K": q(True), "Q5_K_M": q(False)}, | |
| "text_recommended": "Q6_K", "mmproj": {"q8_0": {"pass": True, "with": "Q6_K", **sc(7.2, 6.0, 2.5, 99)}}, | |
| "mmproj_recommended": "q8_0", "recommended_pair": [f"{N}-Q6_K.gguf", f"mmproj-{N}-q8_0.gguf"], | |
| "bundle": {"file": f"{N}-bundle.gguf", "unpack_byte_identical": True}}) | |
| ex = [("so uh I went to the the store and bought some bread", "So I went to the store and bought some bread.", "dis-test-%d"), | |
| ("um what is the capital of France", "What is the capital of France?", "say-test-%d")] | |
| wr, fr = [], [] | |
| for i in range(4): | |
| for hyp, clean, idf in ex: | |
| s = idf.rsplit("-", 1)[0] | |
| wr.append({"id": idf % i, "set": s, "out": hyp}) | |
| fr.append({"id": idf % i, "set": s, "out": clean, "transcript_c": clean, "target": clean, "ref": hyp}) | |
| w(R / "eval-whisper-rows.jsonl", wr) | |
| w(R / "eval-fused-rows.jsonl", fr) | |
| w(root / "data" / "stats.json", {"text-train": 6400, "audio-train": 22000}) | |
| for sp in ("train", "valid"): | |
| w(root / "data" / "text" / f"{sp}.jsonl", [{"id": "dis-train-1", "part": "A", "input": "a", "target": "a"}, | |
| {"id": "x", "part": "D", "input": "b", "target": "b", "license": "Apache-2.0 (oasst2)"}]) | |
| w(root / "data" / f"audio-{sp}.jsonl", [{"id": "1", "set": "ls-train", "audio": "ls-train/1.flac", "input": "a", "target": "a"}]) | |
| w(root / "data" / "teacher" / "vox-en-train.jsonl", [{"id": "v1", "hyp": "hello"}]) | |
| def test_release() -> None: | |
| with tempfile.TemporaryDirectory() as t: | |
| root = Path(t) | |
| fake_tree(root) | |
| d = release.build(root) | |
| res = release.check(root, d) | |
| assert res["pass"], res["problems"] | |
| card = (root / "release" / "model" / "README.md").read_text() | |
| assert d["params"]["total"] == 1_434_000 and d["params"]["unused_in_text_dir"] == 100 # vision not counted | |
| assert res["repos"]["gguf_repo"].endswith(f"Turbo-Kev-Dictate-{d['size']}-GGUF") | |
| assert "| **7.10** |" in card and "31.20% lower" in card and "| 10.31 |" in card | |
| assert "So I went to the store" in card and "What is the capital of France?" in card | |
| gg = (root / "release" / "gguf" / "README.md").read_text() | |
| assert f"{N}-Q6_K.gguf` + `mmproj-{N}-q8_0.gguf" in gg and f"{N}-Q5_K_M" not in {p.name for p in (root / "release/gguf").iterdir()} | |
| ds = [json.loads(x) for x in (root / "release/dataset/teacher/vox-en-train.jsonl").read_text().splitlines()] | |
| assert ds[0]["license"].startswith("CC0") | |
| # stale card: results change after the build -> check fails | |
| (root / "results" / "eval-fused.json").write_text(json.dumps({"scores": {**json.loads( | |
| (root / "results" / "eval-fused.json").read_text())["scores"], "G1_dis_wer_vs_clean": 7.0}})) | |
| assert not release.check(root, release.load(root) | {"root": root, "counts": d["counts"]})["pass"] | |
| with tempfile.TemporaryDirectory() as t: # a failing gate -> check fails | |
| root = Path(t) | |
| fake_tree(root, fused_pass=False) | |
| d = release.build(root) | |
| res = release.check(root, d) | |
| assert not res["pass"] and "gate eval-fused not passed" in res["problems"] | |
| print("test_release ok") | |
| if __name__ == "__main__": | |
| test_release() | |