Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batch fix for Prompt Matrix #12509

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 35 additions & 7 deletions scripts/prompt_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,41 @@ def run(self, p, put_at_start, different_seeds, prompt_type, variations_delimite

print(f"Prompt matrix will create {len(all_prompts)} images using a total of {p.n_iter} batches.")

if prompt_type == "positive":
p.prompt = all_prompts
else:
p.negative_prompt = all_prompts
p.seed = [p.seed + (i if different_seeds else 0) for i in range(len(all_prompts))]
p.prompt_for_display = positive_prompt
processed = process_images(p)
alt_batch_size=len(all_prompts)%p.batch_size
if alt_batch_size:
p.n_iter-=1

processed=None
last_seed=None
if p.n_iter:
if prompt_type == "positive":
p.prompt = all_prompts[:len(all_prompts)-alt_batch_size]
else:
p.negative_prompt= all_prompts[:len(all_prompts)-alt_batch_size]
p.seed = [p.seed + (i if different_seeds else 0) for i in range(len(all_prompts)-alt_batch_size)]
last_seed=p.seed[-1]
p.prompt_for_display = positive_prompt
processed = process_images(p)

if alt_batch_size:
old_batch_size=p.batch_size
p.batch_size=alt_batch_size
p.n_iter=1
if prompt_type == "positive":
p.prompt = all_prompts[-alt_batch_size:]
else:
p.negative_prompt= all_prompts[-alt_batch_size:]
if last_seed:
p.seed = [last_seed+ (i if different_seeds else 0) for i in range(alt_batch_size)]
else:
p.seed = [p.seed + (i if different_seeds else 0) for i in range(alt_batch_size)]
new_processed=process_images(p)
if processed:
processed.images=processed.images+new_processed.images
processed.infotexts=processed.infotexts+new_processed.infotexts
else:
processed=new_processed
p.batch_size=old_batch_size

grid = images.image_grid(processed.images, p.batch_size, rows=1 << ((len(prompt_matrix_parts) - 1) // 2))
grid = images.draw_prompt_matrix(grid, processed.images[0].width, processed.images[0].height, prompt_matrix_parts, margin_size)
Expand Down