Kandinsky6 (#8537)
Signed-off-by: leffff <levnovitskiy@gmail.com> Signed-off-by: Artem Borisov <divotionchannel@gmail.com> Co-authored-by: leffff <levnovitskiy@gmail.com> Co-authored-by: Artem Borisov <divotionchannel@gmail.com>
This commit is contained in:
38 files changed
+8574
-8
No files matched your search
@@ -908,6 +908,35 @@ def enable_cache_for_mammothmoda2(pipeline: Any, cache_config: Any) -> CacheDiTE
|
||||
return CacheDiTEnableResult(refresh=refresh, targets=(block_adapter,))
|
||||
|
||||
|
||||
def enable_cache_for_kandinsky6(pipeline: Any, cache_config: Any) -> RefreshCacheContextFunc:
|
||||
"""Cache-DiT over K6 visual blocks only.
|
||||
|
||||
Text and audio block lists are not one residual chain with the visual
|
||||
stack. If the block adapter rejects the fused ``(video, audio)`` return,
|
||||
fall back to the same step-level velocity cache MagCache uses.
|
||||
"""
|
||||
transformer = pipeline.transformer
|
||||
block_adapter = BlockAdapter(
|
||||
transformer=transformer,
|
||||
blocks=[transformer.visual_transformer_blocks],
|
||||
forward_pattern=[ForwardPattern.Pattern_0],
|
||||
has_separate_cfg=True,
|
||||
check_forward_pattern=False,
|
||||
)
|
||||
try:
|
||||
return enable_cache_for_dit(pipeline, cache_config, block_adapter)
|
||||
except Exception as exc:
|
||||
logger.warning("Cache-DiT block adapter failed for Kandinsky 6 (%s); using step cache", exc)
|
||||
from vllm_omni.diffusion.models.kandinsky6.cache_accel import attach_mag_cache
|
||||
|
||||
attach_mag_cache(transformer, threshold=0.24, max_skip_steps=3, retention_ratio=0.1)
|
||||
|
||||
def _refresh(*_args, **_kwargs):
|
||||
return None
|
||||
|
||||
return _refresh
|
||||
|
||||
|
||||
def register_custom_dit_enablers() -> None:
|
||||
"""Register model-specific Cache-DiT enablers.
|
||||
|
||||
@@ -925,6 +954,7 @@ def register_custom_dit_enablers() -> None:
|
||||
"Cosmos3OmniDiffusersPipeline": enable_cache_for_cosmos3,
|
||||
"Cosmos3OmniPipeline": enable_cache_for_cosmos3,
|
||||
"Krea2Pipeline": enable_cache_for_krea2,
|
||||
"Kandinsky6TI2VAPipeline": enable_cache_for_kandinsky6,
|
||||
"Magi2Pipeline": enable_cache_for_magi2,
|
||||
"MammothModa2DiTPipeline": enable_cache_for_mammothmoda2,
|
||||
}
|
||||
|
||||
+14
-1
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""
|
||||
MagCache backend implementation.
|
||||
@@ -73,6 +73,19 @@ class MagCacheBackend(CacheBackend):
|
||||
transformer = pipeline.transformer
|
||||
transformer_type = transformer.__class__.__name__
|
||||
|
||||
if transformer_type == "Kandinsky6Transformer3DModel":
|
||||
from vllm_omni.diffusion.models.kandinsky6.cache_accel import attach_mag_cache
|
||||
|
||||
attach_mag_cache(
|
||||
transformer,
|
||||
threshold=self.config.mag_threshold,
|
||||
max_skip_steps=self.config.mag_max_skip_steps,
|
||||
retention_ratio=self.config.mag_retention_ratio,
|
||||
)
|
||||
self._registered = True
|
||||
logger.info("MagCache: Kandinsky 6 step-cache attached (visual/audio velocity reuse)")
|
||||
return
|
||||
|
||||
num_inference_steps = self.config.num_inference_steps or 28
|
||||
|
||||
mag_ratios = self.config.mag_ratios
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""
|
||||
Hook-based MagCache implementation for vLLM-Omni.
|
||||
@@ -543,9 +543,12 @@ def apply_mag_cache_hook(
|
||||
state_manager = StateManager(MagCacheState, (), {})
|
||||
remaining_blocks = []
|
||||
|
||||
allowed = getattr(module, "_magcache_block_attrs", None)
|
||||
for name, submodule in module.named_children():
|
||||
if not isinstance(submodule, torch.nn.ModuleList):
|
||||
continue
|
||||
if allowed is not None and name not in allowed:
|
||||
continue
|
||||
for index, block in enumerate(submodule):
|
||||
remaining_blocks.append((f"{name}.{index}", block))
|
||||
|
||||
|
||||
+20
-1
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
"""
|
||||
TeaCache backend implementation.
|
||||
@@ -143,11 +143,30 @@ def enable_flux2_klein_teacache(pipeline: Any, config: DiffusionCacheConfig) ->
|
||||
)
|
||||
|
||||
|
||||
def enable_kandinsky6_teacache(pipeline: Any, config: DiffusionCacheConfig) -> None:
|
||||
"""TeaCache for Kandinsky 6 via the denoise-loop step cache.
|
||||
|
||||
Coefficients are uncalibrated (see ``K6_TEACACHE_COEFFICIENTS``).
|
||||
"""
|
||||
from vllm_omni.diffusion.models.kandinsky6.cache_accel import attach_tea_cache
|
||||
|
||||
attach_tea_cache(
|
||||
pipeline.transformer,
|
||||
rel_l1_thresh=config.rel_l1_thresh if config.rel_l1_thresh is not None else 0.2,
|
||||
coefficients=tuple(config.coefficients) if config.coefficients is not None else None,
|
||||
)
|
||||
logger.info(
|
||||
"TeaCache: Kandinsky 6 step-cache attached (uncalibrated coefficients, thresh=%s)",
|
||||
config.rel_l1_thresh,
|
||||
)
|
||||
|
||||
|
||||
CUSTOM_TEACACHE_ENABLERS = {
|
||||
"BagelPipeline": enable_bagel_teacache,
|
||||
"Flux2KleinPipeline": enable_flux2_klein_teacache,
|
||||
"HunyuanImage3Pipeline": enable_hunyuan_image3_teacache,
|
||||
"MammothModa2DiTPipeline": enable_mammoth_moda2_teacache,
|
||||
"Kandinsky6TI2VAPipeline": enable_kandinsky6_teacache,
|
||||
"MiniMaxH3Pipeline": enable_minimax_h3_teacache,
|
||||
"SenseNovaU1Pipeline": enable_sensenova_u1_teacache,
|
||||
}
|
||||
|
||||
+10
-1
@@ -1,5 +1,5 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM-Omni project
|
||||
|
||||
from dataclasses import dataclass
|
||||
|
||||
@@ -8,6 +8,15 @@ from dataclasses import dataclass
|
||||
# Source: TeaCache paper and ComfyUI-TeaCache empirical tuning
|
||||
_MODEL_COEFFICIENTS = {
|
||||
# FLUX transformer coefficients from TeaCache paper
|
||||
# Uncalibrated stand-in so Kandinsky 6 TeaCache can be enabled.
|
||||
# Copied from Qwen-Image; refit before treating skips as quality-neutral.
|
||||
"Kandinsky6Transformer3DModel": [
|
||||
-4.50000000e02,
|
||||
2.80000000e02,
|
||||
-4.50000000e01,
|
||||
3.20000000e00,
|
||||
-2.00000000e-02,
|
||||
],
|
||||
"FluxTransformer2DModel": [
|
||||
4.98651651e02,
|
||||
-2.83781631e02,
|
||||
|
||||
Reference in new issue
Block a user