Spaces:
Runtime error
Runtime error
import gc | |
import torch.cuda | |
import comfy.model_management | |
class AnyType(str): | |
"""A special class that is always equal in not equal comparisons. Credit to pythongosssss""" | |
def __eq__(self, __value: object) -> bool: | |
return True | |
def __ne__(self, __value: object) -> bool: | |
return False | |
any = AnyType("*") | |
class PurgeVRAMNode: | |
def __init__(self): | |
pass | |
def INPUT_TYPES(cls): | |
return { | |
"required": { | |
"anything": (any, {}), | |
"purge_cache": ("BOOLEAN", {"default": True}), | |
"purge_models": ("BOOLEAN", {"default": True}), | |
}, | |
"optional": { | |
} | |
} | |
RETURN_TYPES = () | |
FUNCTION = "purge_vram" | |
CATEGORY = "tbox/other" | |
OUTPUT_NODE = True | |
def purge_vram(self, anything, purge_cache, purge_models): | |
gc.collect() | |
if torch.cuda.is_available(): | |
torch.cuda.empty_cache() | |
torch.cuda.ipc_collect() | |
if purge_models: | |
comfy.model_management.unload_all_models() | |
comfy.model_management.soft_empty_cache() | |
return (None,) | |