M06: Extract prompt/seed prep to prompt_seed_prep.py

- Add modules/prompt_seed_prep.py with prepare_prompt_seed_state(p)
- Replace inline all_seeds/all_subseeds logic in process_images_inner
- Mutate p.seed/p.subseed before call; prepare_prompt_seed_state writes to p
- Behavior-preserving: fill_fields_from_opts, setup_prompts unchanged
- Phase II runtime seam preparation

Made-with: Cursor
This commit is contained in:
Michael Cahill 2026-03-09 23:15:47 -07:00
parent 595ea21752
commit 92fbf62319
4 changed files with 337 additions and 43 deletions

View file

@ -26,6 +26,7 @@ import modules.paths as paths
import modules.face_restoration
import modules.images as images
import modules.styles
import modules.prompt_seed_prep as prompt_seed_prep
import modules.runtime_utils as runtime_utils
import modules.sd_models as sd_models
import modules.sd_vae as sd_vae
@ -861,8 +862,8 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
devices.torch_gc()
seed = get_fixed_seed(p.seed)
subseed = get_fixed_seed(p.subseed)
p.seed = get_fixed_seed(p.seed)
p.subseed = get_fixed_seed(p.subseed)
if p.restore_faces is None:
p.restore_faces = opts.face_restoration
@ -889,15 +890,7 @@ def process_images_inner(p: StableDiffusionProcessing) -> Processed:
p.fill_fields_from_opts()
p.setup_prompts()
if isinstance(seed, list):
p.all_seeds = seed
else:
p.all_seeds = [int(seed) + (x if p.subseed_strength == 0 else 0) for x in range(len(p.all_prompts))]
if isinstance(subseed, list):
p.all_subseeds = subseed
else:
p.all_subseeds = [int(subseed) + x for x in range(len(p.all_prompts))]
prompt_seed_prep.prepare_prompt_seed_state(p)
if os.path.exists(cmd_opts.embeddings_dir) and not p.do_not_reload_embeddings:
model_hijack.embedding_db.load_textual_inversion_embeddings()

View file

@ -0,0 +1,30 @@
"""
Prompt and seed preparation for Stable Diffusion processing.
Extracted from processing.py (M06) to isolate preparation logic from sampling.
Behavior-preserving: writes directly to p; assumes setup_prompts() already ran.
"""
from __future__ import annotations
def prepare_prompt_seed_state(p):
"""
Populate p.all_seeds and p.all_subseeds from p.seed and p.subseed.
Assumes:
- p.seed and p.subseed have already been normalized via get_fixed_seed()
- p.setup_prompts() has already run (p.all_prompts exists)
"""
if isinstance(p.seed, list):
p.all_seeds = p.seed
else:
p.all_seeds = [
int(p.seed) + (x if p.subseed_strength == 0 else 0)
for x in range(len(p.all_prompts))
]
if isinstance(p.subseed, list):
p.all_subseeds = p.subseed
else:
p.all_subseeds = [int(p.subseed) + x for x in range(len(p.all_prompts))]