From d1327f99f915aca83abac739107cdb8c5d29d278 Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Thu, 23 Mar 2023 22:12:24 -0300 Subject: [PATCH] Fix broken callbacks.py --- modules/callbacks.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/modules/callbacks.py b/modules/callbacks.py index 50a69183..93cd1d63 100644 --- a/modules/callbacks.py +++ b/modules/callbacks.py @@ -4,8 +4,6 @@ from threading import Thread import torch import transformers -from modules.text_generation import clear_torch_cache - # Copied from https://github.com/PygmalionAI/gradio-ui/ class _SentinelTokenStoppingCriteria(transformers.StoppingCriteria): @@ -89,3 +87,8 @@ class Iteratorize: def __exit__(self, exc_type, exc_val, exc_tb): self.stop_now = True clear_torch_cache() + +def clear_torch_cache(): + gc.collect() + if not shared.args.cpu: + torch.cuda.empty_cache()