From 63419c107bc23c0e7af1842605e66c7d77c273ed Mon Sep 17 00:00:00 2001 From: Vijaysinh Date: Fri, 28 Nov 2025 18:30:33 +0530 Subject: [PATCH] Implement unload_text_encoder for memory cleanup Add unload_text_encoder function to manage encoder memory. --- comfy/model_management.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/comfy/model_management.py b/comfy/model_management.py index 175af930c..ad2ffa253 100644 --- a/comfy/model_management.py +++ b/comfy/model_management.py @@ -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()