Skip to content

fix: correct Z-Image guidance scale threshold from > 1 to > 0#13094

Open
Mr-Neutr0n wants to merge 1 commit intohuggingface:mainfrom
Mr-Neutr0n:fix/z-image-guidance-scale-threshold
Open

fix: correct Z-Image guidance scale threshold from > 1 to > 0#13094
Mr-Neutr0n wants to merge 1 commit intohuggingface:mainfrom
Mr-Neutr0n:fix/z-image-guidance-scale-threshold

Conversation

@Mr-Neutr0n
Copy link

Summary

Fix incorrect do_classifier_free_guidance threshold check in Z-Image pipeline.

Problem

Z-Image uses a non-standard CFG formula:

pred = pos + guidance_scale * (pos - neg)

Unlike the standard formula:

pred = neg + guidance_scale * (pos - neg)

With Z-Image's formula:

  • guidance_scale = 0: pred = pos (conditional, no CFG)
  • guidance_scale = 0.5: pred = 1.5*pos - 0.5*neg (partial CFG)
  • guidance_scale = 1: pred = 2*pos - neg (standard CFG)

Any guidance_scale > 0 applies a CFG effect. The previous > 1 check was incorrect and caused CFG to be completely ignored when 0 < guidance_scale < 1.

Changes

  1. Changed do_classifier_free_guidance property from > 1 to > 0
  2. Updated docstring to document the Z-Image specific CFG formula

Fixes #12905

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 huggingface#12905
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong Z_Image guidance scale implementation

1 participant