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

Clamp Noise Offset Results #1173

Open
Haoming02 opened this issue Mar 12, 2024 · 3 comments
Open

Clamp Noise Offset Results #1173

Haoming02 opened this issue Mar 12, 2024 · 3 comments

Comments

@Haoming02
Copy link

Currently, is there any clipping/clamping done to the latents after using Noise Offset?

In my experience, I was training a LoRA for a character that wears a white uniform.
Everything works fine except... sometimes the uniform comes out as black when using the LoRA in generations.

Previously, I was also training a LoRA for a character that wears a blue dress.
Again, everything works fine except the dress often comes out red instead.

I highly suspect that, when applying the noise offsets, the resulting latents have values outside of what the model can handle, causing some sort of overflow, resulting in white becoming black as I experienced.

Therefore, I experimented by manually add a torch.clamp before the return of the apply_noise_offset function.

And as a result, the white uniform no longer becomes black during generation!

Is it just a coincidence? Or can someone verify this interactions? And perhaps implement a fix?

@gesen2egee
Copy link
Contributor

That sounds a bit scary.

What does the added code look like?
I'd like to test it to see if there's any difference.

@Haoming02
Copy link
Author

Haoming02 commented Mar 12, 2024

I changed the line above return to this:

    noise = torch.clamp(
        noise + noise_offset * torch.randn((latents.shape[0], latents.shape[1], 1, 1), device=latents.device),
        min=-4.0, max=4.0
    )

Also note: the min/max value for SD 1.5 and SDXL would be different iirc
The above is for SDXL

@gesen2egee
Copy link
Contributor

you can try this #1177
I get better result. (with --ip_noise_gamma=0.05 --ip_noise_gamma_random_strength)

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