69 lines
2.4 KiB
Python
69 lines
2.4 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import argparse
|
||
|
|
import sys
|
||
|
|
|
||
|
|
from airfrans_frontier.paths import DEFAULT_RAW_DATA_DIR, DEFAULT_RAW_MANIFEST_PATH, resolve_path
|
||
|
|
from airfrans_frontier.raw.inspect import format_raw_inspection, inspect_raw_subset
|
||
|
|
|
||
|
|
|
||
|
|
def build_parser() -> argparse.ArgumentParser:
|
||
|
|
parser = argparse.ArgumentParser(prog="airfrans-frontier")
|
||
|
|
subparsers = parser.add_subparsers(required=True)
|
||
|
|
|
||
|
|
inspect_raw = subparsers.add_parser("inspect-raw", help="inspect the local raw AirfRANS subset")
|
||
|
|
inspect_raw.add_argument("--data-dir", default=str(DEFAULT_RAW_DATA_DIR))
|
||
|
|
inspect_raw.add_argument("--manifest", default=str(DEFAULT_RAW_MANIFEST_PATH))
|
||
|
|
inspect_raw.add_argument("--sample-limit", type=int, default=5)
|
||
|
|
inspect_raw.set_defaults(command="inspect-raw")
|
||
|
|
|
||
|
|
train = subparsers.add_parser("train", help="train a configured baseline model")
|
||
|
|
train.add_argument("config", help="path to a training config TOML file")
|
||
|
|
train.set_defaults(command="train")
|
||
|
|
|
||
|
|
return parser
|
||
|
|
|
||
|
|
|
||
|
|
def main(argv: list[str] | None = None) -> int:
|
||
|
|
parser = build_parser()
|
||
|
|
args = parser.parse_args(argv)
|
||
|
|
|
||
|
|
if args.command == "inspect-raw":
|
||
|
|
if args.sample_limit < 0:
|
||
|
|
print("error: --sample-limit must be non-negative", file=sys.stderr)
|
||
|
|
return 1
|
||
|
|
|
||
|
|
data_dir = resolve_path(args.data_dir)
|
||
|
|
manifest_path = resolve_path(args.manifest)
|
||
|
|
try:
|
||
|
|
report = inspect_raw_subset(data_dir, manifest_path)
|
||
|
|
except (FileNotFoundError, NotADirectoryError, ValueError) as exc:
|
||
|
|
print(f"error: {exc}", file=sys.stderr)
|
||
|
|
return 1
|
||
|
|
|
||
|
|
print(format_raw_inspection(report, sample_limit=args.sample_limit))
|
||
|
|
return 0 if report.matches_manifest else 1
|
||
|
|
|
||
|
|
if args.command == "train":
|
||
|
|
from airfrans_frontier.runtime import remove_pythonpath_entries
|
||
|
|
|
||
|
|
remove_pythonpath_entries()
|
||
|
|
from airfrans_frontier.training.loop import train_from_config_path
|
||
|
|
|
||
|
|
try:
|
||
|
|
result = train_from_config_path(resolve_path(args.config))
|
||
|
|
except (FileNotFoundError, NotADirectoryError, ValueError, RuntimeError) as exc:
|
||
|
|
print(f"error: {exc}", file=sys.stderr)
|
||
|
|
return 1
|
||
|
|
|
||
|
|
print(f"run_dir: {result.run_dir}")
|
||
|
|
print(f"final_metrics: {result.run_dir / 'final_metrics.json'}")
|
||
|
|
return 0
|
||
|
|
|
||
|
|
parser.error(f"unknown command: {args.command}")
|
||
|
|
return 2
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
raise SystemExit(main())
|