multiple patches

This commit is contained in:
Vladimir Mandic
2024-05-27 16:29:32 -04:00
parent 2f323aa55d
commit b5c1ec1941
10 changed files with 40 additions and 17 deletions
+3
View File
@@ -6,6 +6,9 @@ from modules.hidiffusion import hidiffusion
def apply_hidiffusion(p, model_type):
if model_type not in ['sd', 'sdxl'] and p.hidiffusion:
shared.log.warning(f'HiDiffusion: class={shared.sd_model.__class__.__name__} not supported')
return
remove_hidiffusion(p)
if p.hidiffusion:
t0 = time.time()
+14 -11
View File
@@ -92,17 +92,20 @@ def set_pipeline_args(p, model, prompts: list, negative_prompts: list, prompts_2
steps = kwargs.get("num_inference_steps", None) or len(getattr(p, 'timesteps', ['1']))
if 'timesteps' in possible:
try:
timesteps = re.split(',| ', shared.opts.schedulers_timesteps)
timesteps = [int(x) for x in timesteps if x.isdigit()]
if len(timesteps) > 0:
args['timesteps'] = timesteps
p.steps = len(timesteps)
p.timesteps = timesteps
steps = p.steps
shared.log.debug(f'Sampler: steps={len(timesteps)} timesteps={timesteps}')
except Exception as e:
shared.log.error(f'Sampler timesteps: {e}')
if hasattr(model.scheduler, 'set_timesteps') and "timesteps" in set(inspect.signature(model.scheduler.set_timesteps).parameters.keys()):
try:
timesteps = re.split(',| ', shared.opts.schedulers_timesteps)
timesteps = [int(x) for x in timesteps if x.isdigit()]
if len(timesteps) > 0:
args['timesteps'] = timesteps
p.steps = len(timesteps)
p.timesteps = timesteps
steps = p.steps
shared.log.debug(f'Sampler: steps={len(timesteps)} timesteps={timesteps}')
except Exception as e:
shared.log.error(f'Sampler timesteps: {e}')
else:
shared.log.warning(f'Sampler: sampler={model.scheduler.__class__.__name__} timesteps not supported')
if shared.opts.prompt_attention != 'Fixed attention' and ('StableDiffusion' in model.__class__.__name__ or 'StableCascade' in model.__class__.__name__) and 'Onnx' not in model.__class__.__name__:
try:
prompt_parser_diffusers.encode_prompts(model, p, prompts, negative_prompts, steps=steps, clip_skip=clip_skip)
+3 -3
View File
@@ -85,6 +85,7 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
shared.sd_model = update_pipeline(shared.sd_model, p)
shared.log.info(f'Base: class={shared.sd_model.__class__.__name__}')
update_sampler(p, shared.sd_model)
base_args = set_pipeline_args(
p=p,
model=shared.sd_model,
@@ -102,7 +103,6 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
clip_skip=p.clip_skip,
desc='Base',
)
update_sampler(p, shared.sd_model)
shared.state.sampling_steps = base_args.get('num_inference_steps', None) or p.steps
p.extra_generation_params['Pipeline'] = shared.sd_model.__class__.__name__
if shared.opts.scheduler_eta is not None and shared.opts.scheduler_eta > 0 and shared.opts.scheduler_eta < 1:
@@ -192,6 +192,7 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
sd_models.move_model(shared.sd_model, devices.device)
orig_denoise = p.denoising_strength
p.denoising_strength = getattr(p, 'hr_denoising_strength', p.denoising_strength)
update_sampler(p, shared.sd_model, second_pass=True)
hires_args = set_pipeline_args(
p=p,
model=shared.sd_model,
@@ -209,7 +210,6 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
strength=p.denoising_strength,
desc='Hires',
)
update_sampler(p, shared.sd_model, second_pass=True)
shared.state.job = 'HiRes'
shared.state.sampling_steps = hires_args.get('num_inference_steps', None) or p.steps
try:
@@ -257,6 +257,7 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
if hasattr(p, 'task_args') and 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
shared.log.info(f'Refiner: class={shared.sd_refiner.__class__.__name__}')
update_sampler(p, shared.sd_refiner, second_pass=True)
refiner_args = set_pipeline_args(
p=p,
model=shared.sd_refiner,
@@ -275,7 +276,6 @@ def process_diffusers(p: processing.StableDiffusionProcessing):
clip_skip=p.clip_skip,
desc='Refiner',
)
update_sampler(p, shared.sd_refiner, second_pass=True)
shared.state.sampling_steps = refiner_args.get('num_inference_steps', None) or p.steps
try:
if 'requires_aesthetics_score' in shared.sd_refiner.config: # sdxl-model needs false and sdxl-refiner needs true
+2
View File
@@ -610,6 +610,8 @@ def detect_pipeline(f: str, op: str = 'model', warning=True):
if 'stable-cascade' in f.lower() or 'stablecascade' in f.lower() or 'wuerstchen3' in f.lower():
if shared.backend == shared.Backend.ORIGINAL:
warn(f'Model detected as Stable Cascade model, but attempting to load using backend=original: {op}={f} size={size} MB')
if devices.dtype == torch.float16:
warn('Stable Cascade does not support Float16')
guess = 'Stable Cascade'
if 'pixart_sigma' in f.lower():
if shared.backend == shared.Backend.ORIGINAL:
+4 -1
View File
@@ -1,4 +1,5 @@
import os
import re
import inspect
from modules import shared
from modules import sd_samplers_common
@@ -128,7 +129,9 @@ class DiffusionSampler:
if shared.opts.schedulers_beta_schedule != 'default':
self.config['beta_schedule'] = shared.opts.schedulers_beta_schedule
if 'use_karras_sigmas' in self.config:
self.config['use_karras_sigmas'] = shared.opts.schedulers_use_karras
timesteps = re.split(',| ', shared.opts.schedulers_timesteps)
timesteps = [int(x) for x in timesteps if x.isdigit()]
self.config['use_karras_sigmas'] = shared.opts.schedulers_use_karras if len(timesteps) == 0 else False
if 'thresholding' in self.config:
self.config['thresholding'] = shared.opts.schedulers_use_thresholding
if 'lower_order_final' in self.config: