Fix UniPC data cast and shape broadcast in #184

Fix UniPC data cast and shape broadcast in #184

This also fix potential problems in DDIM. The cause of this BUG is A1111’s `modules\models\diffusion\uni_pc\uni_pc.py` does not have a data cast and the Forge’s DDIM estimator forget to match the broadcast shape of sigmas.

(At the same time when we are fixing this BUG in A1111’s very original and high-quality samplers, comfyanonymous is still believing that Forge is using comfyui to sample images, eg, ComfyUI UniPC.
Comfyanonymous is so cute.
See also the jokes here https://github.com/lllyasviel/stable-diffusion-webui-forge/discussions/169#discussioncomment-8428689)
This commit is contained in:
lllyasviel 2024-02-10 18:35:42 -08:00
parent 15bb49e761
commit ee023f4fbf
2 changed files with 3 additions and 3 deletions

View File

@ -445,7 +445,7 @@ class UniPC:
s = torch.quantile(torch.abs(x0).reshape((x0.shape[0], -1)), p, dim=1)
s = expand_dims(torch.maximum(s, self.max_val * torch.ones_like(s).to(s.device)), dims)
x0 = torch.clamp(x0, -s, s) / s
return x0
return x0.to(x)
def model_fn(self, x, t):
"""

View File

@ -162,7 +162,7 @@ class CFGDenoiser(torch.nn.Module):
fake_sigmas = ((1 - acd) / acd) ** 0.5
real_sigma = fake_sigmas[sigma.round().long().clip(0, int(fake_sigmas.shape[0]))]
real_sigma_data = 1.0
x = x * (real_sigma ** 2.0 + real_sigma_data ** 2.0) ** 0.5
x = x * (((real_sigma ** 2.0 + real_sigma_data ** 2.0) ** 0.5)[:, None, None, None])
sigma = real_sigma
if sd_samplers_common.apply_refiner(self, x):
@ -195,7 +195,7 @@ class CFGDenoiser(torch.nn.Module):
self.step += 1
if self.classic_ddim_eps_estimation:
eps = (x - denoised) / sigma
eps = (x - denoised) / sigma[:, None, None, None]
return eps
return denoised.to(device=original_x_device, dtype=original_x_dtype)