File size: 3,517 Bytes
62600b8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python3
from __future__ import annotations

import argparse
import os
import sys
import zipfile
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "src"))

from romani_asr.manifest import read_manifest_csv


DEFAULT_MANIFESTS = [
    Path("artifacts/manifests/clean/train_clean.csv"),
    Path("artifacts/manifests/clean/validation_clean.csv"),
    Path("artifacts/manifests/test.csv"),
]

CODE_PATHS = [
    Path("requirements.txt"),
    Path("README.md"),
    Path("scripts/train_mms_adapter.py"),
    Path("scripts/evaluate_mms_asr.py"),
    Path("scripts/summarize_frozen_asr_eval.py"),
    Path("scripts/run_mms_gpu_training.sh"),
    Path("docs/mms-gpu-training.md"),
    Path("reports/frozen-asr-evaluation-2026-08-10.md"),
]


def parse_args() -> argparse.Namespace:
    parser = argparse.ArgumentParser(
        description="Create a portable ZIP for MMS GPU training."
    )
    parser.add_argument(
        "--output",
        type=Path,
        default=Path("artifacts/gpu/mms-romani-gpu-training-bundle.zip"),
    )
    parser.add_argument(
        "--manifest",
        action="append",
        type=Path,
        dest="manifests",
        help="Manifest to include. Defaults to clean train/validation and test.",
    )
    parser.add_argument(
        "--dry-run",
        action="store_true",
        help="Validate files and print the bundle plan without writing the ZIP.",
    )
    return parser.parse_args()


def project_files() -> list[Path]:
    files = list(CODE_PATHS)
    files.extend(sorted(Path("src").glob("romani_asr/*.py")))
    return files


def referenced_audio_files(manifests: list[Path]) -> list[Path]:
    audio_paths: set[Path] = set()
    for manifest in manifests:
        for row in read_manifest_csv(manifest):
            audio_paths.add(Path(row["audio_path"]))
    return sorted(audio_paths)


def validate_files(paths: list[Path]) -> None:
    missing = [path for path in paths if not path.exists()]
    if missing:
        formatted = "\n".join(f"- {path}" for path in missing[:20])
        suffix = "" if len(missing) <= 20 else f"\n... and {len(missing) - 20} more"
        raise FileNotFoundError(f"Missing files for bundle:\n{formatted}{suffix}")


def bundle_paths(manifests: list[Path]) -> list[Path]:
    paths: set[Path] = set(manifests)
    paths.update(project_files())
    paths.update(referenced_audio_files(manifests))
    return sorted(paths)


def write_zip(output: Path, paths: list[Path]) -> None:
    output.parent.mkdir(parents=True, exist_ok=True)
    temporary = output.with_suffix(output.suffix + ".tmp")
    if temporary.exists():
        temporary.unlink()
    with zipfile.ZipFile(
        temporary,
        "w",
        compression=zipfile.ZIP_DEFLATED,
        compresslevel=6,
    ) as archive:
        for path in paths:
            archive.write(path, path.as_posix())
    os.replace(temporary, output)


def main() -> None:
    args = parse_args()
    manifests = args.manifests or DEFAULT_MANIFESTS
    paths = bundle_paths(manifests)
    validate_files(paths)
    total_bytes = sum(path.stat().st_size for path in paths)
    print(f"Files: {len(paths)}")
    print(f"Uncompressed: {total_bytes / 1024 / 1024:.1f} MB")
    if args.dry_run:
        print("Dry run only; no ZIP written.")
        return
    write_zip(args.output, paths)
    print(f"Wrote: {args.output}")
    print(f"ZIP size: {args.output.stat().st_size / 1024 / 1024:.1f} MB")


if __name__ == "__main__":
    main()