Skip to content

Disengage FBCache on the word of whoever owns it - #11304

Merged
danielhanchen merged 2 commits into
mainfrom
fix/auto-step-cache-disable-verification
Sep 18, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
fix/auto-step-cache-disable-verification

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The failure

Repo tests (CPU, rest) is red on main:

FAILED tests/test_video_backend.py::test_video_step_cache_auto_toggles_on_actual_steps
AssertionError: assert 'fbcache' is None

Bisected: passes at 9cf1f6e24^, fails at 9cf1f6e24 (#11174). CI's captured log names the branch outright:

diffusion.cache: fbcache disable unavailable (cache hooks could not be verified removed); running uncached

What #11174 got right, and where it reached too far

#11174 made the auto disengage refuse to clear _unsloth_step_cache until the private-name hook sweep confirms the hooks are gone. That is correct for the case it was written for: an adopted low-level cache, installed through apply_first_block_cache, leaves _cache_config as None, so diffusers' own disable_cache removes nothing. Clearing the marker there would clear it over live hooks, and the marker is what keeps the CUDA graph wrapper eager, so "cannot verify" genuinely has to mean "still engaged".

But the veto was applied unconditionally. When diffusers owns the cache, disable_cache() returning without raising is the evidence: it removed both hooks and cleared _cache_config itself. Requiring the private sweep on top makes every disengage depend on diffusers.hooks.first_block_cache staying importable, and on any version where it is not, FBCache stays engaged on short trajectories forever. That is the quality regression FBCACHE_MIN_STEPS exists to prevent: an 8-step trajectory has almost no headroom, which is the reason the auto bar is there at all.

The veto now applies only where the code's own comment says it is needed.

The test's stub was wrong too, and it is what hid this

diffusers.FirstBlockCacheConfig = lambda threshold = None: ("fbcache", threshold)

The cache layer matches on type(...).__name__ to tell its own FBCache config from a MagCache / PAB one. A plain tuple reads as "some other cache", so the teardown was unverifiable by construction. It is now a class named FirstBlockCacheConfig, exactly as test_diffusion_cache.py already does it, and the fake DiT records _cache_config the way diffusers does.

Robustification

Two regression tests, covering both directions. #11174 shipped 618 lines of tests that never reached this, because its harness always makes the sweep succeed; these deliberately make the private names unimportable:

  • a cache diffusers owns still disengages when diffusers.hooks.first_block_cache is gone;
  • an adopted cache that cannot be verified removed still reports fbcache, so the CUDA-graph hazard stays covered.

Verification

Sabotage, each half independently necessary:

change result
revert the product fix only 2 failed (the new test, and the video one)
revert the stub only 1 failed (the video one)
both restored 365 passed

Full studio/backend/tests run, branch vs clean main (9f76c5a3e), same host and same -n 8:

branch: 165 failed, 47711 passed, 200 errors
main:   166 failed, 47711 passed, 200 errors

Diffing the two failure sets: nothing fails only on the branch, and exactly one failure exists only on main -- test_video_step_cache_auto_toggles_on_actual_steps. The remaining 165 and the 200 errors are this workspace's environment (no CUDA runtime for bitsandbytes) and are identical on both sides.

test_video_backend.py::test_video_step_cache_auto_toggles_on_actual_steps is red on
main. Bisected: it passes at 9cf1f6e^ and fails at 9cf1f6e (#11174). CI's captured
log names the branch outright:

    diffusion.cache: fbcache disable unavailable (cache hooks could not be verified
    removed); running uncached

#11174 made the auto disengage refuse to clear the marker until the private-name hook
sweep confirms the hooks are gone. That is right for the case it was written for: an
ADOPTED low-level cache, installed through apply_first_block_cache, leaves _cache_config
None, so diffusers' own disable_cache removes nothing and trusting it would clear the
marker over live hooks. Clearing it there would let the CUDA graph wrapper capture across
them, so "cannot verify" has to mean "still engaged".

But the veto was applied unconditionally. When diffusers owns the cache, disable_cache
returning without raising IS the evidence: it removed both hooks and cleared the config
itself. Requiring the sweep on top makes every disengage depend on
diffusers.hooks.first_block_cache staying importable, and where it is not, FBCache stays
engaged on short trajectories forever -- the quality regression the auto policy exists to
prevent. The veto now applies only where the code's own comment says it is needed.

The test's diffusers stub was wrong too, and in a way that hid this: FirstBlockCacheConfig
was a lambda returning ("fbcache", threshold). The cache layer matches on
type(...).__name__ to tell its own config from a MagCache / PAB one, so a plain tuple read
as "some other cache" and made the teardown unverifiable by construction. It is now a
class named FirstBlockCacheConfig, as test_diffusion_cache.py already does, and the fake
DiT records _cache_config the way diffusers does.

Two regression tests cover both directions, since #11174's 618 lines of tests never
reached this: its harness always makes the sweep succeed.

Sabotage, each half independently necessary:
  revert the product fix only -> 2 failed (the new test, and the video one)
  revert the stub only        -> 1 failed (the video one)
  both restored               -> 365 passed
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 18, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-18T21:14:32.639421Z 31704b6 Manual request
🔒 Security Review ✅ Completed 2026-09-18T21:14:41.271464Z 31704b6 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 31704b6c9e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@chatgpt-codex-connector

Copy link
Copy Markdown

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: 31704b6c9e

View security finding report

Only the user who started this review can view the report in Codex.

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

@danielhanchen
danielhanchen merged commit c7d8980 into main Sep 18, 2026
39 of 45 checks passed
@danielhanchen
danielhanchen deleted the fix/auto-step-cache-disable-verification branch September 18, 2026 22:25
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
* Disengage FBCache on the word of whoever owns it

test_video_backend.py::test_video_step_cache_auto_toggles_on_actual_steps is red on
main. Bisected: it passes at 9cf1f6e^ and fails at 9cf1f6e (unslothai#11174). CI's captured
log names the branch outright:

    diffusion.cache: fbcache disable unavailable (cache hooks could not be verified
    removed); running uncached

unslothai#11174 made the auto disengage refuse to clear the marker until the private-name hook
sweep confirms the hooks are gone. That is right for the case it was written for: an
ADOPTED low-level cache, installed through apply_first_block_cache, leaves _cache_config
None, so diffusers' own disable_cache removes nothing and trusting it would clear the
marker over live hooks. Clearing it there would let the CUDA graph wrapper capture across
them, so "cannot verify" has to mean "still engaged".

But the veto was applied unconditionally. When diffusers owns the cache, disable_cache
returning without raising IS the evidence: it removed both hooks and cleared the config
itself. Requiring the sweep on top makes every disengage depend on
diffusers.hooks.first_block_cache staying importable, and where it is not, FBCache stays
engaged on short trajectories forever -- the quality regression the auto policy exists to
prevent. The veto now applies only where the code's own comment says it is needed.

The test's diffusers stub was wrong too, and in a way that hid this: FirstBlockCacheConfig
was a lambda returning ("fbcache", threshold). The cache layer matches on
type(...).__name__ to tell its own config from a MagCache / PAB one, so a plain tuple read
as "some other cache" and made the teardown unverifiable by construction. It is now a
class named FirstBlockCacheConfig, as test_diffusion_cache.py already does, and the fake
DiT records _cache_config the way diffusers does.

Two regression tests cover both directions, since unslothai#11174's 618 lines of tests never
reached this: its harness always makes the sweep succeed.

Sabotage, each half independently necessary:
  revert the product fix only -> 2 failed (the new test, and the video one)
  revert the stub only        -> 1 failed (the video one)
  both restored               -> 365 passed

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@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