wan_vae ¶
Wan VAE decode helpers for Apple Silicon MLX inference.
Two decode backends:
-
TAEHV (primary / fast) — Tiny AutoEncoder (madebyollin/taehv). Fully MLX-native Conv2d path.
taew2_1.pthfor Wan2.1 (z_dim=16),taew2_2.pthfor Wan2.2 5B (z_dim=48, patch_size=2). Expected decode wall-clock ~seconds vs ~minutes for the full 3D VAE on MPS. -
Full AutoencoderKLWan (reference / quality) — denormalize with
latents_mean/latents_stdthen torch decode (MPS preferred). Used for parity gates and when TAEHV is unavailable. A pure-MLX 3D-conv port of the residual Wan2.2 decoder is left as follow-up (causal feat-cache + residual up blocks are large); TAEHV covers the product latency path.
Diffusion latents from the DiT are not mean/std-normalized for TAEHV (matching taehv_decode.py); full VAE decode does denormalize first (matching mlx_wan_prompt_to_video.decode_latents_to_video).
Classes¶
fastvideo.mlx_runtime.wan_vae.MLXTAEHVDecoder ¶
Minimal MLX port of TAEHV decoder (parallel-over-time MemBlocks).
Initialize the TAEHV decoder from a checkpoint for the specified latent dimensionality.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
checkpoint_path | Path | Path to the TAEHV checkpoint. | required |
z_dim | int | Number of latent channels, determining the decoder patch size. | required |
Source code in fastvideo/mlx_runtime/wan_vae.py
Methods:¶
fastvideo.mlx_runtime.wan_vae.MLXTAEHVDecoder.decode_ntchw ¶
Decode latent video batches into clipped RGB frames.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents_ntchw | Any | Latents with shape | required |
Returns:
| Name | Type | Description |
|---|---|---|
Any | Any | Decoded frames with shape |
Source code in fastvideo/mlx_runtime/wan_vae.py
fastvideo.mlx_runtime.wan_vae.WanVAEConfigView dataclass ¶
WanVAEConfigView(z_dim: int, latents_mean: tuple[float, ...], latents_std: tuple[float, ...], scale_factor_spatial: int = 8, scale_factor_temporal: int = 4, patch_size: int | None = None, vae_dir: Path | None = None)
Minimal config fields needed for denormalize + spatial scale.
Methods:¶
fastvideo.mlx_runtime.wan_vae.WanVAEConfigView.from_vae_dir classmethod ¶
from_vae_dir(vae_dir: Path) -> WanVAEConfigView
Load Wan VAE configuration values from a directory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vae_dir | Path | Directory containing the VAE | required |
Returns:
| Name | Type | Description |
|---|---|---|
WanVAEConfigView | WanVAEConfigView | Configuration loaded from the VAE directory. |
Source code in fastvideo/mlx_runtime/wan_vae.py
Functions:¶
fastvideo.mlx_runtime.wan_vae.decode_latents_taehv_mlx ¶
decode_latents_taehv_mlx(latents_np: ndarray, *, z_dim: int | None = None, checkpoint_path: Path | None = None) -> ndarray
Decode latent representations with the MLX TAEHV decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents_np | ndarray | Latents arranged as [B, C, T, H, W]. | required |
z_dim | int | None | Latent channel dimension used to select the decoder checkpoint. | None |
checkpoint_path | Path | None | Optional path to a TAEHV checkpoint. | None |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Decoded pixels arranged as [B, T, H, W, 3] with values in [0, 1]. |
Raises:
| Type | Description |
|---|---|
ValueError | If |
Source code in fastvideo/mlx_runtime/wan_vae.py
fastvideo.mlx_runtime.wan_vae.decode_latents_to_video ¶
decode_latents_to_video(latents_np: ndarray, output_path: Path, *, fps: int = 16, backend: DecodeBackend = 'taehv', vae_dir: Path | None = None, z_dim: int | None = None, taehv_checkpoint: Path | None = None, torch_device: str = 'auto') -> dict[str, Any]
Decode latent video frames and export them as an MP4 file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents_np | ndarray | Latent video representation to decode. | required |
output_path | Path | Destination path for the MP4 file. | required |
fps | int | Output video frame rate. | 16 |
backend | DecodeBackend | Decoder backend to use. | 'taehv' |
vae_dir | Path | None | Directory containing the full Wan VAE when using the | None |
z_dim | int | None | Latent channel count for TAEHV decoding. | None |
taehv_checkpoint | Path | None | Optional TAEHV checkpoint path. | None |
torch_device | str | PyTorch device selection for PyTorch-based decoding. | 'auto' |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: Decode time in seconds, backend name, output path, frame |
dict[str, Any] | count, and video resolution. |
Raises:
| Type | Description |
|---|---|
ValueError | If the full VAE backend lacks |
Source code in fastvideo/mlx_runtime/wan_vae.py
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
fastvideo.mlx_runtime.wan_vae.decode_latents_wan_vae_torch ¶
decode_latents_wan_vae_torch(latents_np: ndarray, *, vae_dir: Path, device: str = 'auto', dtype_name: str = 'fp16') -> ndarray
Full AutoencoderKLWan decode on torch (MPS/CPU) with mean/std denormalize.
Returns pixels [B, T, H, W, 3] float in [0, 1].
Source code in fastvideo/mlx_runtime/wan_vae.py
fastvideo.mlx_runtime.wan_vae.denormalize_latents_np ¶
denormalize_latents_np(latents: ndarray, config: WanVAEConfigView) -> ndarray
Denormalize Wan VAE latent values using the configured means and standard deviations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
latents | ndarray | Latent values in normalized form. | required |
config | WanVAEConfigView | Wan VAE latent statistics. | required |
Returns:
| Type | Description |
|---|---|
ndarray | np.ndarray: Denormalized latent values as float32. |
Source code in fastvideo/mlx_runtime/wan_vae.py
fastvideo.mlx_runtime.wan_vae.ensure_taehv_checkpoint ¶
Return a validated TAEHV checkpoint for the specified latent channel count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
z_dim | int | Number of latent channels, supported values are 16 and 48. | required |
checkpoint_path | Path | None | Optional existing checkpoint path to validate and use. | None |
Returns:
| Name | Type | Description |
|---|---|---|
Path | Path | Path to the validated TAEHV checkpoint. |
Raises:
| Type | Description |
|---|---|
FileNotFoundError | If the supplied checkpoint path does not exist. |
ValueError | If no checkpoint is mapped to the specified latent channel count. |