Skip to content

Commit 9894db8

Browse files
committed
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
1 parent 10dc589 commit 9894db8

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/diffusers/pipelines/z_image/pipeline_z_image.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def guidance_scale(self):
276276

277277
@property
278278
def do_classifier_free_guidance(self):
279-
return self._guidance_scale > 1
279+
return self._guidance_scale > 0
280280

281281
@property
282282
def joint_attention_kwargs(self):
@@ -335,10 +335,9 @@ def __call__(
335335
will be used.
336336
guidance_scale (`float`, *optional*, defaults to 5.0):
337337
Guidance scale as defined in [Classifier-Free Diffusion Guidance](https://arxiv.org/abs/2207.12598).
338-
`guidance_scale` is defined as `w` of equation 2. of [Imagen
339-
Paper](https://arxiv.org/pdf/2205.11487.pdf). Guidance scale is enabled by setting `guidance_scale >
340-
1`. Higher guidance scale encourages to generate images that are closely linked to the text `prompt`,
341-
usually at the expense of lower image quality.
338+
Z-Image uses the formula `pred = pos + guidance_scale * (pos - neg)`, so guidance scale is enabled
339+
by setting `guidance_scale > 0`. Higher guidance scale encourages to generate images that are closely
340+
linked to the text `prompt`, usually at the expense of lower image quality.
342341
cfg_normalization (`bool`, *optional*, defaults to False):
343342
Whether to apply configuration normalization.
344343
cfg_truncation (`float`, *optional*, defaults to 1.0):

0 commit comments

Comments
 (0)