refactor(generation): simplify post-generation cache cleanup

Initialise tts_model before the try so the finally can read its device
without a locals() probe, import empty_device_cache alongside the other
backend imports instead of inside a bare try/except, and flatten the MPS
branch in empty_device_cache.
This commit is contained in:
jamiepine
2026-10-04 00:01:18 +00:00
committed by capy-ai-staging[bot]
parent 38389db82b
commit 17fd1ddd1b
2 changed files with 8 additions and 15 deletions
+2 -3
View File
@@ -219,9 +219,8 @@ def empty_device_cache(device: str) -> None:
torch.cuda.empty_cache()
elif device == "xpu" and hasattr(torch, "xpu"):
torch.xpu.empty_cache()
elif device == "mps" and hasattr(torch.backends, "mps") and torch.backends.mps.is_available():
if hasattr(torch.mps, "empty_cache"):
torch.mps.empty_cache()
elif device == "mps" and torch.backends.mps.is_available() and hasattr(torch.mps, "empty_cache"):
torch.mps.empty_cache()
def manual_seed(seed: int, device: str) -> None: