[optimization] Added Wan 2.2 VAE decode optimizations (#7056)

Signed-off-by: Maciej Bala <mbala@nvidia.com>
Signed-off-by: MaciejBalaNV <mbala@nvidia.com>
This commit is contained in:
MaciejBalaNV authored and GitHub committed 2026-09-22 11:37:49 -07:00
1 parent 7b6a5ee894
commit c482626450
28 files changed
+4740

No files matched your search

+47
View File
@@ -487,11 +487,58 @@ def initialize_model(
# at model loading time, not inside individual model files
_apply_sequence_parallel_if_enabled(model, od_config)
# Install the Wan VAE decoder fast path once the VAE parallel mode is
# known. This runs inside the weight-loading memory pool, so any weight
# re-layout it performs stays offloadable by sleep mode.
_apply_wan_vae_fastpath_if_enabled(model, od_config)
return model
else:
raise ValueError(f"Model class {od_config.model_class_name} not found in diffusion model registry.")
def _apply_wan_vae_fastpath_if_enabled(model, od_config: OmniDiffusionConfig) -> None:
"""Install the Wan VAE decoder fast path on every diffusers Wan VAE of the pipeline.
Controlled by ``od_config.vae_fast_path`` (``off`` / ``lossless`` /
``channels_last``). Only CUDA is supported; other platforms keep the
reference diffusers decoder. Failures never abort model loading.
"""
level = getattr(od_config, "vae_fast_path", "lossless")
if level == "off":
return
if not current_omni_platform.is_cuda():
logger.debug("Wan VAE fast path is only supported on CUDA; skipping")
return
from diffusers.models.autoencoders import AutoencoderKLWan
from vllm_omni.diffusion.distributed.autoencoders.wan_vae_fastpath import install_wan_vae_fastpath
from vllm_omni.diffusion.offloader.module_collector import ModuleDiscovery
candidates: list[tuple[str, nn.Module]] = []
try:
discovered = ModuleDiscovery.discover(model)
candidates = list(zip(discovered.vae_names, discovered.vaes, strict=True))
except Exception:
logger.debug("Wan VAE fast path: component discovery failed; falling back to `vae`", exc_info=True)
if not candidates and isinstance(getattr(model, "vae", None), nn.Module):
candidates = [("vae", model.vae)]
for name, vae in candidates:
if not isinstance(vae, AutoencoderKLWan):
continue
try:
report = install_wan_vae_fastpath(vae, level=level)
except Exception:
logger.warning(
"Failed to install the Wan VAE fast path on %s; using the reference decoder", name, exc_info=True
)
continue
if report.installed:
logger.info("Wan VAE fast path (%s) active on %s", level, name)
def _apply_sequence_parallel_if_enabled(model, od_config: OmniDiffusionConfig) -> None:
"""Apply sequence parallelism hooks if SP is enabled.