mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-04-20 03:13:30 +00:00
Uni_PC: make max denoise behave more like other samplers.
On the KSamplers denoise of 1.0 is the same as txt2img but there was a small difference on UniPC.
This commit is contained in:
parent
c9daec4c89
commit
2976c1ad28
@ -833,7 +833,7 @@ def expand_dims(v, dims):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def sample_unipc(model, noise, image, sigmas, sampling_function, extra_args=None, callback=None, disable=None, noise_mask=None, variant='bh1'):
|
def sample_unipc(model, noise, image, sigmas, sampling_function, max_denoise, extra_args=None, callback=None, disable=None, noise_mask=None, variant='bh1'):
|
||||||
to_zero = False
|
to_zero = False
|
||||||
if sigmas[-1] == 0:
|
if sigmas[-1] == 0:
|
||||||
timesteps = torch.nn.functional.interpolate(sigmas[None,None,:-1], size=(len(sigmas),), mode='linear')[0][0]
|
timesteps = torch.nn.functional.interpolate(sigmas[None,None,:-1], size=(len(sigmas),), mode='linear')[0][0]
|
||||||
@ -847,7 +847,12 @@ def sample_unipc(model, noise, image, sigmas, sampling_function, extra_args=None
|
|||||||
ns = NoiseScheduleVP('discrete', alphas_cumprod=model.inner_model.alphas_cumprod)
|
ns = NoiseScheduleVP('discrete', alphas_cumprod=model.inner_model.alphas_cumprod)
|
||||||
|
|
||||||
if image is not None:
|
if image is not None:
|
||||||
img = image * ns.marginal_alpha(timesteps[0]) + noise * ns.marginal_std(timesteps[0])
|
img = image * ns.marginal_alpha(timesteps[0])
|
||||||
|
if max_denoise:
|
||||||
|
noise_mult = 1.0
|
||||||
|
else:
|
||||||
|
noise_mult = ns.marginal_std(timesteps[0])
|
||||||
|
img += noise * noise_mult
|
||||||
else:
|
else:
|
||||||
img = noise
|
img = noise
|
||||||
|
|
||||||
|
@ -334,6 +334,7 @@ class KSampler:
|
|||||||
self.sigma_min=float(self.model_wrap.sigma_min)
|
self.sigma_min=float(self.model_wrap.sigma_min)
|
||||||
self.sigma_max=float(self.model_wrap.sigma_max)
|
self.sigma_max=float(self.model_wrap.sigma_max)
|
||||||
self.set_steps(steps, denoise)
|
self.set_steps(steps, denoise)
|
||||||
|
self.denoise = denoise
|
||||||
|
|
||||||
def _calculate_sigmas(self, steps):
|
def _calculate_sigmas(self, steps):
|
||||||
sigmas = None
|
sigmas = None
|
||||||
@ -417,11 +418,16 @@ class KSampler:
|
|||||||
cond_concat.append(blank_inpaint_image_like(noise))
|
cond_concat.append(blank_inpaint_image_like(noise))
|
||||||
extra_args["cond_concat"] = cond_concat
|
extra_args["cond_concat"] = cond_concat
|
||||||
|
|
||||||
|
if sigmas[0] != self.sigmas[0] or (self.denoise is not None and self.denoise < 1.0):
|
||||||
|
max_denoise = False
|
||||||
|
else:
|
||||||
|
max_denoise = True
|
||||||
|
|
||||||
with precision_scope(self.device):
|
with precision_scope(self.device):
|
||||||
if self.sampler == "uni_pc":
|
if self.sampler == "uni_pc":
|
||||||
samples = uni_pc.sample_unipc(self.model_wrap, noise, latent_image, sigmas, sampling_function=sampling_function, extra_args=extra_args, noise_mask=denoise_mask)
|
samples = uni_pc.sample_unipc(self.model_wrap, noise, latent_image, sigmas, sampling_function=sampling_function, max_denoise=max_denoise, extra_args=extra_args, noise_mask=denoise_mask)
|
||||||
elif self.sampler == "uni_pc_bh2":
|
elif self.sampler == "uni_pc_bh2":
|
||||||
samples = uni_pc.sample_unipc(self.model_wrap, noise, latent_image, sigmas, sampling_function=sampling_function, extra_args=extra_args, noise_mask=denoise_mask, variant='bh2')
|
samples = uni_pc.sample_unipc(self.model_wrap, noise, latent_image, sigmas, sampling_function=sampling_function, max_denoise=max_denoise, extra_args=extra_args, noise_mask=denoise_mask, variant='bh2')
|
||||||
else:
|
else:
|
||||||
extra_args["denoise_mask"] = denoise_mask
|
extra_args["denoise_mask"] = denoise_mask
|
||||||
self.model_k.latent_image = latent_image
|
self.model_k.latent_image = latent_image
|
||||||
|
Loading…
Reference in New Issue
Block a user