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
16 changes: 7 additions & 9 deletions src/diffusers/pipelines/z_image/pipeline_z_image_controlnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,11 @@ def __call__(
self._num_timesteps = len(timesteps)

# 6. Denoising loop
if self.do_classifier_free_guidance and self._cfg_truncation is not None and float(self._cfg_truncation) <= 1:
_precomputed_t_norms = ((1000 - timesteps.float()) / 1000).tolist()
else:
_precomputed_t_norms = None

with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
if self.interrupt:
Expand All @@ -628,17 +633,10 @@ def __call__(
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
timestep = t.expand(latents.shape[0])
timestep = (1000 - timestep) / 1000
# Normalized time for time-aware config (0 at start, 1 at end)
t_norm = timestep[0].item()

# Handle cfg truncation
current_guidance_scale = self.guidance_scale
if (
self.do_classifier_free_guidance
and self._cfg_truncation is not None
and float(self._cfg_truncation) <= 1
):
if t_norm > self._cfg_truncation:
if _precomputed_t_norms is not None:
if _precomputed_t_norms[i] > self._cfg_truncation:
current_guidance_scale = 0.0

# Run CFG only if configured AND scale is non-zero
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,11 @@ def __call__(
self._num_timesteps = len(timesteps)

# 6. Denoising loop
if self.do_classifier_free_guidance and self._cfg_truncation is not None and float(self._cfg_truncation) <= 1:
_precomputed_t_norms = ((1000 - timesteps.float()) / 1000).tolist()
else:
_precomputed_t_norms = None

with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
if self.interrupt:
Expand All @@ -655,17 +660,10 @@ def __call__(
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
timestep = t.expand(latents.shape[0])
timestep = (1000 - timestep) / 1000
# Normalized time for time-aware config (0 at start, 1 at end)
t_norm = timestep[0].item()

# Handle cfg truncation
current_guidance_scale = self.guidance_scale
if (
self.do_classifier_free_guidance
and self._cfg_truncation is not None
and float(self._cfg_truncation) <= 1
):
if t_norm > self._cfg_truncation:
if _precomputed_t_norms is not None:
if _precomputed_t_norms[i] > self._cfg_truncation:
current_guidance_scale = 0.0

# Run CFG only if configured AND scale is non-zero
Expand Down
16 changes: 7 additions & 9 deletions src/diffusers/pipelines/z_image/pipeline_z_image_img2img.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@ def __call__(
self._num_timesteps = len(timesteps)

# 8. Denoising loop
if self.do_classifier_free_guidance and self._cfg_truncation is not None and float(self._cfg_truncation) <= 1:
_precomputed_t_norms = ((1000 - timesteps.float()) / 1000).tolist()
else:
_precomputed_t_norms = None

with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
if self.interrupt:
Expand All @@ -614,17 +619,10 @@ def __call__(
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
timestep = t.expand(latents.shape[0])
timestep = (1000 - timestep) / 1000
# Normalized time for time-aware config (0 at start, 1 at end)
t_norm = timestep[0].item()

# Handle cfg truncation
current_guidance_scale = self.guidance_scale
if (
self.do_classifier_free_guidance
and self._cfg_truncation is not None
and float(self._cfg_truncation) <= 1
):
if t_norm > self._cfg_truncation:
if _precomputed_t_norms is not None:
if _precomputed_t_norms[i] > self._cfg_truncation:
current_guidance_scale = 0.0

# Run CFG only if configured AND scale is non-zero
Expand Down
16 changes: 7 additions & 9 deletions src/diffusers/pipelines/z_image/pipeline_z_image_inpaint.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,6 +811,11 @@ def __call__(
self._num_timesteps = len(timesteps)

# 9. Denoising loop
if self.do_classifier_free_guidance and self._cfg_truncation is not None and float(self._cfg_truncation) <= 1:
_precomputed_t_norms = ((1000 - timesteps.float()) / 1000).tolist()
else:
_precomputed_t_norms = None

with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
if self.interrupt:
Expand All @@ -819,17 +824,10 @@ def __call__(
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
timestep = t.expand(latents.shape[0])
timestep = (1000 - timestep) / 1000
# Normalized time for time-aware config (0 at start, 1 at end)
t_norm = timestep[0].item()

# Handle cfg truncation
current_guidance_scale = self.guidance_scale
if (
self.do_classifier_free_guidance
and self._cfg_truncation is not None
and float(self._cfg_truncation) <= 1
):
if t_norm > self._cfg_truncation:
if _precomputed_t_norms is not None:
if _precomputed_t_norms[i] > self._cfg_truncation:
current_guidance_scale = 0.0

# Run CFG only if configured AND scale is non-zero
Expand Down
16 changes: 7 additions & 9 deletions src/diffusers/pipelines/z_image/pipeline_z_image_omni.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,11 @@ def __call__(
self._num_timesteps = len(timesteps)

# 6. Denoising loop
if self.do_classifier_free_guidance and self._cfg_truncation is not None and float(self._cfg_truncation) <= 1:
_precomputed_t_norms = ((1000 - timesteps.float()) / 1000).tolist()
else:
_precomputed_t_norms = None

with self.progress_bar(total=num_inference_steps) as progress_bar:
for i, t in enumerate(timesteps):
if self.interrupt:
Expand All @@ -631,17 +636,10 @@ def __call__(
# broadcast to batch dimension in a way that's compatible with ONNX/Core ML
timestep = t.expand(latents.shape[0])
timestep = (1000 - timestep) / 1000
# Normalized time for time-aware config (0 at start, 1 at end)
t_norm = timestep[0].item()

# Handle cfg truncation
current_guidance_scale = self.guidance_scale
if (
self.do_classifier_free_guidance
and self._cfg_truncation is not None
and float(self._cfg_truncation) <= 1
):
if t_norm > self._cfg_truncation:
if _precomputed_t_norms is not None:
if _precomputed_t_norms[i] > self._cfg_truncation:
current_guidance_scale = 0.0

# Run CFG only if configured AND scale is non-zero
Expand Down
Loading