Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add first scratch of implementation for maestro CLI #35

Merged
merged 15 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions maestro/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions maestro/cli/env.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DISABLE_RECIPE_IMPORTS_WARNINGS_ENV = "DISABLE_RECIPE_IMPORTS_WARNINGS"
DEFAULT_DISABLE_RECIPE_IMPORTS_WARNINGS_ENV = "False"
37 changes: 37 additions & 0 deletions maestro/cli/introspection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import os

import typer

from maestro.cli.env import DISABLE_RECIPE_IMPORTS_WARNINGS_ENV, \
DEFAULT_DISABLE_RECIPE_IMPORTS_WARNINGS_ENV
from maestro.cli.utils import str2bool


def find_training_recipes(app: typer.Typer) -> None:
try:
from maestro.trainer.models.florence_2.entrypoint import florence_2_app

app.add_typer(florence_2_app, name="florence2")
except Exception:
_warn_about_recipe_import_error(model_name="Florence 2")

try:
from maestro.trainer.models.paligemma.entrypoint import paligemma_app

app.add_typer(paligemma_app, name="paligemma")
except Exception:
_warn_about_recipe_import_error(model_name="PaliGemma")


def _warn_about_recipe_import_error(model_name: str) -> None:
disable_warnings = str2bool(
os.getenv(
DISABLE_RECIPE_IMPORTS_WARNINGS_ENV,
DEFAULT_DISABLE_RECIPE_IMPORTS_WARNINGS_ENV,
)
)
if disable_warnings:
return None
warning = typer.style("WARNING", fg=typer.colors.RED, bold=True)
message = "๐Ÿšง " + warning + f" cannot import recipe for {model_name}"
typer.echo(message)
15 changes: 15 additions & 0 deletions maestro/cli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import typer

from maestro.cli.introspection import find_training_recipes

app = typer.Typer()
find_training_recipes(app=app)


@app.command(help="Display information about maestro")
def info():
typer.echo("Welcome to maestro CLI. Let's train some VLM! ๐Ÿ‹")


if __name__ == "__main__":
app()
2 changes: 2 additions & 0 deletions maestro/cli/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def str2bool(value: str) -> bool:
return value.lower() in {"y", "t", "yes", "true"}
19 changes: 19 additions & 0 deletions maestro/trainer/common/utils/file_system.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
from glob import glob
from typing import Union, List


Expand Down Expand Up @@ -38,3 +39,21 @@ def save_json(path: str, content: dict) -> None:
def ensure_parent_dir_exists(path: str) -> None:
parent_dir = os.path.dirname(os.path.abspath(path))
os.makedirs(parent_dir, exist_ok=True)


def create_new_run_directory(base_output_dir: str) -> str:
"""
Creates a new numbered directory for the current training run.

Args:
base_output_dir (str): The base directory where all run directories are stored.

Returns:
str: The path to the newly created run directory.
"""
base_output_dir = os.path.abspath(base_output_dir)
existing_run_dirs = [d for d in glob(os.path.join(base_output_dir, "*")) if os.path.isdir(d)]
new_run_number = len(existing_run_dirs) + 1
new_run_dir = os.path.join(base_output_dir, str(new_run_number))
os.makedirs(new_run_dir, exist_ok=True)
return new_run_dir
2 changes: 2 additions & 0 deletions maestro/trainer/models/florence_2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from maestro.trainer.models.florence_2.core import TrainingConfiguration, train
from maestro.trainer.models.florence_2.metrics import MeanAveragePrecisionMetric
Loading