Skip to content

Commit

Permalink
added weights_only=True for all torch.load calls
Browse files Browse the repository at this point in the history
  • Loading branch information
AznamirWoW committed Jan 30, 2025
1 parent 9cfa0ae commit 11d1395
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion rvc/infer/infer.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ def load_model(self, weight_root):
weight_root (str): Path to the model weights.
"""
self.cpt = (
torch.load(weight_root, map_location="cpu")
torch.load(weight_root, map_location="cpu", weights_only=True)
if os.path.isfile(weight_root)
else None
)
Expand Down
2 changes: 1 addition & 1 deletion rvc/lib/predictors/FCPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,7 +728,7 @@ def __init__(self, model_path, device=None, dtype=torch.float32):
if device is None:
device = "cuda" if torch.cuda.is_available() else "cpu"
self.device = device
ckpt = torch.load(model_path, map_location=torch.device(self.device))
ckpt = torch.load(model_path, map_location=torch.device(self.device), weights_only=True)
self.args = DotDict(ckpt["config"])
self.dtype = dtype
model = FCPE(
Expand Down
2 changes: 1 addition & 1 deletion rvc/lib/predictors/RMVPE.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ class RMVPE0Predictor:
def __init__(self, model_path, device=None):
self.resample_kernel = {}
model = E2E(4, 1, (2, 2))
ckpt = torch.load(model_path, map_location="cpu")
ckpt = torch.load(model_path, map_location="cpu", weights_only=True)
model.load_state_dict(ckpt)
model.eval()
self.model = model
Expand Down
2 changes: 1 addition & 1 deletion rvc/train/data_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def get_audio(self, filename):
spec_filename = filename.replace(".wav", ".spec.pt")
if os.path.exists(spec_filename):
try:
spec = torch.load(spec_filename)
spec = torch.load(spec_filename, weights_only=True)
except Exception as error:
print(f"An error occurred getting spec from {spec_filename}: {error}")
spec = spectrogram_torch(
Expand Down
2 changes: 1 addition & 1 deletion rvc/train/process/change_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

def change_info(path, info, name):
try:
ckpt = torch.load(path, map_location="cpu")
ckpt = torch.load(path, map_location="cpu", weights_only=True)
ckpt["info"] = info

if not name:
Expand Down
4 changes: 2 additions & 2 deletions rvc/train/process/model_blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def extract(ckpt):
def model_blender(name, path1, path2, ratio):
try:
message = f"Model {path1} and {path2} are merged with alpha {ratio}."
ckpt1 = torch.load(path1, map_location="cpu")
ckpt2 = torch.load(path2, map_location="cpu")
ckpt1 = torch.load(path1, map_location="cpu", weights_only=True)
ckpt2 = torch.load(path2, map_location="cpu", weights_only=True)

if ckpt1["sr"] != ckpt2["sr"]:
return "The sample rates of the two models are not the same."
Expand Down
2 changes: 1 addition & 1 deletion rvc/train/process/model_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def prettify_date(date_str):


def model_information(path):
model_data = torch.load(path, map_location="cpu")
model_data = torch.load(path, map_location="cpu", weights_only=True)

print(f"Loaded model from {path}")

Expand Down
8 changes: 4 additions & 4 deletions rvc/train/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,23 +469,23 @@ def run(
print(f"Loaded pretrained (G) '{pretrainG}'")
if hasattr(net_g, "module"):
net_g.module.load_state_dict(
torch.load(pretrainG, map_location="cpu")["model"]
torch.load(pretrainG, map_location="cpu", weights_only=True)["model"]
)
else:
net_g.load_state_dict(
torch.load(pretrainG, map_location="cpu")["model"]
torch.load(pretrainG, map_location="cpu", weights_only=True)["model"]
)

if pretrainD != "" and pretrainD != "None":
if rank == 0:
print(f"Loaded pretrained (D) '{pretrainD}'")
if hasattr(net_d, "module"):
net_d.module.load_state_dict(
torch.load(pretrainD, map_location="cpu")["model"]
torch.load(pretrainD, map_location="cpu", weights_only=True)["model"]
)
else:
net_d.load_state_dict(
torch.load(pretrainD, map_location="cpu")["model"]
torch.load(pretrainD, map_location="cpu", weights_only=True)["model"]
)

# Initialize schedulers
Expand Down
2 changes: 1 addition & 1 deletion rvc/train/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def load_checkpoint(checkpoint_path, model, optimizer=None, load_opt=1):
checkpoint_path
), f"Checkpoint file not found: {checkpoint_path}"

checkpoint_dict = torch.load(checkpoint_path, map_location="cpu")
checkpoint_dict = torch.load(checkpoint_path, map_location="cpu", weights_only=True)
checkpoint_dict = replace_keys_in_dict(
replace_keys_in_dict(
checkpoint_dict, ".weight_v", ".parametrizations.weight.original1"
Expand Down

0 comments on commit 11d1395

Please sign in to comment.