From ec2890c19b2c6aad9869899e27da9f9c0d4180cd Mon Sep 17 00:00:00 2001 From: Jonathan <34005131+JPPhoto@users.noreply.github.com> Date: Fri, 24 Feb 2023 07:48:54 -0600 Subject: [PATCH] Run garbage collection to allow the CUDA cache to completely empty. (#2791) --- ldm/generate.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ldm/generate.py b/ldm/generate.py index 7695c3a0bc..413a1e25cb 100644 --- a/ldm/generate.py +++ b/ldm/generate.py @@ -650,6 +650,8 @@ class Generate: def clear_cuda_cache(self): if self._has_cuda(): self.gather_cuda_stats() + # Run garbage collection prior to emptying the CUDA cache + gc.collect() torch.cuda.empty_cache() def clear_cuda_stats(self):