Fix FasterCache crash and SmoothedEnergyGuidance hook install bugs#13
Draft
cursor[bot] wants to merge 1 commit into
Draft
Fix FasterCache crash and SmoothedEnergyGuidance hook install bugs#13cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
- 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>
This was referenced Jun 26, 2026
Draft
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes two critical correctness bugs found during automated review, plus a small tooling fix for copy checking in environments where
ruffis 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:
FasterCacheBlockHookattempted to readself.state.cache[-1]before any forward pass populated the cache. For guidance-distilled models,is_guidance_distilled=Trueforces 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 passedBug 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):
SmoothedEnergyGuidance.prepare_modelsoverrides the base method without incrementing_count_prepared, so the hook gating conditionis_conditional and _count_prepared > 1is never satisfied.seg_guidance_layersshorthand buildsSmoothedEnergyGuidanceConfig(layer, fqn="auto"), passing an int toindices(which must belist[int]), causingTypeErrorduring hook install — same class of bug as PR Fix LayerSkipConfig shorthand crash in SkipLayerGuidance and AutoGuidance #10 forLayerSkipConfig.Fix:
self._count_prepared += 1inprepare_models.indices=[layer]when building configs from shorthand.Validation:
pytest tests/guiders/test_smoothed_energy_guidance.py— 2 passedTooling
utils/check_copies.py: invoke ruff viapython -m ruffso pre-commit copy checking works whenruffis not on PATH (same approach as PR Fix LayerSkipConfig shorthand crash in SkipLayerGuidance and AutoGuidance #10).Existing open PRs (unchanged)
These tracked bugs still have open PRs awaiting review: