[diffusion] cache-dit: respect CFG parallel for dual-transformer models (#43704)
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
2428d0f531
commit
2c1e85964e
@@ -680,6 +680,7 @@ def enable_cache_on_dual_transformer(
|
||||
model_name: str = "wan2.2",
|
||||
sp_group: Optional[torch.distributed.ProcessGroup] = None,
|
||||
tp_group: Optional[torch.distributed.ProcessGroup] = None,
|
||||
has_separate_cfg: bool = True,
|
||||
) -> tuple[torch.nn.Module, torch.nn.Module]:
|
||||
"""Enable cache-dit on dual transformers using BlockAdapter.
|
||||
|
||||
@@ -861,7 +862,7 @@ def enable_cache_on_dual_transformer(
|
||||
params_modifiers=[primary_modifier, secondary_modifier],
|
||||
check_forward_pattern=adapter_spec.check_forward_pattern,
|
||||
check_num_outputs=adapter_spec.check_num_outputs,
|
||||
has_separate_cfg=adapter_spec.has_separate_cfg,
|
||||
has_separate_cfg=adapter_spec.has_separate_cfg and has_separate_cfg,
|
||||
),
|
||||
parallelism_config=None,
|
||||
)
|
||||
|
||||
@@ -1191,6 +1191,7 @@ class DenoisingStage(PipelineStage, RolloutDenoisingMixin):
|
||||
model_name=self._cache_dit_dual_model_name(),
|
||||
sp_group=sp_group,
|
||||
tp_group=tp_group,
|
||||
has_separate_cfg=has_separate_cfg,
|
||||
)
|
||||
logger.info(
|
||||
"cache-dit enabled on dual transformers (steps=%d, %d)",
|
||||
|
||||
@@ -545,6 +545,30 @@ class TestCalibratorSelection(unittest.TestCase):
|
||||
)
|
||||
self.assertEqual(module.cache_dit.enable_calls, [])
|
||||
|
||||
def test_dual_transformer_has_separate_cfg_follows_runtime(self):
|
||||
"""Under CFG parallel each rank makes one Wan2.2 call per step;
|
||||
cache-dit must not pair consecutive calls as cond/uncond."""
|
||||
for runtime_flag in (True, False):
|
||||
with self.subTest(has_separate_cfg=runtime_flag):
|
||||
module = _import_module_with_stub()
|
||||
module.ParamsModifier = types.SimpleNamespace
|
||||
transformer = _make_transformer("AnyModel")
|
||||
transformer.blocks = ["block_0"]
|
||||
transformer_2 = _make_transformer("AnyModel")
|
||||
transformer_2.blocks = ["block_0"]
|
||||
|
||||
module.enable_cache_on_dual_transformer(
|
||||
transformer,
|
||||
transformer_2,
|
||||
self._config(module),
|
||||
self._config(module),
|
||||
model_name="wan2.2",
|
||||
has_separate_cfg=runtime_flag,
|
||||
)
|
||||
|
||||
adapter = module.cache_dit.enable_calls[0]["target"]
|
||||
self.assertEqual(adapter.has_separate_cfg, runtime_flag)
|
||||
|
||||
|
||||
class TestCacheDitLegacyFallback(unittest.TestCase):
|
||||
"""cache-dit < 1.5.0 (CI base jobs ship 1.3.0): fallback import + DMD guard."""
|
||||
|
||||
Reference in New Issue
Block a user