Skip to content

Wait for the diffusion run record instead of sleeping 0.1s for it - #11263

Merged
danielhanchen merged 3 commits into
mainfrom
improve-diffusion-run-record-wait
Sep 18, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
improve-diffusion-run-record-wait

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

What

_pump_loop publishes the terminal status through _apply_event and only then calls _persist_run_record, from its own thread:

self._apply_event(ev, proc = proc)      # status goes "completed"
...
if ev.get("type") in _TERMINAL:
    ...
    self._persist_run_record()          # the file appears here

So _wait_status(svc, "completed") can return before the record exists. Two history tests bridged that with time.sleep(0.1) and the comment "give the thread a beat", which is a bet on the pump being scheduled inside the sleep.

_wait_record polls for the file with a 5 s bound and returns the parsed record. The tests now state the precondition they actually depend on, and a genuinely stuck pump fails with the pump never persisted <path> within 5.0s rather than a FileNotFoundError on a file that is about to appear. Nothing changes when the pump is prompt.

What this does not claim

I found this while triaging a red next to it, and I want to be exact about the connection, because there isn't a proven one.

Backend CI / (Python 3.13, a-k) failed on tests/test_diffusion_training.py::test_runs_route_tolerates_bad_field_record with:

AssertionError: assert ['out', 'good'] == ['good']

"out" is this file's own _CFG output_dir, and _isolated_runs_dir repoints _runs_dir per test, so a pump that persisted late would write into the next test's directory. That is a coherent story and it is why I looked here.

I could not reproduce it. I built the two-test probe it predicts, and it passed with and without a fix, including with _persist_run_record forcibly delayed by 1.5 s. I also wrote and then removed a fixture-level thread-join backstop, because I could not show it did anything, and machinery that looks protective without being tested is worse than none.

So: this PR is the robustness change only. The a-k failure stays open, cause unknown, same as #11241. The file passes 135/135 here either way, and it is not reproducible locally in any form I have found, so this should not be read as closing it.

Verification

  • tests/test_diffusion_training.py: 135 passed before and after. The isolated test passes alone and the whole file passes in declaration order, on main and on this branch.

@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-18T12:59:06.288317Z ac3c5bf Manual request
🔒 Security Review ✅ Completed 2026-09-18T11:24:19.290217Z 65e12e7 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.

@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@shimmyshimmer

Copy link
Copy Markdown
Member

@codex security review

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 65e12e705e

ℹ️ 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: 65e12e705e

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 force-pushed the improve-diffusion-run-record-wait branch from 65e12e7 to 4b654fb Compare September 18, 2026 11:50
@danielhanchen
danielhanchen changed the base branch from main to fix-desktop-branding-contract September 18, 2026 11:50
@danielhanchen
danielhanchen force-pushed the fix-desktop-branding-contract branch from 76d1742 to c9796c8 Compare September 18, 2026 12:15
@danielhanchen
danielhanchen force-pushed the improve-diffusion-run-record-wait branch from ed3303c to 896bc27 Compare September 18, 2026 12:15
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 896bc27965

ℹ️ 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".

@danielhanchen
danielhanchen force-pushed the improve-diffusion-run-record-wait branch from f13c683 to a1f7567 Compare September 18, 2026 12:32
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@shimmyshimmer

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1f7567418

ℹ️ 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".

for rail in _corner_rails(provider):
for token in rail.split():
utility = _split_variants(token)[1]
assert not re.fullmatch(r"p[xytblr]?-(\d+|\[[^\]]*rem[^\]]*\])", utility), (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject arbitrary important padding utilities

The new guard misses important arbitrary pixel utilities such as !pr-[0px] or md:!p-[4px]: _split_variants removes the !, but this regex only recognizes numeric spacing-scale utilities or arbitrary values containing rem. These classes override the inline gutter declarations with !important, so either rail can lose its shadow gutter or right inset while this regression test still passes. Broaden the check to reject important padding utilities with arbitrary values as well.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, fixed in 22c9c3a on #11268, which this PR is stacked on.

Your point that !pr-[0px] and md:!p-[4px] override the inline declarations outright is what settled the approach: matching values had an endless tail, so the check now matches the padding PROPERTY instead. The rail takes its padding from the inline px style, so any padding utility is a defect regardless of value. Both of your examples are in the seven sabotage cases.

@danielhanchen
danielhanchen force-pushed the fix-desktop-branding-contract branch from c9796c8 to b430ebb Compare September 18, 2026 12:51
Base automatically changed from fix-desktop-branding-contract to main September 18, 2026 12:51
@danielhanchen
danielhanchen changed the base branch from main to fix-overlay-rail-matchers September 18, 2026 12:53
@danielhanchen
danielhanchen force-pushed the improve-diffusion-run-record-wait branch from c005e68 to ac3c5bf Compare September 18, 2026 12:53
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: ac3c5bfec5

ℹ️ 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".

danielhanchen and others added 3 commits September 18, 2026 06:40
* Stop a redundant step-cache engage from tearing the cache down

diffusers' enable_cache raises ValueError when a cache is already enabled, so a second
apply_step_cache on the same transformer lands in the recovery branch, which calls
disable_cache() and returns None. One redundant call and the working First-Block-Cache is
gone, reported only at warning level.

Same settings are now a no-op. Different settings go through disable_cache first, which is
the only order diffusers accepts a new config in. The recovery branch also clears
_unsloth_step_cache: that marker is read well away from here as "this transformer step
caches" (the CUDA graph wrapper short-circuits to eager on it), so a marker left set by a
failed engage sends a transformer that is not caching down the caching path for the rest of
the process.

Latent rather than live: nothing on main calls apply_step_cache twice on one transformer
today. Three of the four new tests fail without the fix.

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

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

* Keep the step-cache marker when the cleanup could not take the hooks off

The recovery branch cleared _unsloth_step_cache unconditionally after a failed engage. If
disable_cache() ALSO raises, the hooks are still live, and clearing the marker there reintroduces the
desync this guard exists to remove, only pointing the other way.

The two directions are not equally bad. A marker left set on a transformer that is not caching forces
eager in the CUDA graph wrapper: slower, still correct. A marker cleared while hooks are live lets the
wrapper capture a graph over a cache-hooked forward, which is wrong output. So the marker now tracks
the hooks rather than this function's intent: it comes off when disable_cache succeeded, or when it
raised but the model still reports is_cache_enabled False, meaning the hooks went anyway. When
disable_cache raised and the cache reads as enabled, the marker stays and the slow path is the one we
land on.

Two tests: the preserved case fails without the change, and the paired case pins that a cleanup which
did unhook still clears the marker, so this does not just pin the marker on forever.

* Ask the model whether the re-configure cleanup actually unhooked

The re-entry guard's cleanup runs two statements, and which one raised changes the answer.
_restore_hooked_block_inners raising means disable_cache never ran, so the cache is still live and
reporting the prior mode is right. disable_cache raising can still have taken the hooks off first, and
there the old behaviour returned the prior mode and left the marker set on a transformer that no
longer caches: pinned to the eager path, and every later auto-cache call skipping the re-enable
because the marker says it is already caching.

So consult is_cache_enabled, as the failure-recovery branch below now does. Still caching keeps the
prior mode. Not caching means the reconfiguration this call asked for is what happened, so the stale
marker is dropped and the engage proceeds at the new settings.

Two tests, one per side. The re-engage case fails without the change.

* Take the cache hooks off directly instead of asking diffusers whether they are gone

After a failed enable_cache, neither signal the last round relied on can be trusted. Checked against
the pinned diffusers 0.40: CacheMixin.enable_cache assigns _cache_config as its LAST statement, after
apply_first_block_cache returns, and disable_cache logs a warning and returns when _cache_config is
None. So a raise part-way through hooking leaves the installed hooks LIVE while is_cache_enabled reads
False and disable_cache is a silent no-op. Both say uncached about a transformer that is partly hooked,
and clearing the marker there lets the CUDA graph wrapper capture that forward.

_unhook_first_block_cache removes both FBCache hooks by name through HookRegistry, the layer under
diffusers' own teardown. remove_hook skips a name that is not registered and recurses into every
submodule, so it is safe whatever got installed, and it clears the dangling _cache_config. The marker
now comes off only when that removal is known to have happened; when the registry or the hook names
cannot be reached it stays set and the transformer keeps the eager path, which is slower and not wrong.

The round-one test asserted the best answer available when is_cache_enabled was all we could ask; it
now asserts the stronger property that the hooks were actually removed. Two new tests, one modelling
the silent partial engage above and one the unverifiable teardown. Both new ones fail on the previous
head.

* Finish the teardown in the re-entry guard too, not just the recovery branch

disable_cache removes the FBC leader and block hooks in SEPARATE remove_hook calls and clears
_cache_config only after both, so a raise between them leaves block hooks installed with no leader to
make the skip decision, while is_cache_enabled still reads True. The guard then reported the prior
cache as healthy when half of it was gone, and the next generation skips blocks on stale state.

Half a cache is not the prior cache, so the guard now runs the same _unhook_first_block_cache the
recovery branch does: finish the removal by name, then re-engage at the new settings. It still reports
the prior mode when the removal cannot be verified at all, which is the only case left where asking
is the best available answer.

Both cleanup paths now go through one primitive instead of two different readings of is_cache_enabled.
The round-two test asserted the old diagnose-only behaviour and now covers the unverifiable case,
which is what it was really pinning; the new test for the mid-teardown raise fails on the previous head.

* Do not tear down a cache that is not ours

_cache_config is GENERIC across every cache CacheMixin supports, and disable_cache dispatches on its
type. So a transformer running MagCache, FasterCache or PAB whose teardown raises arrives in this
fallback looking exactly like a broken FBC one. Removing FBC's two hook names does nothing for it, and
clearing the state made diffusers forget a cache that is still installed, after which enable_cache
stacks FBC on top of the live hooks.

The unhook now declines when _cache_config is some other config type, which the caller already reads
as unverified: it reports the cache that is actually running and leaves it alone. Matched by class
name because the config is exported from two different modules depending on the diffusers version.

One test, failing without the change. The mid-teardown fixture from the last round used a bare object
as the stand-in config and is now an FBC-named one, which is what it was always meant to represent.

* Ask the model, not the marker, whether the call is redundant

The fast path compared _unsloth_step_cache against the requested settings, so a transformer whose
cache someone else engaged, or whose marker went stale, took the reconfigure path even when the live
FirstBlockCacheConfig already carried this exact threshold. That tears down a healthy cache and
rebuilds an identical one, which is the thing this guard exists to prevent, and loses it outright if
the rebuild then fails.

The live _cache_config decides now, and the marker is repaired on the way out rather than being
trusted as the source of truth. That is the same direction as the rest of the PR: every earlier round
established a way the marker can disagree with the hooks, so it is the derived value, not the fact.

One test, failing without the change: a transformer cached by hand, with no marker at all, keeps its
cache untouched and comes back with the marker written.

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

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

* Let only the live cache config authorize the no-op, and integrate one we adopt

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

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

* Leave an FBCache installed through the low-level API alone

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

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

* Integrate and mark a low-level cache before reporting it engaged

Adopting hooks installed through apply_first_block_cache ran neither post-enable
step and left _unsloth_step_cache clear over live hooks, which is the marker
GraphedForward.__call__ short-circuits to eager on: the CUDA graph wrapper could
capture a cache-hooked forward whose skip decision is data-dependent. Run the
same integration the live-config branch runs, and set the marker (mode only,
since the adopted cache's threshold is its installer's) before returning.

* Unhook an adopted cache in auto mode instead of trusting disable_cache

A cache adopted from apply_first_block_cache has no _cache_config, so diffusers'
disable_cache warns and returns having removed nothing. maybe_toggle_step_cache
cleared the marker on the strength of that call, leaving it clear over live FBCache
hooks and reporting the transformer uncached, which is the state GraphedForward
reads as safe to capture. Take the hooks off by name and clear the marker only once
they are known gone; an unverifiable teardown keeps the marker and stays engaged.

* Trim the comments added by this branch

Comments only, AST verified. diffusion_cache.py 111 comment lines to 71 (24.1% to
17.1% of non-blank); the merge base was 11.9%, so the excess was this branch's.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
_pump_loop publishes the terminal status through _apply_event and only then calls
_persist_run_record, from its own thread, so _wait_status can return before the
file exists. Two history tests bridged that with time.sleep(0.1) and a comment
saying "give the thread a beat", which is a bet on the pump being scheduled
inside the sleep.

_wait_record polls for the file with a 5s bound and returns the parsed record, so
the tests state the precondition they actually depend on and fail with "the pump
never persisted <path>" rather than FileNotFoundError on a file that is about to
appear. No behaviour change when the pump is prompt.

This is a robustness change, not a claimed fix: I could not reproduce the
(Python 3.13, a-k) failure it was found next to. See the pull request for what
that leaves open.
@danielhanchen
danielhanchen changed the base branch from fix-overlay-rail-matchers to main September 18, 2026 13:43
@danielhanchen
danielhanchen force-pushed the improve-diffusion-run-record-wait branch from ac3c5bf to 92ebe53 Compare September 18, 2026 13:43
@danielhanchen
danielhanchen merged commit 5c14484 into main Sep 18, 2026
8 of 34 checks passed
@danielhanchen
danielhanchen deleted the improve-diffusion-run-record-wait branch September 18, 2026 13:48
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…slothai#11263)

* Stop a redundant step-cache engage from tearing the cache down (unslothai#11174)

* Stop a redundant step-cache engage from tearing the cache down

diffusers' enable_cache raises ValueError when a cache is already enabled, so a second
apply_step_cache on the same transformer lands in the recovery branch, which calls
disable_cache() and returns None. One redundant call and the working First-Block-Cache is
gone, reported only at warning level.

Same settings are now a no-op. Different settings go through disable_cache first, which is
the only order diffusers accepts a new config in. The recovery branch also clears
_unsloth_step_cache: that marker is read well away from here as "this transformer step
caches" (the CUDA graph wrapper short-circuits to eager on it), so a marker left set by a
failed engage sends a transformer that is not caching down the caching path for the rest of
the process.

Latent rather than live: nothing on main calls apply_step_cache twice on one transformer
today. Three of the four new tests fail without the fix.

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

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

* Keep the step-cache marker when the cleanup could not take the hooks off

The recovery branch cleared _unsloth_step_cache unconditionally after a failed engage. If
disable_cache() ALSO raises, the hooks are still live, and clearing the marker there reintroduces the
desync this guard exists to remove, only pointing the other way.

The two directions are not equally bad. A marker left set on a transformer that is not caching forces
eager in the CUDA graph wrapper: slower, still correct. A marker cleared while hooks are live lets the
wrapper capture a graph over a cache-hooked forward, which is wrong output. So the marker now tracks
the hooks rather than this function's intent: it comes off when disable_cache succeeded, or when it
raised but the model still reports is_cache_enabled False, meaning the hooks went anyway. When
disable_cache raised and the cache reads as enabled, the marker stays and the slow path is the one we
land on.

Two tests: the preserved case fails without the change, and the paired case pins that a cleanup which
did unhook still clears the marker, so this does not just pin the marker on forever.

* Ask the model whether the re-configure cleanup actually unhooked

The re-entry guard's cleanup runs two statements, and which one raised changes the answer.
_restore_hooked_block_inners raising means disable_cache never ran, so the cache is still live and
reporting the prior mode is right. disable_cache raising can still have taken the hooks off first, and
there the old behaviour returned the prior mode and left the marker set on a transformer that no
longer caches: pinned to the eager path, and every later auto-cache call skipping the re-enable
because the marker says it is already caching.

So consult is_cache_enabled, as the failure-recovery branch below now does. Still caching keeps the
prior mode. Not caching means the reconfiguration this call asked for is what happened, so the stale
marker is dropped and the engage proceeds at the new settings.

Two tests, one per side. The re-engage case fails without the change.

* Take the cache hooks off directly instead of asking diffusers whether they are gone

After a failed enable_cache, neither signal the last round relied on can be trusted. Checked against
the pinned diffusers 0.40: CacheMixin.enable_cache assigns _cache_config as its LAST statement, after
apply_first_block_cache returns, and disable_cache logs a warning and returns when _cache_config is
None. So a raise part-way through hooking leaves the installed hooks LIVE while is_cache_enabled reads
False and disable_cache is a silent no-op. Both say uncached about a transformer that is partly hooked,
and clearing the marker there lets the CUDA graph wrapper capture that forward.

_unhook_first_block_cache removes both FBCache hooks by name through HookRegistry, the layer under
diffusers' own teardown. remove_hook skips a name that is not registered and recurses into every
submodule, so it is safe whatever got installed, and it clears the dangling _cache_config. The marker
now comes off only when that removal is known to have happened; when the registry or the hook names
cannot be reached it stays set and the transformer keeps the eager path, which is slower and not wrong.

The round-one test asserted the best answer available when is_cache_enabled was all we could ask; it
now asserts the stronger property that the hooks were actually removed. Two new tests, one modelling
the silent partial engage above and one the unverifiable teardown. Both new ones fail on the previous
head.

* Finish the teardown in the re-entry guard too, not just the recovery branch

disable_cache removes the FBC leader and block hooks in SEPARATE remove_hook calls and clears
_cache_config only after both, so a raise between them leaves block hooks installed with no leader to
make the skip decision, while is_cache_enabled still reads True. The guard then reported the prior
cache as healthy when half of it was gone, and the next generation skips blocks on stale state.

Half a cache is not the prior cache, so the guard now runs the same _unhook_first_block_cache the
recovery branch does: finish the removal by name, then re-engage at the new settings. It still reports
the prior mode when the removal cannot be verified at all, which is the only case left where asking
is the best available answer.

Both cleanup paths now go through one primitive instead of two different readings of is_cache_enabled.
The round-two test asserted the old diagnose-only behaviour and now covers the unverifiable case,
which is what it was really pinning; the new test for the mid-teardown raise fails on the previous head.

* Do not tear down a cache that is not ours

_cache_config is GENERIC across every cache CacheMixin supports, and disable_cache dispatches on its
type. So a transformer running MagCache, FasterCache or PAB whose teardown raises arrives in this
fallback looking exactly like a broken FBC one. Removing FBC's two hook names does nothing for it, and
clearing the state made diffusers forget a cache that is still installed, after which enable_cache
stacks FBC on top of the live hooks.

The unhook now declines when _cache_config is some other config type, which the caller already reads
as unverified: it reports the cache that is actually running and leaves it alone. Matched by class
name because the config is exported from two different modules depending on the diffusers version.

One test, failing without the change. The mid-teardown fixture from the last round used a bare object
as the stand-in config and is now an FBC-named one, which is what it was always meant to represent.

* Ask the model, not the marker, whether the call is redundant

The fast path compared _unsloth_step_cache against the requested settings, so a transformer whose
cache someone else engaged, or whose marker went stale, took the reconfigure path even when the live
FirstBlockCacheConfig already carried this exact threshold. That tears down a healthy cache and
rebuilds an identical one, which is the thing this guard exists to prevent, and loses it outright if
the rebuild then fails.

The live _cache_config decides now, and the marker is repaired on the way out rather than being
trusted as the source of truth. That is the same direction as the rest of the PR: every earlier round
established a way the marker can disagree with the hooks, so it is the derived value, not the fact.

One test, failing without the change: a transformer cached by hand, with no marker at all, keeps its
cache untouched and comes back with the marker written.

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

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

* Let only the live cache config authorize the no-op, and integrate one we adopt

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

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

* Leave an FBCache installed through the low-level API alone

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

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

* Integrate and mark a low-level cache before reporting it engaged

Adopting hooks installed through apply_first_block_cache ran neither post-enable
step and left _unsloth_step_cache clear over live hooks, which is the marker
GraphedForward.__call__ short-circuits to eager on: the CUDA graph wrapper could
capture a cache-hooked forward whose skip decision is data-dependent. Run the
same integration the live-config branch runs, and set the marker (mode only,
since the adopted cache's threshold is its installer's) before returning.

* Unhook an adopted cache in auto mode instead of trusting disable_cache

A cache adopted from apply_first_block_cache has no _cache_config, so diffusers'
disable_cache warns and returns having removed nothing. maybe_toggle_step_cache
cleared the marker on the strength of that call, leaving it clear over live FBCache
hooks and reporting the transformer uncached, which is the state GraphedForward
reads as safe to capture. Take the hooks off by name and clear the marker only once
they are known gone; an unverifiable teardown keeps the marker and stays engaged.

* Trim the comments added by this branch

Comments only, AST verified. diffusion_cache.py 111 comment lines to 71 (24.1% to
17.1% of non-blank); the merge base was 11.9%, so the excess was this branch's.

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>

* Wait for the diffusion run record instead of sleeping 0.1s for it

_pump_loop publishes the terminal status through _apply_event and only then calls
_persist_run_record, from its own thread, so _wait_status can return before the
file exists. Two history tests bridged that with time.sleep(0.1) and a comment
saying "give the thread a beat", which is a bet on the pump being scheduled
inside the sleep.

_wait_record polls for the file with a 5s bound and returns the parsed record, so
the tests state the precondition they actually depend on and fail with "the pump
never persisted <path>" rather than FileNotFoundError on a file that is about to
appear. No behaviour change when the pump is prompt.

This is a robustness change, not a claimed fix: I could not reproduce the
(Python 3.13, a-k) failure it was found next to. See the pull request for what
that leaves open.

* [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.

2 participants