-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incorrect stochastic adjustment -- image goes to black when eta > 0 #1
Comments
Hi author, Many thanks |
probably some values are going out of range, either blowing up or going to zero? I have not figured it out, but made a request at the TCD authors’ repository. Diffusers architecture is quite different than ComfyUI scheduling, I couldn’t figure out how to properly offset the timestep by eta. |
Many thanks, I will check step by step. |
TCDScheduler node seems to be working (sample workflow that works pretty nicely below), but when trying to use SamplerTCD - always black output. |
What about this implementation? @torch.no_grad()
def sampler_tcd(model, x, sigmas, extra_args=None, callback=None, disable=None, noise_sampler=None, gamma=None):
extra_args = {} if extra_args is None else extra_args
noise_sampler = default_noise_sampler(x) if noise_sampler is None else noise_sampler
s_in = x.new_ones([x.shape[0]])
for i in trange(len(sigmas) - 1, disable=disable):
denoised = model(x, sigmas[i] * s_in, **extra_args)
if callback is not None:
callback({'x': x, 'i': i, 'sigma': sigmas[i], 'sigma_hat': sigmas[i], 'denoised': denoised})
d = to_d(x, sigmas[i], denoised)
sigma_from = sigmas[i]
sigma_to = sigmas[i + 1]
t = model.inner_model.inner_model.model_sampling.timestep(sigma_from)
down_t = (1 - gamma) * t
sigma_down = model.inner_model.inner_model.model_sampling.sigma(down_t)
if sigma_down > sigma_to:
sigma_down = sigma_to
sigma_up = (sigma_to ** 2 - sigma_down ** 2) ** 0.5
# same as euler ancestral
d = to_d(x, sigma_from, denoised)
dt = sigma_down - sigma_from
x = x + d * dt
if sigma_to > 0:
x = x + noise_sampler(sigma_from, sigma_to) * sigma_up
return x |
thanks @laksjdjf! This works, though somehow the quality is not as good as the reference implementation: https://huggingface.co/spaces/h1t/TCD is it correct to get sigmas from ddim_uniform scheduler? I picked that because I see some DDIM references inside the reference diffusers.TCDScheduler code. (edit: aha, I see now there should be some DDPM sampler behavior in the step, it is tricky to figure out how to normalize properly) (As an aside, Intuitively I think it would make more sense to have gamma=0 be soft like euler, and gamma=1.0 for noisy details) |
@josemerinom sorry I had a bad merge, please pull again |
there are some differences in structure between Diffusers (more explicit time scheduling) and ComfyUI (array of sigmas, and abstracted scheduling), so I was unable to correctly translate. Perhaps someone with more knowledge about diffusers could assist?
The text was updated successfully, but these errors were encountered: