Skip to content

Commit

Permalink
Delete the cached objects explicitly.
Browse files Browse the repository at this point in the history
  • Loading branch information
Prashant Kumar committed Jan 6, 2023
1 parent 4102c12 commit fea1694
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions web/models/stable_diffusion/cache_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from models.stable_diffusion.schedulers import (
SharkEulerDiscreteScheduler,
)
import gc


model_config = {
Expand Down Expand Up @@ -81,6 +82,9 @@ def __init__(self):
self.version = None
self.schedulers = None
self.tokenizer = None
self.vae = None
self.clip = None
self.unet = None

def set_models(self, device_key):
if self.device != device_key or self.variant != args.variant:
Expand All @@ -91,6 +95,12 @@ def set_models(self, device_key):
args.max_length = 64
args.use_tuned = True
set_init_device_flags()
del self.schedulers
del self.tokenizer
del self.vae
del self.unet
del self.clip
gc.collect()
self.schedulers = get_schedulers(args.version)
self.tokenizer = get_tokenizer(args.version)
self.vae = get_vae()
Expand Down

0 comments on commit fea1694

Please sign in to comment.