Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions b/src/diffusers/guiders/guider_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)
# Avoid division by zero when std_cfg is zero, which can produce NaN/Inf in noise predictions
std_cfg = std_cfg.clamp(min=1e-8)
# rescale the results from guidance (fixes overexposure)
noise_pred_rescaled = noise_cfg * (std_text / std_cfg)
# mix with the original results from guidance by factor guidance_rescale to avoid "plain looking" images
2 changes: 2 additions & 0 deletions src/diffusers/guiders/guider_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ def rescale_noise_cfg(noise_cfg, noise_pred_text, guidance_rescale=0.0):
"""
std_text = noise_pred_text.std(dim=list(range(1, noise_pred_text.ndim)), keepdim=True)
std_cfg = noise_cfg.std(dim=list(range(1, noise_cfg.ndim)), keepdim=True)
# Avoid division by zero when std_cfg is zero, which can produce NaN/Inf in noise predictions
std_cfg = std_cfg.clamp(min=1e-8)
# rescale the results from guidance (fixes overexposure)
noise_pred_rescaled = noise_cfg * (std_text / std_cfg)
# mix with the original results from guidance by factor guidance_rescale to avoid "plain looking" images
Expand Down
Loading