fix: load model into local var before patching to avoid half-initialised state

Apply local-var-then-assign pattern to chatterbox_backend.py (multilingual)
to match the turbo backend. Also use _current_model_size fallback in
unload, delete, and status endpoints for consistent Qwen model size checks.
This commit is contained in:
James Pine
2026-03-13 05:40:18 -07:00
parent bfd7b815a5
commit 2f535a772f
3 changed files with 33 additions and 12 deletions
+12 -3
View File
@@ -1512,7 +1512,10 @@ async def unload_model_by_name(model_name: str):
try:
if model_type == "tts":
tts_model = tts.get_tts_model()
if tts_model.is_loaded() and tts_model.model_size == model_size:
loaded_size = getattr(
tts_model, "_current_model_size", None
) or getattr(tts_model, "model_size", None)
if tts_model.is_loaded() and loaded_size == model_size:
tts.unload_tts_model()
else:
return {"message": f"Model {model_name} is not loaded"}
@@ -1595,7 +1598,10 @@ async def get_model_status():
"""Check if TTS model is loaded with specific size."""
try:
tts_model = tts.get_tts_model()
return tts_model.is_loaded() and getattr(tts_model, 'model_size', None) == model_size
loaded_size = getattr(
tts_model, "_current_model_size", None
) or getattr(tts_model, "model_size", None)
return tts_model.is_loaded() and loaded_size == model_size
except Exception:
return False
@@ -2072,7 +2078,10 @@ async def delete_model(model_name: str):
# Check if model is loaded and unload it first
if config["model_type"] == "tts":
tts_model = tts.get_tts_model()
if tts_model.is_loaded() and tts_model.model_size == config["model_size"]:
loaded_size = getattr(
tts_model, "_current_model_size", None
) or getattr(tts_model, "model_size", None)
if tts_model.is_loaded() and loaded_size == config["model_size"]:
tts.unload_tts_model()
elif config["model_type"] == "luxtts":
from .backends import get_tts_backend_for_engine