File size: 2,072 Bytes
41b9d24
 
84b19f5
adcb896
84b19f5
3c83fc3
 
84b19f5
41b9d24
adcb896
 
 
 
 
 
 
 
 
3c83fc3
 
 
 
adcb896
 
 
 
 
3c83fc3
 
 
 
adcb896
41b9d24
 
3c83fc3
 
 
 
 
 
 
 
 
41b9d24
 
 
 
adcb896
84b19f5
 
3c83fc3
4a07932
41b9d24
3c83fc3
 
 
 
4a07932
 
3c83fc3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
adcb896
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from pathlib import Path

import shutil
import argparse
from vampnet import DEFAULT_HF_MODEL_REPO
from huggingface_hub import create_repo, repo_exists, HfApi



parser = argparse.ArgumentParser(description="Export the fine-tuned model to the repo")
parser.add_argument(
    "--name", type=str, default="lazaro-ros-sep",
    help="name of the fine-tuned model to export"
)
parser.add_argument(
    "--model", type=str, default="latest",
    help="model version to export. check runs/<name> for available versions"
)
parser.add_argument(
    "--repo", type=str, default=DEFAULT_HF_MODEL_REPO,
    help="name of the repo to export to"
)

args = parser.parse_args()
name = args.name
version = args.model

##
print(f"~~~~~~~~~~~ vampnet export! ~~~~~~~~~~~~")
print(f"exporting {name} version {version} to {args.repo}\n")

run_dir = Path(f"runs/{name}")
repo_dir = Path("models/vampnet")

# create our repo
new_repo = False
if not repo_exists(args.repo):
    print(f"repo {args.repo} does not exist, creating it")
    print(f"creating a repo at {args.repo}")
    create_repo(args.repo)
    new_repo = True

paths = []
for part in ("coarse", "c2f"):
    outdir = repo_dir / "loras" / name 
    outdir.mkdir(parents=True, exist_ok=True)
    outpath = outdir / f"{part}.pth"
    path = run_dir / part / version / "vampnet" / "weights.pth"
    # path.rename(outpath)
    shutil.copy(path, outpath)
    paths.append(outpath)
    print(f"copied {path} to {outpath}")

print(f"uploading files to {args.repo}")
# upload files to the repo

# if it's a new repo, let's add the default models too
if new_repo:
    paths.extend([repo_dir / "c2f.pth", repo_dir / "coarse.pth", repo_dir / "codec.pth", repo_dir / "wavebeat.pth"])

api = HfApi()

for path in paths:
    path_in_repo = str(path.relative_to(repo_dir))
    print(f"uploading {path} to {args.repo}/{path_in_repo}")
    api.upload_file(
        path_or_fileobj=path,
        path_in_repo=path_in_repo,
        repo_id=args.repo,
        token=True,
        commit_message=f"uploading {path_in_repo}",
    )


print("done!!! >::0")