Skip to content

Conversation

@hopingZ
Copy link

@hopingZ hopingZ commented Jun 25, 2025

No description provided.

@robbiemu
Copy link

robbiemu commented Aug 11, 2025

Per my 30 minute forray into this intriguing 1-liner: This is the standard Classifier-Free Guidance (CFG) formula. You would very likely never want cond_logits_BxCxV when cfg_scale = 0 because the conditional model is usually undertrained (or performs poorly on its own).

Here's some LLM guidance on it:

When cfg_scale = 0 and you use pure conditional logits:

  • The model hasn't learned to generate high-quality outputs from the conditional path alone
  • It may produce outputs that are too conservative, repetitive, or low-quality
  • The conditional model "expects" to be corrected/guided by the CFG process

When cfg_scale = 0 and you use unconditional logits (correct behavior):

  • You get outputs from the path that was specifically trained to work independently
  • The model generates diverse, reasonable outputs without any text conditioning
  • This is the proper "baseline" behavior before applying any guidance

...

cfg_scale = 0 should mean "ignore the text condition entirely". If you use conditional logits when cfg_scale = 0, you're still using the text condition! This breaks the intended meaning of the parameter. The buggy version doesn't give you a way to get pure unconditional generation - even at cfg_scale = 0, you still get conditional outputs. This limits the model's flexibility and breaks user expectations about what the parameter should do.

--

maybe even better would be (For performance):

    if cfg_scale == 0.0:
        # Pure unconditional generation - no guidance
        logits_BxCxV = uncond_logits_BxCxV
    elif cfg_scale == 1.0:
        # Pure conditional generation - no CFG computation needed
        logits_BxCxV = cond_logits_BxCxV
    else:
        # Standard CFG formula: start from unconditional baseline and apply guidance
        logits_BxCxV = uncond_logits_BxCxV + cfg_scale * (cond_logits_BxCxV - uncond_logits_BxCxV)

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.

2 participants