Merge remote-tracking branch 'upstream/main'

# Conflicts:
#	modules/async_worker.py
#	requirements_versions.txt
#	webui.py
This commit is contained in:
Manuel Schmid
2023-12-14 22:49:29 +01:00
205 changed files with 47072 additions and 2286 deletions
+31 -29
View File
@@ -8,26 +8,25 @@ import einops
import torch
import numpy as np
import fcbh.model_management
import fcbh.model_detection
import fcbh.model_patcher
import fcbh.utils
import fcbh.controlnet
import ldm_patched.modules.model_management
import ldm_patched.modules.model_detection
import ldm_patched.modules.model_patcher
import ldm_patched.modules.utils
import ldm_patched.modules.controlnet
import modules.sample_hijack
import fcbh.samplers
import fcbh.latent_formats
import ldm_patched.modules.samplers
import ldm_patched.modules.latent_formats
import modules.advanced_parameters
from fcbh.sd import load_checkpoint_guess_config
from nodes import VAEDecode, EmptyLatentImage, VAEEncode, VAEEncodeTiled, VAEDecodeTiled, \
from ldm_patched.modules.sd import load_checkpoint_guess_config
from ldm_patched.contrib.external import VAEDecode, EmptyLatentImage, VAEEncode, VAEEncodeTiled, VAEDecodeTiled, \
ControlNetApplyAdvanced
from fcbh_extras.nodes_freelunch import FreeU_V2
from fcbh.sample import prepare_mask
from modules.patch import patched_sampler_cfg_function
from ldm_patched.contrib.external_freelunch import FreeU_V2
from ldm_patched.modules.sample import prepare_mask
from modules.lora import match_lora
from fcbh.lora import model_lora_keys_unet, model_lora_keys_clip
from ldm_patched.modules.lora import model_lora_keys_unet, model_lora_keys_clip
from modules.config import path_embeddings
from fcbh_extras.nodes_model_advanced import ModelSamplingDiscrete
from ldm_patched.contrib.external_model_advanced import ModelSamplingDiscrete
opEmptyLatentImage = EmptyLatentImage()
@@ -98,7 +97,7 @@ class StableDiffusionModel:
self.clip_with_lora = self.clip.clone() if self.clip is not None else None
for lora_filename, weight in loras_to_load:
lora_unmatch = fcbh.utils.load_torch_file(lora_filename, safe_load=False)
lora_unmatch = ldm_patched.modules.utils.load_torch_file(lora_filename, safe_load=False)
lora_unet, lora_unmatch = match_lora(lora_unmatch, self.lora_key_map_unet)
lora_clip, lora_unmatch = match_lora(lora_unmatch, self.lora_key_map_clip)
@@ -136,7 +135,7 @@ def apply_freeu(model, b1, b2, s1, s2):
@torch.no_grad()
@torch.inference_mode()
def load_controlnet(ckpt_filename):
return fcbh.controlnet.load_controlnet(ckpt_filename)
return ldm_patched.modules.controlnet.load_controlnet(ckpt_filename)
@torch.no_grad()
@@ -150,7 +149,6 @@ def apply_controlnet(positive, negative, control_net, image, strength, start_per
@torch.inference_mode()
def load_model(ckpt_filename):
unet, clip, vae, clip_vision = load_checkpoint_guess_config(ckpt_filename, embedding_directory=path_embeddings)
unet.model_options['sampler_cfg_function'] = patched_sampler_cfg_function
return StableDiffusionModel(unet=unet, clip=clip, vae=vae, clip_vision=clip_vision, filename=ckpt_filename)
@@ -230,7 +228,7 @@ def get_previewer(model):
global VAE_approx_models
from modules.config import path_vae_approx
is_sdxl = isinstance(model.model.latent_format, fcbh.latent_formats.SDXL)
is_sdxl = isinstance(model.model.latent_format, ldm_patched.modules.latent_formats.SDXL)
vae_approx_filename = os.path.join(path_vae_approx, 'xlvaeapp.pth' if is_sdxl else 'vaeapp_sd15.pth')
if vae_approx_filename in VAE_approx_models:
@@ -242,14 +240,14 @@ def get_previewer(model):
del sd
VAE_approx_model.eval()
if fcbh.model_management.should_use_fp16():
if ldm_patched.modules.model_management.should_use_fp16():
VAE_approx_model.half()
VAE_approx_model.current_type = torch.float16
else:
VAE_approx_model.float()
VAE_approx_model.current_type = torch.float32
VAE_approx_model.to(fcbh.model_management.get_torch_device())
VAE_approx_model.to(ldm_patched.modules.model_management.get_torch_device())
VAE_approx_models[vae_approx_filename] = VAE_approx_model
@torch.no_grad()
@@ -273,7 +271,7 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa
previewer_start=None, previewer_end=None, sigmas=None, noise_mean=None):
if sigmas is not None:
sigmas = sigmas.clone().to(fcbh.model_management.get_torch_device())
sigmas = sigmas.clone().to(ldm_patched.modules.model_management.get_torch_device())
latent_image = latent["samples"]
@@ -281,7 +279,7 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa
noise = torch.zeros(latent_image.size(), dtype=latent_image.dtype, layout=latent_image.layout, device="cpu")
else:
batch_inds = latent["batch_index"] if "batch_index" in latent else None
noise = fcbh.sample.prepare_noise(latent_image, seed, batch_inds)
noise = ldm_patched.modules.sample.prepare_noise(latent_image, seed, batch_inds)
if isinstance(noise_mean, torch.Tensor):
noise = noise + noise_mean - torch.mean(noise, dim=1, keepdim=True)
@@ -299,7 +297,7 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa
previewer_end = steps
def callback(step, x0, x, total_steps):
fcbh.model_management.throw_exception_if_processing_interrupted()
ldm_patched.modules.model_management.throw_exception_if_processing_interrupted()
y = None
if previewer is not None and not modules.advanced_parameters.disable_preview and not (modules.config.default_black_out_nsfw and modules.config.default_hide_preview_if_black_out_nsfw):
y = previewer(x0, previewer_start + step, previewer_end)
@@ -309,14 +307,18 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=7.0, sa
disable_pbar = False
modules.sample_hijack.current_refiner = refiner
modules.sample_hijack.refiner_switch_step = refiner_switch
fcbh.samplers.sample = modules.sample_hijack.sample_hacked
ldm_patched.modules.samplers.sample = modules.sample_hijack.sample_hacked
try:
samples = fcbh.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
denoise=denoise, disable_noise=disable_noise, start_step=start_step,
last_step=last_step,
force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback,
disable_pbar=disable_pbar, seed=seed, sigmas=sigmas)
samples = ldm_patched.modules.sample.sample(model,
noise, steps, cfg, sampler_name, scheduler,
positive, negative, latent_image,
denoise=denoise, disable_noise=disable_noise,
start_step=start_step,
last_step=last_step,
force_full_denoise=force_full_denoise, noise_mask=noise_mask,
callback=callback,
disable_pbar=disable_pbar, seed=seed, sigmas=sigmas)
out = latent.copy()
out["samples"] = samples