Skip to content

Fix PAB cond/uncond cache cross-contamination - #25

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

Fix PAB cond/uncond cache cross-contamination#25
cursor[bot] wants to merge 1 commit into
mainfrom
cursor/critical-bug-management-2387

Conversation

@cursor

@cursor cursor Bot commented Jun 30, 2026

Copy link
Copy Markdown

Summary

Fixes a critical correctness bug in Pyramid Attention Broadcast (PAB) where hook state was shared across cache_context boundaries.

Bug and impact

When PAB is enabled on pipelines that run separate conditional and unconditional transformer forwards (e.g. CogView4 with CFG, Flux with true CFG, QwenImage, etc.), the uncond pass could reuse cached cond attention outputs on skip steps. This silently corrupts classifier-free guidance and produces wrong generations.

Root cause

PyramidAttentionBroadcastHook stored iteration and cache on a single hook-level self.state object. ModelHook._set_context() only propagates to StateManager attributes, so entering cache_context("cond") vs cache_context("uncond") did not partition PAB state.

Fix

  • Migrate PAB to StateManager (same pattern as MagCache / FirstBlockCache)
  • Fall back to "inference" context when none is set (batch-concatenated pipelines)
  • Add regression test test_pab_isolates_state_between_cond_and_uncond_contexts
  • Update pipeline PAB tests to reference state_manager

Validation

  • pytest tests/hooks/test_pyramid_attention_broadcast.py passes
  • Test fails on pre-fix code (uncond pass skips attention and reuses cond cache)
Open in WebView Automation

PyramidAttentionBroadcastHook stored iteration and cache on a single
hook-level state object that ignored cache_context. Pipelines running
separate cond and uncond forwards (CogView4, Flux true CFG, etc.)
would reuse conditional attention outputs during the uncond pass when
PAB skipped computation, silently corrupting guidance.

Migrate PAB to StateManager so cond/uncond contexts maintain isolated
state, matching MagCache and FirstBlockCache. Add a regression test and
update pipeline PAB tests to use state_manager.

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