F5-TTS Unload model correct tab

This commit is contained in:
erew123 authored and GitHub committed 2024-11-05 09:51:50 +00:00
1 parent 88c97ea700
commit 1a5945235d
1 file changed
+24 -24
+24 -24
View File
@@ -578,34 +578,34 @@ class tts_class:
print(f"[{self.branding}ENG] \033[91mError loading model: {str(e)}\033[0m") print(f"[{self.branding}ENG] \033[91mError loading model: {str(e)}\033[0m")
raise HTTPException(status_code=500, detail=f"Error loading model: {str(e)}") raise HTTPException(status_code=500, detail=f"Error loading model: {str(e)}")
############################### ###############################
############################### ###############################
# CHANGE ME # Model unloading # # CHANGE ME # Model unloading #
############################### ###############################
############################### ###############################
# This function will handle the UN-loading of your model, from VRAM/CUDA, System RAM or whatever. # This function will handle the UN-loading of your model, from VRAM/CUDA, System RAM or whatever.
async def unload_model(self): async def unload_model(self):
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
# ↑↑↑ Keep everything above this line ↑↑↑ # ↑↑↑ Keep everything above this line ↑↑↑
# ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ # ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑
"""Unload the F5-TTS model from memory""" """Unload the F5-TTS model from memory"""
if hasattr(self, 'model'): if hasattr(self, 'model'):
del self.model del self.model
self.model = None self.model = None
if hasattr(self, 'vocoder'): if hasattr(self, 'vocoder'):
del self.vocoder del self.vocoder
self.vocoder = None self.vocoder = None
if torch.cuda.is_available(): if torch.cuda.is_available():
torch.cuda.empty_cache() torch.cuda.empty_cache()
# ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
# ↓↓↓ Keep everything below this line ↓↓↓ # ↓↓↓ Keep everything below this line ↓↓↓
# ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓ # ↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
self.is_tts_model_loaded = False self.is_tts_model_loaded = False
return None return None
################################################################################################################################### ###################################################################################################################################
################################################################################################################################### ###################################################################################################################################