File size: 2,372 Bytes
c60ec61
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Train every (architecture x tokeniser) model.

Tokenisers are 'char' (CharTokenizer baseline), 256 and 512 (BPE), so the full
sweep is 4 architectures x 3 tokenisers = 12 checkpoints. Use --tokenizer to
restrict the run (e.g. only the 4 char baselines).

Each model is trained by launching train_one.py in a fresh subprocess, because
the architecture folders share flat module names and cannot coexist in one
interpreter. The worker streams its own progress; we just orchestrate and
report a final pass/fail summary.

Run:  python src/train_all.py                     # full sweep, all 12 models
      python src/train_all.py --tokenizer char    # only the 4 char baselines
      python src/train_all.py --steps 200         # quick smoke run
"""

from __future__ import annotations

import argparse
import subprocess
import sys
from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
WORKER = ROOT / "src" / "train_one.py"

ARCHITECTURES = ("qwen3", "qwen3_5", "gemma4", "deepseek3")
TOKENIZERS = ("char", "256", "512")


def main() -> None:
    parser = argparse.ArgumentParser(description="Train the tiny models on the names corpus.")
    parser.add_argument("--tokenizer", choices=TOKENIZERS, default=None,
                        help="restrict to one tokeniser (default: all three)")
    parser.add_argument("--steps", type=int, default=None, help="override step count for every run")
    args = parser.parse_args()

    tokenizers = (args.tokenizer,) if args.tokenizer else TOKENIZERS
    runs = [(arch, tok) for arch in ARCHITECTURES for tok in tokenizers]
    results: list[tuple[str, str, int]] = []

    for index, (arch, tok) in enumerate(runs, start=1):
        print(f"\n{'=' * 60}\n[{index}/{len(runs)}] training {arch} · {tok}\n{'=' * 60}")
        command = [sys.executable, str(WORKER), arch, tok]
        if args.steps is not None:
            command += ["--steps", str(args.steps)]
        completed = subprocess.run(command, cwd=str(ROOT))
        results.append((arch, tok, completed.returncode))

    print(f"\n{'=' * 60}\nSUMMARY\n{'=' * 60}")
    for arch, tok, code in results:
        status = "ok" if code == 0 else f"FAILED (exit {code})"
        print(f"  {arch:<10} {tok:<4}: {status}")

    if any(code != 0 for _, _, code in results):
        sys.exit("Some training runs failed.")


if __name__ == "__main__":
    main()