Skip to content

Fix layer-skip guiders silently inert when CFG is disabled#23

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-7d29
Draft

Fix layer-skip guiders silently inert when CFG is disabled#23
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-7d29

Conversation

@cursor

@cursor cursor Bot commented Jun 29, 2026

Copy link
Copy Markdown

Summary

Fixes a critical correctness bug where Skip Layer Guidance, Perturbed Attention Guidance, and Smoothed Energy Guidance silently had no effect when used without classifier-free guidance.

Bug and impact

Impact: Using SLG, PAG, or SEG with guidance_scale=1.0 (CFG off) produces identical outputs to running without guidance — the skip/SEG hooks are never installed, so pred_cond - pred_cond_skip is always zero.

Root cause: Hook installation used is_conditional and _count_prepared > 1. is_conditional is only true for batches 1 and 3 (cond reference and skip pass when CFG is on). When CFG is off, the skip pass is batch 2, where is_conditional is false, so hooks never attach.

Trigger: SkipLayerGuidance(guidance_scale=1.0, skip_layer_guidance_scale=2.8, skip_layer_guidance_layers=[7]) on any modular pipeline — SLG appears enabled but has zero effect.

Fix

  • Add _should_apply_skip_hooks() / _should_apply_seg_hooks() to install hooks on batch 2 when CFG is off and batch 3 when CFG is on.
  • Propagate to PerturbedAttentionGuidance via copied blocks.
  • Add missing _count_prepared += 1 in SmoothedEnergyGuidance.prepare_models.

Validation

pytest tests/guiders/test_skip_layer_guidance.py — 2 passed

Existing open PRs (unchanged)

Open in Web View Automation 

When SkipLayerGuidance, PerturbedAttentionGuidance, or SmoothedEnergyGuidance
run without CFG (guidance_scale=1.0), the skip/SEG pass is batch 2. Hook
installation gated on is_conditional only matched batches 1 and 3, so skip
hooks were never applied and guidance silently had no effect.

Add _should_apply_skip_hooks/_should_apply_seg_hooks to install hooks on
batch 2 when CFG is off and batch 3 when CFG is on. Also increment
_count_prepared in SmoothedEnergyGuidance.prepare_models.

Co-authored-by: Simon Lynch <srlynch1@users.noreply.github.com>
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.

1 participant