From c2a1decf1a23fb9b9481403c758a211300b17d16 Mon Sep 17 00:00:00 2001 From: kyo-zzz <1147385157@qq.com> Date: Mon, 31 Aug 2026 03:14:00 +0800 Subject: [PATCH] fix: actually load SoVITS weights in CLI and GUI entrypoints change_sovits_weights() is a generator function (it yields Gradio update dicts for the webui), but inference_cli.py and inference_gui.py called it as a plain statement. The call only built a generator object: the body never ran, so --sovits_model was silently ignored and synthesis used the default v2 model loaded at import time (fixes #2829). Iterating the generator end-to-end exposed a second latent bug: the post-load yield references six locals (prompt_text_update, prompt_language_update, text_update, text_language_update, visible_sample_steps, visible_inp_refs) that were only assigned when the webui passes UI language args, so any arg-less call raised UnboundLocalError at that yield - previously masked by the bare try/except around the import-time next(). Initialize them with neutral defaults; the webui path overwrites them unchanged. Verified on Windows/CPU with v2 pretrained models: a bogus --sovits_model now fails fast with FileNotFoundError instead of silently using the default model; a valid path loads (double 'loading sovits_v2' log) and synthesizes; the webui-style call still yields its two UI events. --- GPT_SoVITS/inference_cli.py | 5 ++++- GPT_SoVITS/inference_gui.py | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/GPT_SoVITS/inference_cli.py b/GPT_SoVITS/inference_cli.py index 459a3d36..e6e5ca33 100644 --- a/GPT_SoVITS/inference_cli.py +++ b/GPT_SoVITS/inference_cli.py @@ -28,7 +28,10 @@ def synthesize( # Change model weights change_gpt_weights(gpt_path=GPT_model_path) - change_sovits_weights(sovits_path=SoVITS_model_path) + # change_sovits_weights is a generator function (it yields UI update dicts): + # iterate it so the SoVITS weights actually load. + for _ in change_sovits_weights(sovits_path=SoVITS_model_path): + pass # Synthesize audio synthesis_result = get_tts_wav( diff --git a/GPT_SoVITS/inference_gui.py b/GPT_SoVITS/inference_gui.py index 379f7fa8..74651e6d 100644 --- a/GPT_SoVITS/inference_gui.py +++ b/GPT_SoVITS/inference_gui.py @@ -285,7 +285,10 @@ class GPTSoVITSGUI(QMainWindow): change_gpt_weights(gpt_path=GPT_model_path) self.GPT_Path = GPT_model_path if SoVITS_model_path != self.SoVITS_Path: - change_sovits_weights(sovits_path=SoVITS_model_path) + # change_sovits_weights is a generator function (it yields UI update dicts): + # iterate it so the SoVITS weights actually load. + for _ in change_sovits_weights(sovits_path=SoVITS_model_path): + pass self.SoVITS_Path = SoVITS_model_path synthesis_result = get_tts_wav(