music3lab / scripts /run_latent_inversion_v2.py
coolpoodle's picture
code and training scripts
90884df verified
Raw
History Blame Contribute Delete
2.57 kB
"""Launch the frozen v2 inversion through the clean evidence bootstrap."""
from __future__ import annotations
import argparse
import os
from pathlib import Path
import subprocess
import sys
def parser() -> argparse.ArgumentParser:
result = argparse.ArgumentParser(description=__doc__)
for option in (
"config",
"snapshot",
"base-manifest",
"diffusers-root",
"phase0-artifacts",
"v1-source-root",
"v1-config",
"v1-output-root",
"output-root",
):
result.add_argument(f"--{option}", type=Path, required=True)
result.add_argument("--project-root", type=Path)
return result
def main() -> int:
args = parser().parse_args()
config = args.config.expanduser().resolve(strict=True)
project_root = (
args.project_root.expanduser().resolve(strict=True)
if args.project_root is not None
else config.parent.parent.resolve(strict=True)
)
diffusers_root = args.diffusers_root.expanduser().resolve(strict=True)
launcher = project_root / "scripts" / "evidence_bootstrap.py"
values = {
"project-root": project_root,
"config": config,
"snapshot": args.snapshot.expanduser().resolve(strict=True),
"base-manifest": args.base_manifest.expanduser().resolve(strict=True),
"diffusers-root": diffusers_root,
"phase0-artifacts": args.phase0_artifacts.expanduser().resolve(strict=True),
"v1-source-root": args.v1_source_root.expanduser().resolve(strict=True),
"v1-config": args.v1_config.expanduser().resolve(strict=True),
"v1-output-root": args.v1_output_root.expanduser().resolve(strict=True),
"output-root": args.output_root.expanduser().absolute(),
}
arguments = [
"_run-inversion-v2",
*[
value
for name, path in values.items()
for value in (f"--{name}", str(path))
],
]
environment = os.environ.copy()
environment["HF_HUB_OFFLINE"] = "1"
environment["PYTHONDONTWRITEBYTECODE"] = "1"
completed = subprocess.run(
[
sys.executable,
"-I",
"-S",
"-B",
str(launcher),
"--project-root",
str(project_root),
"--diffusers-root",
str(diffusers_root),
"--",
*arguments,
],
env=environment,
check=False,
text=True,
)
return completed.returncode
if __name__ == "__main__":
raise SystemExit(main())