Skip to content

Commit

Permalink
Move parse_model_arg(...) to a util file.
Browse files Browse the repository at this point in the history
  • Loading branch information
RyanJDick committed Jun 3, 2024
1 parent a77f612 commit 31d71c0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
12 changes: 1 addition & 11 deletions src/invoke_training/model_merge/scripts/merge_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from invoke_training._shared.accelerator.accelerator_utils import get_dtype_from_str
from invoke_training._shared.stable_diffusion.model_loading_utils import PipelineVersionEnum, load_pipeline
from invoke_training.model_merge.merge_models import merge_models
from invoke_training.model_merge.utils import parse_model_arg


@dataclass
Expand Down Expand Up @@ -69,17 +70,6 @@ def run_merge_models(
logger.info(f"Saved merged model to '{out_dir_path}'.")


def parse_model_arg(model: str) -> tuple[str, str | None]:
"""Parse a --models argument into a model and a variant."""
parts = model.split("::")
if len(parts) == 1:
return parts[0], None
elif len(parts) == 2:
return parts[0], parts[1]
else:
raise ValueError(f"Unexpected format for --models arg: '{model}'.")


def parse_model_args(models: list[str], weights: list[str]) -> list[MergeModel]:
"""Parse a list of --models arguments and --weights arguments into a list of MergeModels."""
merge_model_list: list[MergeModel] = []
Expand Down
9 changes: 9 additions & 0 deletions src/invoke_training/model_merge/utils/parse_model_arg.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
def parse_model_arg(model: str, delimiter: str = "::") -> tuple[str, str | None]:
"""Parse a model argument into a model and a variant."""
parts = model.split(delimiter)
if len(parts) == 1:
return parts[0], None
elif len(parts) == 2:
return parts[0], parts[1]
else:
raise ValueError(f"Unexpected format for --models arg: '{model}'.")

0 comments on commit 31d71c0

Please sign in to comment.