Skip to content

Commit

Permalink
Merge pull request AUTOMATIC1111#4142 from jn-jairo/processing-close
Browse files Browse the repository at this point in the history
Release processing resources after it finishes
  • Loading branch information
AUTOMATIC1111 authored Nov 2, 2022
2 parents 10f6254 + c9148b2 commit 65522ff
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 2 additions & 0 deletions modules/img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def img2img(mode: int, prompt: str, negative_prompt: str, prompt_style: str, pro
if processed is None:
processed = process_images(p)

p.close()

shared.total_tqdm.clear()

generation_info_js = processed.js()
Expand Down
7 changes: 4 additions & 3 deletions modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def init(self, all_prompts, all_seeds, all_subseeds):
def sample(self, conditioning, unconditional_conditioning, seeds, subseeds, subseed_strength):
raise NotImplementedError()

def close(self):
self.sd_model = None
self.sampler = None


class Processed:
def __init__(self, p: StableDiffusionProcessing, images_list, seed=-1, info="", subseed=None, all_prompts=None, all_seeds=None, all_subseeds=None, index_of_first_image=0, infotexts=None):
Expand Down Expand Up @@ -597,9 +601,6 @@ def infotext(iteration=0, position_in_batch=0):
if p.scripts is not None:
p.scripts.postprocess(p, res)

p.sd_model = None
p.sampler = None

return res


Expand Down
2 changes: 2 additions & 0 deletions modules/txt2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ def txt2img(prompt: str, negative_prompt: str, prompt_style: str, prompt_style2:
if processed is None:
processed = process_images(p)

p.close()

shared.total_tqdm.clear()

generation_info_js = processed.js()
Expand Down

0 comments on commit 65522ff

Please sign in to comment.