File size: 2,110 Bytes
bd72529
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Prepare a Kaggle/Colab session for a uzu lane.

Robustness notes:
- ``hf download --include`` behaviour differs between huggingface_hub versions
  (some accept a single value only). The kit is ~5 MB, so this script downloads
  the whole dataset and avoids ``--include`` entirely.
- The kit is rebuilt from a fixed manifest (``scripts/build_kit.py``), so a
  missing script cannot silently slip in.

Usage:
    python scripts/bootstrap_kaggle.py                 # install deps + fetch kit
    python scripts/bootstrap_kaggle.py --no-install    # kit only
    python scripts/bootstrap_kaggle.py --dry-run
"""

from __future__ import annotations

import argparse
import subprocess
import sys
from pathlib import Path

KIT_REPO = "yamahei21/uzu-quant-kit"
LALAMO = "git+https://github.com/trymirai/lalamo@e401e17761f2fcd337b0cf20218d67d656e6ecba"
PACKAGES = [LALAMO, "jax[cuda12]", "huggingface_hub", "tokenizers"]


def run(command: list[str], dry_run: bool) -> None:
    print("$ " + " ".join(command), flush=True)
    if dry_run:
        return
    subprocess.run(command, check=True)


def main() -> None:
    parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
    parser.add_argument("--work", default="/kaggle/working")
    parser.add_argument("--no-install", action="store_true", help="skip pip install")
    parser.add_argument("--dry-run", action="store_true")
    args = parser.parse_args()

    work = Path(args.work)
    kit = work / "kit"

    if not args.no_install:
        run([sys.executable, "-m", "pip", "install", "-q", *PACKAGES], args.dry_run)

    run(
        [
            "hf",
            "download",
            KIT_REPO,
            "--repo-type",
            "dataset",
            "--local-dir",
            str(kit),
        ],
        args.dry_run,
    )

    print(
        "\nnext:\n"
        f"  python {kit}/scripts/run_lane.py --spec {kit}/lanes/clean-suite-08b.json "
        f"--hf-results <user>/uzu-results --work {work}",
        flush=True,
    )


if __name__ == "__main__":
    main()