Skip to content

Fix FasterCache crash and SmoothedEnergyGuidance hook install bugs#13

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

Fix FasterCache crash and SmoothedEnergyGuidance hook install bugs#13
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-fd39

Conversation

@cursor

@cursor cursor Bot commented Jun 24, 2026

Copy link
Copy Markdown

Summary

Fixes two critical correctness bugs found during automated review, plus a small tooling fix for copy checking in environments where ruff is not on PATH.

Bug 1: FasterCache crash on guidance-distilled models

Impact: Using FasterCache on Flux and other guidance-distilled transformers crashes on the first denoising step inside the configured attention skip timestep range.

Root cause: FasterCacheBlockHook attempted to read self.state.cache[-1] before any forward pass populated the cache. For guidance-distilled models, is_guidance_distilled=True forces attention skip even on iteration 0 when batch sizes match.

Trigger: FasterCacheConfig(is_guidance_distilled=True, spatial_attention_timestep_skip_range=(t_low, t_high), ...) with a timestep inside the skip range on the first block forward → TypeError: 'NoneType' object is not subscriptable.

Fix: Only allow attention skip when self.state.cache is not None, so the first forward computes normally and seeds the cache.

Validation: pytest tests/hooks/test_faster_cache.py — 1 passed

Bug 2: SmoothedEnergyGuidance completely broken

Impact: Smoothed Energy Guidance never installs query-blur hooks, so SEG has no effect regardless of configuration.

Root causes (two bugs):

  1. SmoothedEnergyGuidance.prepare_models overrides the base method without incrementing _count_prepared, so the hook gating condition is_conditional and _count_prepared > 1 is never satisfied.
  2. The seg_guidance_layers shorthand builds SmoothedEnergyGuidanceConfig(layer, fqn="auto"), passing an int to indices (which must be list[int]), causing TypeError during hook install — same class of bug as PR Fix LayerSkipConfig shorthand crash in SkipLayerGuidance and AutoGuidance #10 for LayerSkipConfig.

Fix:

  • Add self._count_prepared += 1 in prepare_models.
  • Pass indices=[layer] when building configs from shorthand.

Validation: pytest tests/guiders/test_smoothed_energy_guidance.py — 2 passed

Tooling

Existing open PRs (unchanged)

These tracked bugs still have open PRs awaiting review:

Open in Web View Automation 

- Guard FasterCacheBlockHook attention skip until cache is populated;
  guidance-distilled models previously crashed on the first forward
  inside the skip timestep range with TypeError on None cache.
- Add missing _count_prepared increment in SmoothedEnergyGuidance.prepare_models
  so SEG hooks are actually installed during inference.
- Pass indices=[layer] when building SmoothedEnergyGuidanceConfig from
  seg_guidance_layers shorthand (same int-vs-list bug as LayerSkipConfig).
- Invoke ruff via python -m in check_copies.py so copy checking works
  when ruff is not on PATH.

Add regression tests for both fixes.

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