Download source/shruti_coreml/batch.py from bingokingooo/shruti-coreml: direct link, hf CLI and curl.
- Browser
- Download file 2.01 kB
-
https://huggingface.co/bingokingooo/shruti-coreml/resolve/main/source/shruti_coreml/batch.py
- Command line
-
hf download hf://bingokingooo/shruti-coreml/source/shruti_coreml/batch.py
-
curl -L -o batch.py https://huggingface.co/bingokingooo/shruti-coreml/resolve/main/source/shruti_coreml/batch.py
2.01 kB
| """Export every pinned language, logging a result even when a conversion fails.""" | |
| import argparse | |
| import concurrent.futures | |
| import json | |
| import os | |
| import subprocess | |
| import sys | |
| from pathlib import Path | |
| from .sources import CATALOG, ROOT, compiled_assets | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("languages", nargs="+") | |
| parser.add_argument("--jobs", default=2, type=int) | |
| parser.add_argument("--compile", choices=("macos", "ios", "iossimulator")) | |
| args = parser.parse_args() | |
| codes = list(CATALOG["models"]) if args.languages == ["all"] else args.languages | |
| log_dir = ROOT / "build/logs" | |
| log_dir.mkdir(parents=True, exist_ok=True) | |
| def convert(code): | |
| directory = ROOT / "build" / code | |
| if (directory / "model.json").exists(): | |
| if not args.compile or len(list(compiled_assets(directory, args.compile).glob("*.mlmodelc"))) == 12: | |
| return code, 0 | |
| command = [sys.executable, "-m", "shruti_coreml.export", code] | |
| if args.compile: | |
| command.extend(["--compile", args.compile]) | |
| with (log_dir / f"{code}.log").open("w") as logfile: | |
| result = subprocess.run(command, cwd=ROOT, env={**os.environ, "OPENBLAS_NUM_THREADS": "1"}, | |
| stdout=logfile, stderr=subprocess.STDOUT) | |
| return code, result.returncode | |
| results = {} | |
| with concurrent.futures.ThreadPoolExecutor(max_workers=args.jobs) as pool: | |
| pending = [pool.submit(convert, code) for code in codes] | |
| for future in concurrent.futures.as_completed(pending): | |
| code, status = future.result() | |
| results[code] = {"success": status == 0, "exit": status} | |
| print(code, status, flush=True) | |
| (ROOT / "build/export-status.json").write_text(json.dumps(results, sort_keys=True, indent=2) + "\n") | |
| raise SystemExit(not all(record["success"] for record in results.values())) | |
| if __name__ == "__main__": | |
| main() | |