Skip to content

Commit

Permalink
change process_one virtual function for script to process_batch, add …
Browse files Browse the repository at this point in the history
…extra args and docs
  • Loading branch information
AUTOMATIC1111 committed Nov 4, 2022
1 parent 99043f3 commit eeb0733
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion modules/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ def infotext(iteration=0, position_in_batch=0):
break

if p.scripts is not None:
p.scripts.process_one(p, n)
p.scripts.process_batch(p, batch_number=n, prompts=prompts, seeds=seeds, subseeds=subseeds)

with devices.autocast():
uc = prompt_parser.get_learned_conditioning(shared.sd_model, len(prompts) * [p.negative_prompt], p.steps)
Expand Down
16 changes: 11 additions & 5 deletions modules/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ def process(self, p, *args):

pass

def process_one(self, p, n, *args):
def process_batch(self, p, *args, **kwargs):
"""
Same as process(), but called for every iteration
Same as process(), but called for every batch.
**kwargs will have those items:
- batch_number - index of current batch, from 0 to number of batches-1
- prompts - list of prompts for current batch; you can change contents of this list but changing the number of entries will likely break things
- seeds - list of seeds for current batch
- subseeds - list of subseeds for current batch
"""

pass
Expand Down Expand Up @@ -303,13 +309,13 @@ def process(self, p):
print(f"Error running process: {script.filename}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)

def process_one(self, p, n):
def process_batch(self, p, **kwargs):
for script in self.alwayson_scripts:
try:
script_args = p.script_args[script.args_from:script.args_to]
script.process_one(p, n, *script_args)
script.process_batch(p, *script_args, **kwargs)
except Exception:
print(f"Error running process_one: {script.filename}", file=sys.stderr)
print(f"Error running process_batch: {script.filename}", file=sys.stderr)
print(traceback.format_exc(), file=sys.stderr)

def postprocess(self, p, processed):
Expand Down

1 comment on commit eeb0733

@macrosoft
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that 'prompts', 'seeds' and 'subseeds' already exist in the 'p' object.

Please sign in to comment.