Tighten fault-path comments added by the video/diffusion hardening pass

This commit is contained in:
Daniel Han 2026-07-13 17:33:01 +00:00
commit 7e1bc5cbde
7 changed files with 22 additions and 33 deletions

View file

@ -681,9 +681,8 @@ def apply_step_cache(
disable_cache()
transformer._unsloth_step_cache = None
except Exception as rollback_exc: # noqa: BLE001
# Both the enable AND its cleanup failed: the transformer may keep partial hooks
# while we'd otherwise report a clean uncached None. Surface it so the caller
# reloads instead of generating on a half-cached model.
# Enable and its cleanup both failed: surface it so the caller reloads instead
# of generating on a half-cached model.
raise RuntimeError(
"step-cache enable failed and rollback also failed; the transformer may be "
"partially cached and must be reloaded "
@ -781,9 +780,8 @@ def maybe_toggle_step_cache(
# endswith, not substring: "#s5" would match inside "#s50".
and not str(engaged).endswith(f"#s{int(steps)}")
):
# A failed removal used to short-circuit and fall through to `return mode`, reporting
# "magcache" while the OLD #sN curve stayed armed (wrong ratio schedule, silently
# degraded output). Fail closed so the caller reloads instead.
# Fail closed: a failed removal would leave the old #sN curve armed while reporting
# "magcache" with the wrong ratio schedule.
if not _disengage_step_cache(
transformer, reason = f"magcache re-interpolating for {steps} steps", logger = logger
):
@ -805,8 +803,8 @@ def maybe_toggle_step_cache(
logger = logger,
)
if not want and engaged:
# Below the cache threshold we want uncached; a failed disable leaves the (possibly
# wrong-step) cache armed, so surface it rather than reporting the stale mode.
# Below the threshold we want uncached; a failed disable leaves the cache armed, so
# surface it instead of the stale mode.
if not _disengage_step_cache(
transformer,
reason = f"auto: {steps} steps < {FBCACHE_MIN_STEPS}",