[Bugfix] Fix cache-dit for single-transformer Wan2.2 models(eg. Wan2.2-TI2V-5B) (#1392)

Signed-off-by: Lancer <maruixiang6688@gmail.com>
Co-authored-by: Hongsheng Liu <liuhongsheng4@huawei.com>
This commit is contained in:
LancerandHongsheng Liu authored and GitHub committed 2026-03-22 17:57:28 +08:00
1 parent af9368d109
commit d8b35035ec
2 files changed
+44 -7

No files matched your search

+40 -3
View File
@@ -65,10 +65,10 @@ def _build_db_cache_config(cache_config: Any) -> DBCacheConfig:
def enable_cache_for_wan22(pipeline: Any, cache_config: Any) -> Callable[[int], None]:
"""Enable cache-dit for Wan2.2 dual-transformer architecture.
"""Enable cache-dit for Wan2.2 single or dual-transformer architecture.
Wan2.2 uses two transformers (transformer and transformer_2) that need
to be enabled together using BlockAdapter.
Wan2.2 can use single or dual transformers (transformer and transformer_2) that need
to be enabled using BlockAdapter.
Args:
pipeline: The Wan2.2 pipeline instance.
@@ -78,6 +78,43 @@ def enable_cache_for_wan22(pipeline: Any, cache_config: Any) -> Callable[[int],
A refresh function that can be called to update cache context with new num_inference_steps.
"""
if getattr(pipeline, "transformer_2", None) is None:
logger.info("transformer_2 not found, enabling cache-dit for single transformer mode")
db_cache_config = _build_db_cache_config(cache_config)
cache_dit.enable_cache(
BlockAdapter(
transformer=pipeline.transformer,
blocks=[pipeline.transformer.blocks],
forward_pattern=[ForwardPattern.Pattern_2],
params_modifiers=[
ParamsModifier(cache_config=db_cache_config),
],
has_separate_cfg=True,
),
cache_config=db_cache_config,
)
def refresh_cache_context(pipeline: Any, num_inference_steps: int, verbose: bool = True) -> None:
"""Refresh cache context for single transformer."""
if cache_config.scm_steps_mask_policy is None:
cache_dit.refresh_context(
pipeline.transformer, num_inference_steps=num_inference_steps, verbose=verbose
)
else:
cache_dit.refresh_context(
pipeline.transformer,
cache_config=DBCacheConfig().reset(
num_inference_steps=num_inference_steps,
steps_computation_mask=cache_dit.steps_mask(
mask_policy=cache_config.scm_steps_mask_policy, total_steps=num_inference_steps
),
steps_computation_policy=cache_config.scm_steps_policy,
),
verbose=verbose,
)
return refresh_cache_context
cache_dit.enable_cache(
BlockAdapter(
transformer=[