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
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/easyanimate/pipeline_easyanimate.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/hunyuandit/pipeline_hunyuandit.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/ltx/pipeline_ltx.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/ltx/pipeline_ltx_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/ltx/pipeline_ltx_image2video.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/ltx2/pipeline_ltx2.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
5 changes: 5 additions & 0 deletions src/diffusers/pipelines/ltx2/pipeline_ltx2_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,11 @@ 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)
# rescale the results from guidance (fixes overexposure)
# Guard against `std_cfg == 0` (constant/zero `noise_cfg`, which can happen at the
# beginning of a schedule or in numerical edge cases): a raw division would produce
# `nan`/`inf` and silently corrupt the diffusion output (issue #13425). When the
# standard deviation of the guided prediction is zero, the rescaling is a no-op.
std_cfg = std_cfg.clamp(min=torch.finfo(noise_cfg.dtype).eps)
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
noise_cfg = guidance_rescale * noise_pred_rescaled + (1 - guidance_rescale) * noise_cfg
Expand Down
Loading
Loading