Views
No views yet
E:\huggingface\wan21-vae\
└── vae/
└── wan/
└── wan21-vae.safetensors (243 MB)| File | Size | Format | Description |
|---|---|---|---|
wan21-vae.safetensors | 243 MB | SafeTensors | WAN2.1 VAE weights |
1import torch
2from diffusers import AutoencoderKL
3
4# Load the WAN2.1 VAE
5vae = AutoencoderKL.from_pretrained(
6 "E:/huggingface/wan21-vae/vae/wan",
7 torch_dtype=torch.float16
8).to("cuda")
9
10print(f"VAE loaded: {vae.config}")1import torch
2from diffusers import AutoencoderKL
3from PIL import Image
4import numpy as np
5
6# Load VAE
7vae = AutoencoderKL.from_pretrained(
8 "E:/huggingface/wan21-vae/vae/wan",
9 torch_dtype=torch.float16
10).to("cuda")
11
12# Prepare video frames (example with dummy data)
13# Shape: [batch, channels, frames, height, width]
14video_frames = torch.randn(1, 3, 16, 480, 720).half().to("cuda")
15
16# Encode video to latent space
17with torch.no_grad():
18 latents = vae.encode(video_frames).latent_dist.sample()
19
20print(f"Latent shape: {latents.shape}")
21print(f"Compression ratio: {np.prod(video_frames.shape) / np.prod(latents.shape):.2f}x")1import torch
2from diffusers import AutoencoderKL
3
4# Load VAE
5vae = AutoencoderKL.from_pretrained(
6 "E:/huggingface/wan21-vae/vae/wan",
7 torch_dtype=torch.float16
8).to("cuda")
9
10# Decode latents back to video frames
11# Assuming you have latents from encoding step
12with torch.no_grad():
13 reconstructed_video = vae.decode(latents).sample
14
15print(f"Reconstructed video shape: {reconstructed_video.shape}")1import torch
2from diffusers import DiffusionPipeline, AutoencoderKL
3
4# Load custom VAE
5vae = AutoencoderKL.from_pretrained(
6 "E:/huggingface/wan21-vae/vae/wan",
7 torch_dtype=torch.float16
8)
9
10# Load WAN model with custom VAE
11pipe = DiffusionPipeline.from_pretrained(
12 "Wan-AI/Wan2.1-T2V-1.3B",
13 vae=vae,
14 torch_dtype=torch.float16
15).to("cuda")
16
17# Generate video
18prompt = "A serene beach at sunset with waves crashing"
19video = pipe(prompt, num_frames=16, height=480, width=720).frames
20
21print(f"Generated video: {len(video)} frames")1# Use gradient checkpointing for lower memory usage
2vae.enable_gradient_checkpointing()
3
4# Use CPU offloading for very large videos
5vae.enable_sequential_cpu_offload()
6
7# Use attention slicing for reduced VRAM
8vae.enable_attention_slicing(1)1# Compile model for faster inference (PyTorch 2.0+)
2vae = torch.compile(vae, mode="reduce-overhead")
3
4# Use xFormers for efficient attention
5vae.enable_xformers_memory_efficient_attention()
6
7# Use half precision for faster inference
8vae = vae.half()1# Process multiple video clips efficiently
2batch_size = 4
3video_clips = torch.randn(batch_size, 3, 16, 480, 720).half().to("cuda")
4
5with torch.no_grad():
6 latents = vae.encode(video_clips).latent_dist.sample()1@misc{wan2025,
2 title={WAN: Open and Advanced Large-Scale Video Generative Models},
3 author={WAN-AI Team},
4 year={2025},
5 publisher={Hugging Face},
6 howpublished={https://huggingface.co/Wan-AI}
7}