mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 01:04:32 +02:00
Replace empty_cache with torch_gc
This commit is contained in:
@@ -111,10 +111,7 @@ class LDSR:
|
||||
eta = 1.0
|
||||
|
||||
gc.collect()
|
||||
if torch.cuda.is_available:
|
||||
torch.cuda.empty_cache()
|
||||
if devices.backend == 'ipex':
|
||||
torch.xpu.empty_cache()
|
||||
devices.torch_gc()
|
||||
|
||||
im_og = image
|
||||
width_og, height_og = im_og.size
|
||||
@@ -150,8 +147,7 @@ class LDSR:
|
||||
|
||||
del model
|
||||
gc.collect()
|
||||
if torch.cuda.is_available:
|
||||
torch.cuda.empty_cache()
|
||||
devices.torch_gc()
|
||||
|
||||
return a
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class UpscalerScuNET(modules.upscaler.Upscaler):
|
||||
|
||||
def do_upscale(self, img: PIL.Image.Image, selected_file):
|
||||
|
||||
torch.cuda.empty_cache()
|
||||
devices.torch_gc()
|
||||
|
||||
model = self.load_model(selected_file)
|
||||
if model is None:
|
||||
@@ -112,7 +112,7 @@ class UpscalerScuNET(modules.upscaler.Upscaler):
|
||||
torch_output = torch_output[:, :h * 1, :w * 1] # remove padding, if any
|
||||
np_output: np.ndarray = torch_output.float().cpu().clamp_(0, 1).numpy()
|
||||
del torch_img, torch_output
|
||||
torch.cuda.empty_cache()
|
||||
devices.torch_gc()
|
||||
|
||||
output = np_output.transpose((1, 2, 0)) # CHW to HWC
|
||||
output = output[:, :, ::-1] # BGR to RGB
|
||||
|
||||
@@ -40,13 +40,7 @@ class UpscalerSwinIR(Upscaler):
|
||||
return img
|
||||
model = model.to(device_swinir, dtype=devices.dtype)
|
||||
img = upscale(img, model)
|
||||
try:
|
||||
if devices.backend == 'ipex':
|
||||
torch.xpu.empty_cache()
|
||||
else:
|
||||
torch.cuda.empty_cache()
|
||||
except Exception:
|
||||
pass
|
||||
devices.torch_gc()
|
||||
return img
|
||||
|
||||
def load_model(self, path, scale=4):
|
||||
|
||||
@@ -101,10 +101,7 @@ def setup_model(dirname):
|
||||
output = self.net(cropped_face_t, w=w if w is not None else shared.opts.code_former_weight, adain=True)[0]
|
||||
restored_face = tensor2img(output, rgb2bgr=True, min_max=(-1, 1))
|
||||
del output
|
||||
if devices.backend == 'ipex':
|
||||
torch.xpu.empty_cache()
|
||||
else:
|
||||
torch.cuda.empty_cache()
|
||||
devices.torch_gc()
|
||||
except Exception as error:
|
||||
print(f'\tFailed inference for CodeFormer: {error}', file=sys.stderr)
|
||||
restored_face = tensor2img(cropped_face_t, rgb2bgr=True, min_max=(-1, 1))
|
||||
|
||||
+1
-1
@@ -193,7 +193,7 @@ else:
|
||||
if backend == 'ipex':
|
||||
#Fix broken functions with ipex
|
||||
from modules.sd_hijack_utils import CondFunc
|
||||
torch.cuda.empty_cache = torch.xpu.empty_cache
|
||||
torch.cuda.empty_cache = torch_gc
|
||||
|
||||
#Functions with dtype errors:
|
||||
CondFunc('torch.nn.modules.GroupNorm.forward',
|
||||
|
||||
Reference in New Issue
Block a user