Spaces:
Running on Zero
Running on Zero
Pin the weights' revision, and fetch the fine-tuned models in the worker at startup rather than inside the GPU call.
Browse files- app.py +8 -0
- vampnet/__init__.py +8 -4
app.py
CHANGED
|
@@ -45,6 +45,14 @@ init_model_choice = open("DEFAULT_MODEL").read().strip()
|
|
| 45 |
|
| 46 |
# load the init model
|
| 47 |
interface.load_finetuned(init_model_choice)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
print(f"Loaded initial model: {init_model_choice}")
|
| 49 |
print(f"Coarse model path: {interface.coarse_path}")
|
| 50 |
print(f"C2F model path: {interface.c2f_path}\n")
|
|
|
|
| 45 |
|
| 46 |
# load the init model
|
| 47 |
interface.load_finetuned(init_model_choice)
|
| 48 |
+
|
| 49 |
+
# The other fine-tuned models the interface offers are fetched in the worker, which runs
|
| 50 |
+
# process_fn, rather than inside the GPU call the first time a request picks one
|
| 51 |
+
if __name__ != "__main__":
|
| 52 |
+
from vampnet import download_finetuned
|
| 53 |
+
for _name in interface.available_models():
|
| 54 |
+
if _name != "default":
|
| 55 |
+
download_finetuned(_name)
|
| 56 |
print(f"Loaded initial model: {init_model_choice}")
|
| 57 |
print(f"Coarse model path: {interface.coarse_path}")
|
| 58 |
print(f"C2F model path: {interface.c2f_path}\n")
|
vampnet/__init__.py
CHANGED
|
@@ -15,6 +15,9 @@ from huggingface_hub import hf_hub_download, HfFileSystem
|
|
| 15 |
DEFAULT_HF_MODEL_REPO_DIR = ROOT / "DEFAULT_HF_MODEL_REPO"
|
| 16 |
DEFAULT_HF_MODEL_REPO = DEFAULT_HF_MODEL_REPO_DIR.read_text().strip()
|
| 17 |
# DEFAULT_HF_MODEL_REPO = "hugggof/vampnet"
|
|
|
|
|
|
|
|
|
|
| 18 |
FS = HfFileSystem()
|
| 19 |
|
| 20 |
def download_codec():
|
|
@@ -26,7 +29,8 @@ def download_codec():
|
|
| 26 |
repo_id=repo_id,
|
| 27 |
filename=filename,
|
| 28 |
subfolder=None,
|
| 29 |
-
local_dir=MODELS_DIR
|
|
|
|
| 30 |
)
|
| 31 |
return codec_path
|
| 32 |
|
|
@@ -39,7 +43,7 @@ def download_default():
|
|
| 39 |
path = f"{MODELS_DIR}/{filename}"
|
| 40 |
if not Path(path).exists():
|
| 41 |
print(f"{path} does not exist, downloading")
|
| 42 |
-
FS.download(f"{repo_id}/{filename}", path)
|
| 43 |
paths.append(path)
|
| 44 |
|
| 45 |
# load the models
|
|
@@ -53,14 +57,14 @@ def download_finetuned(name, repo_id=DEFAULT_HF_MODEL_REPO):
|
|
| 53 |
path = f"{MODELS_DIR}/loras/{name}/{filename}"
|
| 54 |
if not Path(path).exists():
|
| 55 |
print(f"{path} does not exist, downloading")
|
| 56 |
-
FS.download(f"{repo_id}/loras/{name}/{filename}", path)
|
| 57 |
paths.append(path)
|
| 58 |
|
| 59 |
# load the models
|
| 60 |
return paths[0], paths[1]
|
| 61 |
|
| 62 |
def list_finetuned(repo_id=DEFAULT_HF_MODEL_REPO):
|
| 63 |
-
diritems = FS.listdir(f"{repo_id}/loras")
|
| 64 |
# iterate through all the names
|
| 65 |
valid_diritems = []
|
| 66 |
for item in diritems:
|
|
|
|
| 15 |
DEFAULT_HF_MODEL_REPO_DIR = ROOT / "DEFAULT_HF_MODEL_REPO"
|
| 16 |
DEFAULT_HF_MODEL_REPO = DEFAULT_HF_MODEL_REPO_DIR.read_text().strip()
|
| 17 |
# DEFAULT_HF_MODEL_REPO = "hugggof/vampnet"
|
| 18 |
+
# The weights' revision, which every download below names, so that the models cannot change
|
| 19 |
+
# under the Space
|
| 20 |
+
REVISION = "69e9c7dba72b54a45f93122ef91aa738d2e803ba"
|
| 21 |
FS = HfFileSystem()
|
| 22 |
|
| 23 |
def download_codec():
|
|
|
|
| 29 |
repo_id=repo_id,
|
| 30 |
filename=filename,
|
| 31 |
subfolder=None,
|
| 32 |
+
local_dir=MODELS_DIR,
|
| 33 |
+
revision=REVISION,
|
| 34 |
)
|
| 35 |
return codec_path
|
| 36 |
|
|
|
|
| 43 |
path = f"{MODELS_DIR}/{filename}"
|
| 44 |
if not Path(path).exists():
|
| 45 |
print(f"{path} does not exist, downloading")
|
| 46 |
+
FS.download(f"{repo_id}@{REVISION}/{filename}", path)
|
| 47 |
paths.append(path)
|
| 48 |
|
| 49 |
# load the models
|
|
|
|
| 57 |
path = f"{MODELS_DIR}/loras/{name}/{filename}"
|
| 58 |
if not Path(path).exists():
|
| 59 |
print(f"{path} does not exist, downloading")
|
| 60 |
+
FS.download(f"{repo_id}@{REVISION}/loras/{name}/{filename}", path)
|
| 61 |
paths.append(path)
|
| 62 |
|
| 63 |
# load the models
|
| 64 |
return paths[0], paths[1]
|
| 65 |
|
| 66 |
def list_finetuned(repo_id=DEFAULT_HF_MODEL_REPO):
|
| 67 |
+
diritems = FS.listdir(f"{repo_id}@{REVISION}/loras")
|
| 68 |
# iterate through all the names
|
| 69 |
valid_diritems = []
|
| 70 |
for item in diritems:
|