Spaces:
Running on Zero
Running on Zero
Upload seed-vc/modules/bigvgan/bigvgan.py with huggingface_hub
Browse files
seed-vc/modules/bigvgan/bigvgan.py
CHANGED
|
@@ -415,36 +415,45 @@ class BigVGAN(
|
|
| 415 |
cls,
|
| 416 |
*,
|
| 417 |
model_id: str,
|
| 418 |
-
revision: str,
|
| 419 |
-
cache_dir: str,
|
| 420 |
-
force_download: bool,
|
| 421 |
-
proxies: Optional[Dict],
|
| 422 |
-
resume_download: bool,
|
| 423 |
-
local_files_only: bool,
|
| 424 |
-
token: Union[str, bool, None],
|
| 425 |
map_location: str = "cpu", # Additional argument
|
| 426 |
strict: bool = False, # Additional argument
|
| 427 |
use_cuda_kernel: bool = False,
|
| 428 |
**model_kwargs,
|
| 429 |
):
|
| 430 |
"""Load Pytorch pretrained weights and return the loaded model."""
|
|
|
|
| 431 |
|
| 432 |
-
#
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
config_file = os.path.join(model_id, "config.json")
|
| 436 |
-
else:
|
| 437 |
-
config_file = hf_hub_download(
|
| 438 |
repo_id=model_id,
|
| 439 |
-
filename=
|
| 440 |
revision=revision,
|
| 441 |
cache_dir=cache_dir,
|
| 442 |
force_download=force_download,
|
| 443 |
-
proxies=proxies,
|
| 444 |
-
resume_download=resume_download,
|
| 445 |
token=token,
|
| 446 |
local_files_only=local_files_only,
|
| 447 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
h = load_hparams_from_json(config_file)
|
| 449 |
|
| 450 |
# instantiate BigVGAN using h
|
|
@@ -466,17 +475,7 @@ class BigVGAN(
|
|
| 466 |
model_file = os.path.join(model_id, "bigvgan_generator.pt")
|
| 467 |
else:
|
| 468 |
print(f"Loading weights from {model_id}")
|
| 469 |
-
model_file =
|
| 470 |
-
repo_id=model_id,
|
| 471 |
-
filename="bigvgan_generator.pt",
|
| 472 |
-
revision=revision,
|
| 473 |
-
cache_dir=cache_dir,
|
| 474 |
-
force_download=force_download,
|
| 475 |
-
proxies=proxies,
|
| 476 |
-
resume_download=resume_download,
|
| 477 |
-
token=token,
|
| 478 |
-
local_files_only=local_files_only,
|
| 479 |
-
)
|
| 480 |
|
| 481 |
checkpoint_dict = torch.load(model_file, map_location=map_location)
|
| 482 |
|
|
|
|
| 415 |
cls,
|
| 416 |
*,
|
| 417 |
model_id: str,
|
| 418 |
+
revision: str = None,
|
| 419 |
+
cache_dir: str = None,
|
| 420 |
+
force_download: bool = False,
|
| 421 |
+
proxies: Optional[Dict] = None,
|
| 422 |
+
resume_download: Optional[bool] = None,
|
| 423 |
+
local_files_only: bool = False,
|
| 424 |
+
token: Union[str, bool, None] = None,
|
| 425 |
map_location: str = "cpu", # Additional argument
|
| 426 |
strict: bool = False, # Additional argument
|
| 427 |
use_cuda_kernel: bool = False,
|
| 428 |
**model_kwargs,
|
| 429 |
):
|
| 430 |
"""Load Pytorch pretrained weights and return the loaded model."""
|
| 431 |
+
import inspect
|
| 432 |
|
| 433 |
+
# huggingface_hub >=1.0 dropped proxies/resume_download from mixin + download API
|
| 434 |
+
def _hub_download(filename: str) -> str:
|
| 435 |
+
kwargs = dict(
|
|
|
|
|
|
|
|
|
|
| 436 |
repo_id=model_id,
|
| 437 |
+
filename=filename,
|
| 438 |
revision=revision,
|
| 439 |
cache_dir=cache_dir,
|
| 440 |
force_download=force_download,
|
|
|
|
|
|
|
| 441 |
token=token,
|
| 442 |
local_files_only=local_files_only,
|
| 443 |
)
|
| 444 |
+
params = inspect.signature(hf_hub_download).parameters
|
| 445 |
+
if "proxies" in params:
|
| 446 |
+
kwargs["proxies"] = proxies
|
| 447 |
+
if "resume_download" in params and resume_download is not None:
|
| 448 |
+
kwargs["resume_download"] = resume_download
|
| 449 |
+
return hf_hub_download(**kwargs)
|
| 450 |
+
|
| 451 |
+
# Download and load hyperparameters (h) used by BigVGAN
|
| 452 |
+
if os.path.isdir(model_id):
|
| 453 |
+
print("Loading config.json from local directory")
|
| 454 |
+
config_file = os.path.join(model_id, "config.json")
|
| 455 |
+
else:
|
| 456 |
+
config_file = _hub_download("config.json")
|
| 457 |
h = load_hparams_from_json(config_file)
|
| 458 |
|
| 459 |
# instantiate BigVGAN using h
|
|
|
|
| 475 |
model_file = os.path.join(model_id, "bigvgan_generator.pt")
|
| 476 |
else:
|
| 477 |
print(f"Loading weights from {model_id}")
|
| 478 |
+
model_file = _hub_download("bigvgan_generator.pt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 479 |
|
| 480 |
checkpoint_dict = torch.load(model_file, map_location=map_location)
|
| 481 |
|