kohya-ss / kohya-ss/sd-scripts
Clamp Noise Offset Results
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.2k
- Avg merge
- 11m
- Merged PRs (30d)
- 2
Description
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](https://github.com/kohya-ss/sd-scripts/blob/main/library/custom_train_functions.py#L474) 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?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in library/custom_train_functions.py at the apply_noise_offset function and inspect how its returned latents are consumed. Compare behavior with and without the reported torch.clamp, then define reproducible coverage for the white-to-black and blue-to-red cases; done means the cause is verified and the supported behavior is covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100