Update RVC Hubert Loader - add_safe_globals fix

This commit is contained in:
erew123 authored and GitHub committed 2025-02-24 15:06:05 +00:00
1 parent 4959ae36c1
commit 698efdcdec
1 file changed
+15 -6
+15 -6
View File
@@ -56,7 +56,6 @@ def format_title(title):
def load_embedding(embedder_model): def load_embedding(embedder_model):
#print("EMBEDDER MODEL IS", embedder_model)
embedding_list = { embedding_list = {
"contentvec": "contentvec_base.pt", "contentvec": "contentvec_base.pt",
"hubert": "hubert_base.pt", "hubert": "hubert_base.pt",
@@ -65,20 +64,30 @@ def load_embedding(embedder_model):
try: try:
this_dir = Path(__file__).resolve().parent.parent.parent.parent.parent this_dir = Path(__file__).resolve().parent.parent.parent.parent.parent
model_path = this_dir / "models" / "rvc_base" / embedding_list[embedder_model] model_path = this_dir / "models" / "rvc_base" / embedding_list[embedder_model]
#print("MODEL PATH IS", model_path)
# Load model ensemble and task # Import Dictionary class from fairseq
torch.serialization.add_safe_globals([Dictionary]) from fairseq.data.dictionary import Dictionary
# For PyTorch 2.2+, try using add_safe_globals directly but with proper import
# of the Dictionary class from fairseq
try:
torch.serialization.add_safe_globals([Dictionary])
except (AttributeError, ImportError) as e:
# If add_safe_globals doesn't exist, we'll need to load with weights_only=False
# But that's a security risk with untrusted models
logging.warning("Could not use add_safe_globals, loading model with reduced security")
pass
# Load model
models = checkpoint_utils.load_model_ensemble_and_task( models = checkpoint_utils.load_model_ensemble_and_task(
[f"{model_path}"], [f"{model_path}"],
suffix="", suffix="",
) )
#print(f"Embedding model {embedder_model} loaded successfully.")
return models return models
except KeyError as e: except KeyError as e:
logging.error(f"Invalid embedder model name: {embedder_model}") logging.error(f"Invalid embedder model name: {embedder_model}")
raise ValueError(f"Invalid embedder model name: {embedder_model}") from e raise ValueError(f"Invalid embedder model name: {embedder_model}") from e
except Exception as e: except Exception as e:
logging.error(f"Error loading embedding model: {e}") logging.error(f"Error loading embedding model: {e}")
raise RuntimeError(f"Error loading embedding model: {e}") from e raise RuntimeError(f"Error loading embedding model: {e}") from e