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:
parent
15bb49e761
commit
ee023f4fbf
@ -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):
|
||||
"""
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user