Datasets:
File size: 3,153 Bytes
2b42850 93ae952 2b42850 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | #!/usr/bin/env python3
"""Derive tiny smoke specs from the real lane specs.
A full lane takes hours; a broken flag, missing file, or merge mismatch shows up
in the first minutes. This shrinks every lane (samples 1, 32 tokens, 2 eval
chunks) so one CPU session can prove that all of them run end to end.
python scripts/make_smoke_specs.py --out-dir lanes
The generated files are named ``smoke-<lane>.json``. ``balanced-h`` keeps its
merge but only at ratio 0.5; robustness shards keep only the first two
conditions.
"""
from __future__ import annotations
import argparse
import copy
import glob
import json
from pathlib import Path
DEFAULT_SKIP = {"smoke-08b"}
def shrink(spec: dict, robustness_limit: int) -> dict:
spec = copy.deepcopy(spec)
spec["lane"] = f"smoke-{spec['lane']}"
spec.setdefault("paths", {})["jax_platform"] = "cpu"
spec.setdefault("eval", {})["max_sequences"] = 2
spec["eval"]["max_tokens"] = 32
spec["eval"]["min_tokens"] = 4
spec["eval"]["dtype"] = "float32"
spec.setdefault("convert", {})["parallel"] = "replicated"
# quantize only layer 0 so a smoke conversion takes seconds, not ten minutes
spec["convert"]["layer_filter"] = "/[0]/"
is_robustness = "robustness" in spec["lane"]
conditions = spec.get("conditions", [])
if is_robustness:
conditions = conditions[:robustness_limit]
for condition in conditions:
condition["samples"] = 1
condition["max_tokens"] = 32
condition.setdefault("calib_dtype", "float32")
spec["conditions"] = conditions
merge = spec.get("merge")
if merge:
merge["ratios"] = [0.5]
return spec
def main() -> None:
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument("--lanes-dir", type=Path, default=Path("lanes"))
parser.add_argument("--out-dir", type=Path, default=Path("lanes"))
parser.add_argument("--robustness-limit", type=int, default=2)
parser.add_argument("--include", nargs="*", default=None)
parser.add_argument("--dry-run", action="store_true")
args = parser.parse_args()
args.out_dir.mkdir(parents=True, exist_ok=True)
written = []
for path in sorted(args.lanes_dir.glob("*.json")):
if path.name.startswith("smoke-") or path.stem in DEFAULT_SKIP:
continue
if args.include and path.stem not in args.include:
continue
if path.name == "bits-down-out-6.json":
continue
try:
spec = json.loads(path.read_text(encoding="utf-8"))
except json.JSONDecodeError:
continue
if "conditions" not in spec:
continue
smoke = shrink(spec, args.robustness_limit)
out = args.out_dir / f"{smoke['lane']}.json"
print(f"{path.name} -> {out.name} ({len(smoke['conditions'])} conditions)")
if not args.dry_run:
out.write_text(json.dumps(smoke, indent=2, ensure_ascii=False) + "\n", encoding="utf-8")
written.append(out.name)
print(f"{len(written)} smoke specs")
if __name__ == "__main__":
main()
|