-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed as not planned
Description
Invoke has a threshold feature that currently applies only to k-diffusion samplers. This should be generalized to apply to all samplers and thus also for #1583.
Documentation of the feature: https://invoke-ai.github.io/InvokeAI/features/OTHER/#thresholding-and-perlin-noise-initialization-options
Current implementation is here:
InvokeAI/ldm/models/diffusion/ksampler.py
Lines 16 to 27 in f745f78
| def cfg_apply_threshold(result, threshold = 0.0, scale = 0.7): | |
| if threshold <= 0.0: | |
| return result | |
| maxval = 0.0 + torch.max(result).cpu().numpy() | |
| minval = 0.0 + torch.min(result).cpu().numpy() | |
| if maxval < threshold and minval > -threshold: | |
| return result | |
| if maxval > threshold: | |
| maxval = min(max(1, scale*maxval), threshold) | |
| if minval < -threshold: | |
| minval = max(min(-1, scale*minval), -threshold) | |
| return torch.clamp(result, min=minval, max=maxval) |
InvokeAI/ldm/models/diffusion/ksampler.py
Lines 51 to 60 in f745f78
| def forward(self, x, sigma, uncond, cond, cond_scale): | |
| next_x = self.invokeai_diffuser.do_diffusion_step(x, sigma, uncond, cond, cond_scale) | |
| if self.warmup < self.warmup_max: | |
| thresh = max(1, 1 + (self.threshold - 1) * (self.warmup / self.warmup_max)) | |
| self.warmup += 1 | |
| else: | |
| thresh = self.threshold | |
| if thresh > self.threshold: | |
| thresh = self.threshold | |
| return cfg_apply_threshold(next_x, thresh) |
I think this would be an appropriate thing to do in InvokeAIDiffuserComponent.