From 9894db8a0b8fede4df290e04a4696725ce547c6b Mon Sep 17 00:00:00 2001 From: Mr-Neutr0n <64578610+Mr-Neutr0n@users.noreply.github.com> Date: Sat, 7 Feb 2026 13:38:19 +0530 Subject: [PATCH] fix: correct Z-Image guidance scale threshold from > 1 to > 0 Z-Image uses a non-standard CFG formula: pred = pos + scale * (pos - neg) Unlike the standard formula: pred = neg + scale * (pos - neg) With Z-Image's formula, any guidance_scale > 0 applies CFG effect. The previous > 1 check was incorrect and caused CFG to be ignored when 0 < guidance_scale < 1. Also updated docstring to document the correct Z-Image CFG formula. Fixes #12905 --- src/diffusers/pipelines/z_image/pipeline_z_image.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/diffusers/pipelines/z_image/pipeline_z_image.py b/src/diffusers/pipelines/z_image/pipeline_z_image.py index 82bdd7d361b7..6164d993e2d2 100644 --- a/src/diffusers/pipelines/z_image/pipeline_z_image.py +++ b/src/diffusers/pipelines/z_image/pipeline_z_image.py @@ -276,7 +276,7 @@ def guidance_scale(self): @property def do_classifier_free_guidance(self): - return self._guidance_scale > 1 + return self._guidance_scale > 0 @property def joint_attention_kwargs(self): @@ -335,10 +335,9 @@ def __call__( will be used. guidance_scale (`float`, *optional*, defaults to 5.0): Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598). - `guidance_scale` is defined as `w` of equation 2. of [Imagen - Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale > - 1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`, - usually at the expense of lower image quality. + Z-Image uses the formula `pred = pos + guidance_scale * (pos - neg)`, so guidance scale is enabled + by setting `guidance_scale > 0`. Higher guidance scale encourages to generate images that are closely + linked to the text `prompt`, usually at the expense of lower image quality. cfg_normalization (`bool`, *optional*, defaults to False): Whether to apply configuration normalization. cfg_truncation (`float`, *optional*, defaults to 1.0):