mirror of
https://github.com/vladmandic/automatic
synced 2026-09-19 09:14:35 +02:00
fix hires batch, sdxl refiner
Signed-off-by: Vladimir Mandic <mandic00@live.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import time
|
||||
import inspect
|
||||
import torch
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from modules import shared, errors, sd_models, processing, processing_vae, processing_helpers, sd_hijack_hypertile, prompt_parser_diffusers, timer, extra_networks
|
||||
from modules.processing_callbacks import diffusers_callback_legacy, diffusers_callback, set_callbacks_p
|
||||
from modules.processing_helpers import resize_hires, fix_prompts, calculate_base_steps, calculate_hires_steps, calculate_refiner_steps, get_generator, set_latents, apply_circular # pylint: disable=unused-import
|
||||
@@ -22,7 +23,8 @@ def task_specific_kwargs(p, model):
|
||||
if len(getattr(p, 'init_images', [])) > 0:
|
||||
if isinstance(p.init_images[0], str):
|
||||
p.init_images = [helpers.decode_base64_to_image(i, quiet=True) for i in p.init_images]
|
||||
p.init_images = [i.convert('RGB') if i.mode != 'RGB' else i for i in p.init_images if i is not None]
|
||||
if isinstance(p.init_images[0], Image.Image):
|
||||
p.init_images = [i.convert('RGB') if i.mode != 'RGB' else i for i in p.init_images if i is not None]
|
||||
if (sd_models.get_diffusers_task(model) == sd_models.DiffusersTaskType.TEXT_2_IMAGE or len(getattr(p, 'init_images', [])) == 0) and not is_img2img_model:
|
||||
p.ops.append('txt2img')
|
||||
if hasattr(p, 'width') and hasattr(p, 'height'):
|
||||
@@ -99,7 +101,7 @@ def task_specific_kwargs(p, model):
|
||||
return task_args
|
||||
|
||||
|
||||
def set_pipeline_args(p, model, prompts: list, negative_prompts: list, prompts_2: typing.Optional[list]=None, negative_prompts_2: typing.Optional[list]=None, desc:str='', **kwargs):
|
||||
def set_pipeline_args(p, model, prompts:list, negative_prompts:list, prompts_2:typing.Optional[list]=None, negative_prompts_2:typing.Optional[list]=None, prompt_attention:typing.Optional[str]=None, desc:typing.Optional[str]='', **kwargs):
|
||||
t0 = time.time()
|
||||
shared.sd_model = sd_models.apply_balanced_offload(shared.sd_model)
|
||||
apply_circular(p.tiling, model)
|
||||
@@ -118,7 +120,8 @@ def set_pipeline_args(p, model, prompts: list, negative_prompts: list, prompts_2
|
||||
clip_skip = kwargs.pop("clip_skip", 1)
|
||||
|
||||
parser = 'fixed'
|
||||
if shared.opts.prompt_attention != 'fixed' and 'Onnx' not in model.__class__.__name__ and (
|
||||
prompt_attention = prompt_attention or shared.opts.prompt_attention
|
||||
if prompt_attention != 'fixed' and 'Onnx' not in model.__class__.__name__ and (
|
||||
'StableDiffusion' in model.__class__.__name__ or
|
||||
'StableCascade' in model.__class__.__name__ or
|
||||
'Flux' in model.__class__.__name__
|
||||
@@ -265,7 +268,7 @@ def set_pipeline_args(p, model, prompts: list, negative_prompts: list, prompts_2
|
||||
elif 'callback' in possible:
|
||||
args['callback'] = diffusers_callback_legacy
|
||||
|
||||
if 'image' in kwargs and len(getattr(p, 'init_images', [])) == 0:
|
||||
if 'image' in kwargs:
|
||||
p.init_images = kwargs['image'] if isinstance(kwargs['image'], list) else [kwargs['image']]
|
||||
|
||||
# handle remaining args
|
||||
|
||||
@@ -199,8 +199,6 @@ def process_hires(p: processing.StableDiffusionProcessing, output):
|
||||
if p.is_control and hasattr(p, 'task_args') and p.task_args.get('image', None) is not None:
|
||||
if hasattr(shared.sd_model, "vae") and output.images is not None and len(output.images) > 0:
|
||||
output.images = processing_vae.vae_decode(latents=output.images, model=shared.sd_model, full_quality=p.full_quality, output_type='pil', width=p.hr_upscale_to_x, height=p.hr_upscale_to_y) # controlnet cannnot deal with latent input
|
||||
p.init_images = output.images # replace so hires uses new output
|
||||
# p.task_args['image'] = output.images # replace so hires uses new output
|
||||
update_sampler(p, shared.sd_model, second_pass=True)
|
||||
orig_denoise = p.denoising_strength
|
||||
p.denoising_strength = strength
|
||||
@@ -289,10 +287,8 @@ def process_refine(p: processing.StableDiffusionProcessing, output):
|
||||
image = processing_vae.vae_decode(latents=image, model=shared.sd_model, full_quality=p.full_quality, output_type='pil', width=p.width, height=p.height)
|
||||
p.extra_generation_params['Noise level'] = noise_level
|
||||
output_type = 'np'
|
||||
if p.task_args.get('image', None) is not None and output is not None: # replace input with output so it can be used by hires/refine
|
||||
# p.task_args['image'] = image
|
||||
p.init_images = [image]
|
||||
update_sampler(p, shared.sd_refiner, second_pass=True)
|
||||
shared.opts.prompt_attention = 'fixed'
|
||||
refiner_args = set_pipeline_args(
|
||||
p=p,
|
||||
model=shared.sd_refiner,
|
||||
@@ -309,6 +305,7 @@ def process_refine(p: processing.StableDiffusionProcessing, output):
|
||||
image=image,
|
||||
output_type=output_type,
|
||||
clip_skip=p.clip_skip,
|
||||
prompt_attention='fixed',
|
||||
desc='Refiner',
|
||||
)
|
||||
shared.state.sampling_steps = refiner_args.get('prior_num_inference_steps', None) or p.steps or refiner_args.get('num_inference_steps', None)
|
||||
|
||||
@@ -170,6 +170,8 @@ def get_load_config(model_file, model_type, config_type='yaml'):
|
||||
return 'configs/sd15'
|
||||
if model_type == 'Stable Diffusion XL':
|
||||
return 'configs/sdxl'
|
||||
if model_type == 'Stable Diffusion XL Refiner':
|
||||
return 'configs/sdxl-refiner'
|
||||
if model_type == 'Stable Diffusion 3':
|
||||
return 'configs/sd3'
|
||||
if model_type == 'FLUX':
|
||||
|
||||
@@ -68,7 +68,7 @@ def get_pipelines():
|
||||
'Stable Diffusion Instruct': getattr(diffusers, 'StableDiffusionInstructPix2PixPipeline', None),
|
||||
'Stable Diffusion Upscale': getattr(diffusers, 'StableDiffusionUpscalePipeline', None),
|
||||
'Stable Diffusion XL': getattr(diffusers, 'StableDiffusionXLPipeline', None),
|
||||
'Stable Diffusion XL Refiner': getattr(diffusers, 'StableDiffusionXLPipeline', None),
|
||||
'Stable Diffusion XL Refiner': getattr(diffusers, 'StableDiffusionXLImg2ImgPipeline', None),
|
||||
'Stable Diffusion XL Img2Img': getattr(diffusers, 'StableDiffusionXLImg2ImgPipeline', None),
|
||||
'Stable Diffusion XL Inpaint': getattr(diffusers, 'StableDiffusionXLInpaintPipeline', None),
|
||||
'Stable Diffusion XL Instruct': getattr(diffusers, 'StableDiffusionXLInstructPix2PixPipeline', None),
|
||||
|
||||
@@ -418,7 +418,7 @@ class EmbeddingDatabase:
|
||||
self.word_embeddings.update(sorted_word_embeddings)
|
||||
|
||||
displayed_embeddings = (tuple(self.word_embeddings.keys()), tuple(self.skipped_embeddings.keys()))
|
||||
if self.previously_displayed_embeddings != displayed_embeddings:
|
||||
if self.previously_displayed_embeddings != displayed_embeddings and shared.opts.diffusers_enable_embed:
|
||||
self.previously_displayed_embeddings = displayed_embeddings
|
||||
t1 = time.time()
|
||||
shared.log.info(f"Load network: type=embeddings loaded={len(self.word_embeddings)} skipped={len(self.skipped_embeddings)} time={t1-t0:.2f}")
|
||||
|
||||
Reference in New Issue
Block a user