Added memory clearance after deletion

This commit is contained in:
Ritesh Gangnani 2023-11-05 19:15:38 +05:30
parent ff1609f91e
commit 44db35fb1a

View File

@ -1,3 +1,5 @@
import gc
import torch import torch
from torch.nn.functional import silu from torch.nn.functional import silu
from types import MethodType from types import MethodType
@ -191,6 +193,8 @@ class StableDiffusionModelHijack:
delattr(m.model.diffusion_model.output_blocks[1][1].transformer_blocks,i) delattr(m.model.diffusion_model.output_blocks[1][1].transformer_blocks,i)
delattr(m.model.diffusion_model.output_blocks[4][1].transformer_blocks,'1') delattr(m.model.diffusion_model.output_blocks[4][1].transformer_blocks,'1')
delattr(m.model.diffusion_model.output_blocks[5][1].transformer_blocks,'1') delattr(m.model.diffusion_model.output_blocks[5][1].transformer_blocks,'1')
torch.cuda.empty_cache()
gc.collect()
def hijack(self, m): def hijack(self, m):
conditioner = getattr(m, 'conditioner', None) conditioner = getattr(m, 'conditioner', None)