Skip to content
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

Add support to clip predicted samples to the desired range. #55

Open
Kinyugo opened this issue Mar 7, 2023 · 2 comments
Open

Add support to clip predicted samples to the desired range. #55

Kinyugo opened this issue Mar 7, 2023 · 2 comments

Comments

@Kinyugo
Copy link

Kinyugo commented Mar 7, 2023

In diffusion it is common to want to clip samples to a desired range like [-1, 1], I think previous versions of this package supported this. However, the current implementation does not support this.

I think it would be useful to support clipping samples to a desired range.

VSampler

  def forward(..., clip_denoised: bool = False, dynamic_threshold: float = 0.0) -> Tensor:
    ...
    x_pred = alphas[i] * x_noisy - betas[i] * v_pred 
    # Add clipping support here 
    if clip_denoised:
      clip(x_pred, dynamic_threshold=dynamic_threshold)
    ...

I am happy to open a PR if this is acceptable.

@flavioschneider
Copy link
Member

flavioschneider commented Mar 8, 2023

Hey Kinyugo! Looks good to me. Only things is that dynamic thresholding is usually applied inside the sampling loop not only at the end. So a simple x_pred.clamp(-1,1) is probably enough -- I didn't transfer dynamic thresholding to v-diff since I'm not sure it would play well inside the sampling loop as we're not only predicting the ground truth like with normal or k-diff.

@Kinyugo
Copy link
Author

Kinyugo commented Mar 23, 2023

Hello Flavio. It makes sense not have dynamic thresholding. Have you experimented with the effects of clipping on the final sample quality?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants