[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
c998183cc2
commit
f7824b9db1
3 changed files with 126 additions and 45 deletions
|
|
@ -272,14 +272,17 @@ _CONFIGS: dict[str, dict[str, Any]] = {
|
|||
# (it auto-engages under any active speed tier), so trim_off isolates its win. The
|
||||
# trim key defaults True everywhere else; only this row forces it off.
|
||||
"trim_off": dict(
|
||||
te = "none", vae = "none", dit = "none", speed = "default", attn = "auto", cache = "off",
|
||||
te = "none",
|
||||
vae = "none",
|
||||
dit = "none",
|
||||
speed = "default",
|
||||
attn = "auto",
|
||||
cache = "off",
|
||||
trim = False,
|
||||
),
|
||||
# Compile isolation at matched attention/trim: eager tier (channels_last + cudnn
|
||||
# benchmark, NO compile) vs the "cudnn" row (default tier = regional compile).
|
||||
"eager_trim": dict(
|
||||
te = "none", vae = "none", dit = "none", speed = "eager", attn = "auto", cache = "off"
|
||||
),
|
||||
"eager_trim": dict(te = "none", vae = "none", dit = "none", speed = "eager", attn = "auto", cache = "off"),
|
||||
# int8 DiT baseline at the production attention stack (cudnn + trim), cache off,
|
||||
# directly comparable to the "cudnn" dense row.
|
||||
"int8_cudnn": dict(
|
||||
|
|
|
|||
|
|
@ -64,18 +64,108 @@ FBCACHE_MIN_STEPS = 20
|
|||
# enough -- diffusers interpolates it to the actual step count. Conditional-branch curve
|
||||
# per the MagCache calibration guidance.
|
||||
_MAGCACHE_720P_RATIOS = (
|
||||
1.0, 1.0226, 1.0093, 1.001, 1.0008, 1.0001, 0.9995, 1.0003, 0.9998, 0.9993, 0.9994, 0.9993,
|
||||
0.9997, 1.0002, 0.9994, 0.9985, 0.9987, 0.9997, 0.9979, 0.9987, 0.9985, 0.9982, 0.9977, 0.998,
|
||||
0.9979, 0.9971, 0.9968, 0.9967, 0.9964, 0.9965, 0.9959, 0.9954, 0.995, 0.9938, 0.9942, 0.9924,
|
||||
0.9924, 0.9907, 0.9905, 0.9878, 0.9867, 0.9845, 0.9808, 0.9773, 0.9715, 0.9652, 0.9529,
|
||||
0.9347, 0.9011, 0.83,
|
||||
1.0,
|
||||
1.0226,
|
||||
1.0093,
|
||||
1.001,
|
||||
1.0008,
|
||||
1.0001,
|
||||
0.9995,
|
||||
1.0003,
|
||||
0.9998,
|
||||
0.9993,
|
||||
0.9994,
|
||||
0.9993,
|
||||
0.9997,
|
||||
1.0002,
|
||||
0.9994,
|
||||
0.9985,
|
||||
0.9987,
|
||||
0.9997,
|
||||
0.9979,
|
||||
0.9987,
|
||||
0.9985,
|
||||
0.9982,
|
||||
0.9977,
|
||||
0.998,
|
||||
0.9979,
|
||||
0.9971,
|
||||
0.9968,
|
||||
0.9967,
|
||||
0.9964,
|
||||
0.9965,
|
||||
0.9959,
|
||||
0.9954,
|
||||
0.995,
|
||||
0.9938,
|
||||
0.9942,
|
||||
0.9924,
|
||||
0.9924,
|
||||
0.9907,
|
||||
0.9905,
|
||||
0.9878,
|
||||
0.9867,
|
||||
0.9845,
|
||||
0.9808,
|
||||
0.9773,
|
||||
0.9715,
|
||||
0.9652,
|
||||
0.9529,
|
||||
0.9347,
|
||||
0.9011,
|
||||
0.83,
|
||||
)
|
||||
_MAGCACHE_480P_RATIOS = (
|
||||
1.0, 1.0077, 1.0138, 1.0043, 1.0029, 0.9986, 0.9966, 1.0, 1.0006, 0.9996, 0.9993, 0.9986, 1.0,
|
||||
0.9993, 0.9966, 0.9986, 0.9988, 0.9991, 0.998, 0.9977, 0.9976, 0.9971, 0.9973, 0.9969, 0.996,
|
||||
0.9961, 0.9949, 0.9958, 0.9933, 0.9942, 0.9941, 0.9926, 0.9929, 0.9916, 0.9923, 0.9887, 0.99,
|
||||
0.9882, 0.9865, 0.9833, 0.9827, 0.9791, 0.9763, 0.9718, 0.9657, 0.9563, 0.9454, 0.9264,
|
||||
0.8967, 0.8382,
|
||||
1.0,
|
||||
1.0077,
|
||||
1.0138,
|
||||
1.0043,
|
||||
1.0029,
|
||||
0.9986,
|
||||
0.9966,
|
||||
1.0,
|
||||
1.0006,
|
||||
0.9996,
|
||||
0.9993,
|
||||
0.9986,
|
||||
1.0,
|
||||
0.9993,
|
||||
0.9966,
|
||||
0.9986,
|
||||
0.9988,
|
||||
0.9991,
|
||||
0.998,
|
||||
0.9977,
|
||||
0.9976,
|
||||
0.9971,
|
||||
0.9973,
|
||||
0.9969,
|
||||
0.996,
|
||||
0.9961,
|
||||
0.9949,
|
||||
0.9958,
|
||||
0.9933,
|
||||
0.9942,
|
||||
0.9941,
|
||||
0.9926,
|
||||
0.9929,
|
||||
0.9916,
|
||||
0.9923,
|
||||
0.9887,
|
||||
0.99,
|
||||
0.9882,
|
||||
0.9865,
|
||||
0.9833,
|
||||
0.9827,
|
||||
0.9791,
|
||||
0.9763,
|
||||
0.9718,
|
||||
0.9657,
|
||||
0.9563,
|
||||
0.9454,
|
||||
0.9264,
|
||||
0.8967,
|
||||
0.8382,
|
||||
)
|
||||
_MAGCACHE_FAMILY_RATIOS: dict[str, tuple[float, ...]] = {
|
||||
"hunyuanvideo-1.5": _MAGCACHE_480P_RATIOS,
|
||||
|
|
@ -156,7 +246,6 @@ def _ensure_block_metadata_registered(transformer: Any, logger: Any = None) -> N
|
|||
import importlib
|
||||
|
||||
from diffusers.hooks._helpers import TransformerBlockMetadata, TransformerBlockRegistry
|
||||
|
||||
for module_name, cls_name, hs_index, ehs_index in specs:
|
||||
block_cls = getattr(importlib.import_module(module_name), cls_name)
|
||||
try:
|
||||
|
|
@ -280,7 +369,8 @@ def apply_step_cache(
|
|||
# No silent FBCache fallback: the family was routed to magcache exactly
|
||||
# because FBCache derails it, so an uncalibrated checkpoint runs uncached.
|
||||
_warn(
|
||||
logger, mode,
|
||||
logger,
|
||||
mode,
|
||||
RuntimeError(f"no calibrated mag_ratios for family '{family}'"),
|
||||
)
|
||||
return None
|
||||
|
|
@ -370,7 +460,12 @@ def effective_request_strength(
|
|||
return pipe_default_strength if isinstance(pipe_default_strength, (int, float)) else None
|
||||
|
||||
|
||||
def _disengage_step_cache(transformer: Any, *, reason: str, logger: Any = None) -> bool:
|
||||
def _disengage_step_cache(
|
||||
transformer: Any,
|
||||
*,
|
||||
reason: str,
|
||||
logger: Any = None,
|
||||
) -> bool:
|
||||
"""disable_cache + clear the marker; True when the transformer is now uncached."""
|
||||
disable_cache = getattr(transformer, "disable_cache", None)
|
||||
if not callable(disable_cache):
|
||||
|
|
|
|||
|
|
@ -400,9 +400,7 @@ def _stub_hunyuan15_registry(monkeypatch):
|
|||
helpers.TransformerBlockRegistry = _Registry
|
||||
monkeypatch.setitem(sys.modules, "diffusers.hooks._helpers", helpers)
|
||||
|
||||
blocks = types.ModuleType(
|
||||
"diffusers.models.transformers.transformer_hunyuan_video15"
|
||||
)
|
||||
blocks = types.ModuleType("diffusers.models.transformers.transformer_hunyuan_video15")
|
||||
blocks.HunyuanVideo15TransformerBlock = HunyuanVideo15TransformerBlock
|
||||
monkeypatch.setitem(
|
||||
sys.modules,
|
||||
|
|
@ -493,14 +491,7 @@ from core.inference.diffusion_cache import ( # noqa: E402
|
|||
|
||||
|
||||
class _MagConfig:
|
||||
def __init__(
|
||||
self,
|
||||
threshold,
|
||||
max_skip_steps,
|
||||
retention_ratio,
|
||||
num_inference_steps,
|
||||
mag_ratios,
|
||||
):
|
||||
def __init__(self, threshold, max_skip_steps, retention_ratio, num_inference_steps, mag_ratios):
|
||||
self.threshold = threshold
|
||||
self.max_skip_steps = max_skip_steps
|
||||
self.retention_ratio = retention_ratio
|
||||
|
|
@ -534,7 +525,6 @@ def test_magcache_families_have_calibrated_ratios():
|
|||
# Every family the auto policy routes to magcache must ship a calibrated curve, or
|
||||
# the auto default silently runs uncached (apply_step_cache checks the table).
|
||||
from core.inference.diffusion_cache import _FAMILY_AUTO_CACHE_MODE
|
||||
|
||||
for fam, mode in _FAMILY_AUTO_CACHE_MODE.items():
|
||||
if mode == TC_MAGCACHE:
|
||||
ratios = _MAGCACHE_FAMILY_RATIOS[fam]
|
||||
|
|
@ -545,9 +535,7 @@ def test_magcache_families_have_calibrated_ratios():
|
|||
def test_magcache_engages_with_family_curve(monkeypatch):
|
||||
_stub_diffusers_with_magcache(monkeypatch)
|
||||
t = _MixinTransformer()
|
||||
engaged = apply_step_cache(
|
||||
_pipe(t), mode = "magcache", family = "hunyuanvideo-1.5-720p", steps = 50
|
||||
)
|
||||
engaged = apply_step_cache(_pipe(t), mode = "magcache", family = "hunyuanvideo-1.5-720p", steps = 50)
|
||||
assert engaged == TC_MAGCACHE
|
||||
cfg = t.enabled_with
|
||||
assert cfg.threshold == DEFAULT_MAGCACHE_THRESHOLD
|
||||
|
|
@ -571,9 +559,7 @@ def test_magcache_without_calibration_runs_uncached(monkeypatch):
|
|||
def test_magcache_without_steps_runs_uncached(monkeypatch):
|
||||
_stub_diffusers_with_magcache(monkeypatch)
|
||||
t = _MixinTransformer()
|
||||
assert (
|
||||
apply_step_cache(_pipe(t), mode = "magcache", family = "hunyuanvideo-1.5-720p") is None
|
||||
)
|
||||
assert apply_step_cache(_pipe(t), mode = "magcache", family = "hunyuanvideo-1.5-720p") is None
|
||||
assert t.enabled_with is None
|
||||
|
||||
|
||||
|
|
@ -581,7 +567,10 @@ def test_magcache_explicit_threshold_wins(monkeypatch):
|
|||
_stub_diffusers_with_magcache(monkeypatch)
|
||||
t = _MixinTransformer()
|
||||
apply_step_cache(
|
||||
_pipe(t), mode = "magcache", family = "hunyuanvideo-1.5-720p", steps = 30,
|
||||
_pipe(t),
|
||||
mode = "magcache",
|
||||
family = "hunyuanvideo-1.5-720p",
|
||||
steps = 30,
|
||||
threshold = 0.24,
|
||||
)
|
||||
assert t.enabled_with.threshold == 0.24
|
||||
|
|
@ -602,12 +591,8 @@ def test_toggle_magcache_reengages_on_step_change(monkeypatch):
|
|||
# step-count change must disable + re-enable; the same count stays idempotent.
|
||||
_stub_diffusers_with_magcache(monkeypatch)
|
||||
t = _ToggleTransformer()
|
||||
maybe_toggle_step_cache(
|
||||
_pipe(t), steps = 30, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p"
|
||||
)
|
||||
maybe_toggle_step_cache(
|
||||
_pipe(t), steps = 30, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p"
|
||||
)
|
||||
maybe_toggle_step_cache(_pipe(t), steps = 30, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p")
|
||||
maybe_toggle_step_cache(_pipe(t), steps = 30, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p")
|
||||
assert t.enables == 1 and t.disables == 0 # idempotent at the same count
|
||||
mode = maybe_toggle_step_cache(
|
||||
_pipe(t), steps = 50, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p"
|
||||
|
|
@ -619,9 +604,7 @@ def test_toggle_magcache_reengages_on_step_change(monkeypatch):
|
|||
def test_toggle_magcache_disengages_below_bar(monkeypatch):
|
||||
_stub_diffusers_with_magcache(monkeypatch)
|
||||
t = _ToggleTransformer()
|
||||
maybe_toggle_step_cache(
|
||||
_pipe(t), steps = 30, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p"
|
||||
)
|
||||
maybe_toggle_step_cache(_pipe(t), steps = 30, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p")
|
||||
mode = maybe_toggle_step_cache(
|
||||
_pipe(t), steps = 8, mode = TC_MAGCACHE, family = "hunyuanvideo-1.5-720p"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue