From fc8eca1c34ac54d42299d40859e11a261f8ecb07 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Sat, 12 Aug 2023 07:18:19 +0000 Subject: [PATCH] deallocate images on batch --- modules/images.py | 1 + modules/postprocessing.py | 1 + webui.py | 1 + 3 files changed, 3 insertions(+) diff --git a/modules/images.py b/modules/images.py index fdcbac1de..92ceb4e46 100644 --- a/modules/images.py +++ b/modules/images.py @@ -477,6 +477,7 @@ def atomically_save_image(): image.save(fn, format=image_format, quality=shared.opts.jpeg_quality) except Exception as e: shared.log.warning(f'Image save failed: {fn} {e}') + image.close() # additional metadata saved in files if shared.opts.save_txt and len(exifinfo) > 0: try: diff --git a/modules/postprocessing.py b/modules/postprocessing.py index 932b82289..4ff648461 100644 --- a/modules/postprocessing.py +++ b/modules/postprocessing.py @@ -76,6 +76,7 @@ def run_postprocessing(extras_mode, image, image_folder: List[tempfile.NamedTemp images.save_image(pp.image, path=outpath, basename=basename, seed=None, prompt=None, extension=ext or opts.samples_format, info=infotext, short_filename=True, no_prompt=True, grid=False, pnginfo_section_name="extras", existing_info=pp.image.info, forced_filename=None) if extras_mode != 2 or show_extras_results: outputs.append(pp.image) + image.close() devices.torch_gc() return outputs, infotext, params diff --git a/webui.py b/webui.py index d4feb3001..af2393d0a 100644 --- a/webui.py +++ b/webui.py @@ -17,6 +17,7 @@ local_url = None errors.log.debug('Loading Torch') import torch # pylint: disable=C0411 +errors.log.debug(f'Torch init: {torch.sum(torch.randn(2, 2)).to(0) > 0}') # fix silly pytorch_lightning issue try: import intel_extension_for_pytorch as ipex # pylint: disable=import-error, unused-import except Exception: