Implement unload_text_encoder for memory cleanup

Add unload_text_encoder function to manage encoder memory.
This commit is contained in:
Vijaysinh 2025-11-28 18:30:33 +05:30 committed by GitHub
parent 387aeed9ce
commit 63419c107b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1550,6 +1550,7 @@ def unload_all_models_full():
logging.info("All models unloaded successfully (manual full unload).")
except Exception as e:
logging.warning(f"Model unload warning: {e}")
"""
@ -1559,4 +1560,14 @@ def cleanup_ram():
torch.cuda.empty_cache()
except:
pass
def unload_text_encoder(encoder):
if encoder is None:
return
try:
if hasattr(encoder, "model"):
del encoder.model
del encoder
except:
pass
cleanup_ram()