From d4c9eb031c497ab4b4d7a63b118f3e21b022480e Mon Sep 17 00:00:00 2001 From: XXXXRT666 <157766680+XXXXRT666@users.noreply.github.com> Date: Fri, 5 Sep 2025 21:32:27 +0000 Subject: [PATCH] . --- GPT_SoVITS/BigVGAN/bigvgan.py | 2 +- GPT_SoVITS/BigVGAN/utils0.py | 2 +- GPT_SoVITS/inference_webui.py | 8 ++++---- GPT_SoVITS/module/models.py | 2 +- GPT_SoVITS/module/models_onnx.py | 2 +- GPT_SoVITS/module/modules.py | 2 +- GPT_SoVITS/module/mrte_model.py | 2 +- GPT_SoVITS/process_ckpt.py | 6 +++--- GPT_SoVITS/s2_train.py | 2 +- GPT_SoVITS/s2_train_v3.py | 2 +- GPT_SoVITS/s2_train_v3_lora.py | 2 +- GPT_SoVITS/utils.py | 10 ++++++++++ tools/AP_BWE/models/model.py | 2 +- 13 files changed, 27 insertions(+), 17 deletions(-) diff --git a/GPT_SoVITS/BigVGAN/bigvgan.py b/GPT_SoVITS/BigVGAN/bigvgan.py index 5cfc2376..1470c8fd 100644 --- a/GPT_SoVITS/BigVGAN/bigvgan.py +++ b/GPT_SoVITS/BigVGAN/bigvgan.py @@ -14,7 +14,7 @@ import torch.nn as nn from huggingface_hub import PyTorchModelHubMixin, hf_hub_download from torch.nn import Conv1d, ConvTranspose1d from torch.nn.utils import remove_weight_norm -from torch.nn.utils.parametrizations weight_norm +from torch.nn.utils import weight_norm from . import activations from .alias_free_activation.torch.act import Activation1d as TorchActivation1d diff --git a/GPT_SoVITS/BigVGAN/utils0.py b/GPT_SoVITS/BigVGAN/utils0.py index 7b2db0ff..2d66aa17 100644 --- a/GPT_SoVITS/BigVGAN/utils0.py +++ b/GPT_SoVITS/BigVGAN/utils0.py @@ -5,7 +5,7 @@ import glob import os import torch -from torch.nn.utils.parametrizations import weight_norm +from torch.nn.utils import weight_norm def init_weights(m, mean=0.0, std=0.01): diff --git a/GPT_SoVITS/inference_webui.py b/GPT_SoVITS/inference_webui.py index 363046ee..4faba94a 100644 --- a/GPT_SoVITS/inference_webui.py +++ b/GPT_SoVITS/inference_webui.py @@ -345,11 +345,10 @@ def change_sovits_weights(sovits_path, prompt_language=None, text_language=None) n_speakers=hps.data.n_speakers, **hps.model, ).eval() + if "pretrained" not in sovits_path: - try: + if hasattr(vq_model, "enc_q"): del vq_model.enc_q - finally: - pass if is_lora is False: console.print(f">> loading sovits_{model_version}", vq_model.load_state_dict(dict_s2["weight"], strict=False)) @@ -358,7 +357,8 @@ def change_sovits_weights(sovits_path, prompt_language=None, text_language=None) console.print(f">> loading sovits_{model_version}spretrained_G") dict_pretrain = torch.load(path_sovits)["weight"] console.print(f">> loading sovits_{model_version}_lora{model_version}") - state_dict = dict_pretrain.update(dict_s2["weight"]) + dict_pretrain.update(dict_s2["weight"]) + state_dict = dict_pretrain lora_rank = dict_s2["lora_rank"] lora_config = LoraConfig( target_modules=["to_k", "to_q", "to_v", "to_out.0"], diff --git a/GPT_SoVITS/module/models.py b/GPT_SoVITS/module/models.py index 7955083f..eb2960cc 100644 --- a/GPT_SoVITS/module/models.py +++ b/GPT_SoVITS/module/models.py @@ -8,7 +8,7 @@ from torch.cuda.amp import autocast from torch.nn import Conv1d, Conv2d, ConvTranspose1d from torch.nn import functional as F from torch.nn.utils import remove_weight_norm, spectral_norm -from torch.nn.utils.parametrizations import weight_norm +from torch.nn.utils import weight_norm from GPT_SoVITS.f5_tts.model import DiT from GPT_SoVITS.text import symbols as symbols_v1 diff --git a/GPT_SoVITS/module/models_onnx.py b/GPT_SoVITS/module/models_onnx.py index bd75b818..912539c3 100644 --- a/GPT_SoVITS/module/models_onnx.py +++ b/GPT_SoVITS/module/models_onnx.py @@ -6,7 +6,7 @@ from torch import nn from torch.nn import Conv1d, Conv2d, ConvTranspose1d from torch.nn import functional as F from torch.nn.utils import remove_weight_norm, spectral_norm -from torch.nn.utils.parametrizations import weight_norm +from torch.nn.utils import weight_norm from GPT_SoVITS.f5_tts.model import DiT from GPT_SoVITS.text import symbols as symbols_v1 diff --git a/GPT_SoVITS/module/modules.py b/GPT_SoVITS/module/modules.py index 8bfeffb7..ebf9e8d5 100644 --- a/GPT_SoVITS/module/modules.py +++ b/GPT_SoVITS/module/modules.py @@ -7,7 +7,7 @@ from torch import nn from torch.nn import Conv1d from torch.nn import functional as F from torch.nn.utils import remove_weight_norm -from torch.nn.utils.parametrizations import weight_norm +from torch.nn.utils import weight_norm from . import commons from .commons import get_padding, init_weights diff --git a/GPT_SoVITS/module/mrte_model.py b/GPT_SoVITS/module/mrte_model.py index 640bd71f..bf25cb07 100644 --- a/GPT_SoVITS/module/mrte_model.py +++ b/GPT_SoVITS/module/mrte_model.py @@ -3,7 +3,7 @@ import torch from torch import nn from torch.nn.utils import remove_weight_norm -from torch.nn.utils.parametrizations import weight_norm +from torch.nn.utils import weight_norm from .attentions import MultiHeadAttention diff --git a/GPT_SoVITS/process_ckpt.py b/GPT_SoVITS/process_ckpt.py index 8197cfa7..3a563a0b 100644 --- a/GPT_SoVITS/process_ckpt.py +++ b/GPT_SoVITS/process_ckpt.py @@ -30,7 +30,7 @@ def save_ckpt(ckpt, name, epoch, steps, hps, lora_rank=None): if "enc_q" in key: continue opt["weight"][key] = ckpt[key].half() - opt["config"] = hps.__dict__ + opt["config"] = hps.to_dict() opt["info"] = f"{epoch}epoch_{steps}iteration" if lora_rank: opt["lora_rank"] = lora_rank @@ -51,8 +51,8 @@ def inspect_version( dict_s2 = torch.load(f, map_location="cpu", mmap=True) hps = dict_s2["config"] version: str | None = None - if "version" in hps: - version = hps.version + if "version" in hps.keys(): + version = hps["version"] is_lora = "lora_rank" in dict_s2.keys() if version is not None: diff --git a/GPT_SoVITS/s2_train.py b/GPT_SoVITS/s2_train.py index 27cb93bf..b9cfc9f1 100644 --- a/GPT_SoVITS/s2_train.py +++ b/GPT_SoVITS/s2_train.py @@ -93,7 +93,7 @@ def run(rank, n_gpus, hps): diagnose=True, format="{time:YY-MM-DD HH:mm:ss}\t{name}\t{level}\t{message}", ) - console.print(hps.__dict__) + console.print(hps.to_dict()) writer: SummaryWriter | None = SummaryWriter(log_dir=hps.s2_ckpt_dir) writer_eval: SummaryWriter | None = SummaryWriter(log_dir=os.path.join(hps.s2_ckpt_dir, "eval")) else: diff --git a/GPT_SoVITS/s2_train_v3.py b/GPT_SoVITS/s2_train_v3.py index 82897190..414bdd00 100644 --- a/GPT_SoVITS/s2_train_v3.py +++ b/GPT_SoVITS/s2_train_v3.py @@ -88,7 +88,7 @@ def run(rank, n_gpus, hps): diagnose=True, format="{time:YY-MM-DD HH:mm:ss}\t{name}\t{level}\t{message}", ) - console.print(hps.__dict__) + console.print(hps.to_dict()) writer: SummaryWriter | None = SummaryWriter(log_dir=hps.s2_ckpt_dir) writer_eval: SummaryWriter | None = SummaryWriter(log_dir=os.path.join(hps.s2_ckpt_dir, "eval")) else: diff --git a/GPT_SoVITS/s2_train_v3_lora.py b/GPT_SoVITS/s2_train_v3_lora.py index 69cd1c4d..2186a467 100644 --- a/GPT_SoVITS/s2_train_v3_lora.py +++ b/GPT_SoVITS/s2_train_v3_lora.py @@ -97,7 +97,7 @@ def run(rank, n_gpus, hps): diagnose=True, format="{time:YY-MM-DD HH:mm:ss}\t{name}\t{level}\t{message}", ) - console.print(hps.__dict__) + console.print(hps.to_dict()) writer: SummaryWriter | None = SummaryWriter(log_dir=hps.s2_ckpt_dir) writer_eval: SummaryWriter | None = SummaryWriter(log_dir=os.path.join(hps.s2_ckpt_dir, "eval")) else: diff --git a/GPT_SoVITS/utils.py b/GPT_SoVITS/utils.py index 1467c318..a58430ad 100644 --- a/GPT_SoVITS/utils.py +++ b/GPT_SoVITS/utils.py @@ -360,3 +360,13 @@ class HParams: def __repr__(self): return self.__dict__.__repr__() + + def to_dict(self): + """Convert HParams to a plain dictionary recursively""" + result = {} + for k, v in self.__dict__.items(): + if isinstance(v, HParams): + result[k] = v.to_dict() + else: + result[k] = v + return result diff --git a/tools/AP_BWE/models/model.py b/tools/AP_BWE/models/model.py index ecd15802..51f7aa2f 100644 --- a/tools/AP_BWE/models/model.py +++ b/tools/AP_BWE/models/model.py @@ -5,7 +5,7 @@ import torch import torch.nn as nn import torch.nn.functional as F from torch.nn.utils import spectral_norm -from torch.nn.utils.parametrizations import weight_norm +from torch.nn.utils import weight_norm # from utils import init_weights, get_padding