Repository navigation
Description
Describe the bug
VideoProcessor.postprocess_video denormalizes decoded video on the accelerator before returning NumPy or PIL frames on the CPU. With the public Wan2.1 1.3B checkpoint at 832 × 480 resolution and 81 frames, the default NumPy output requires an additional 740.4 MiB of CUDA memory during postprocessing, while the decoded video tensor itself already occupies 370.2 MiB.
Moving the decoded video to CPU before denormalization avoids these additional CUDA allocations.
Source code · Wan2.1 model card
I have implemented and validated a local fix and would like to submit a PR if the maintainers agree with this approach.
Reproduction
import torch
from diffusers import AutoencoderKLWan, WanPipeline
model_id = "Wan-AI/Wan2.1-T2V-1.3B-Diffusers"
revision = "0fad780a534b6463e45facd96134c9f345acfa5b"
vae = AutoencoderKLWan.from_pretrained(
model_id, subfolder="vae", revision=revision, dtype=torch.float32
)
pipe = WanPipeline.from_pretrained(
model_id, revision=revision, vae=vae, torch_dtype=torch.bfloat16
).to("cuda")
postprocess_video = pipe.video_processor.postprocess_video
def measure_postprocessing(video, output_type):
torch.cuda.synchronize()
start = torch.cuda.memory_allocated()
torch.cuda.reset_peak_memory_stats()
frames = postprocess_video(video, output_type=output_type)
extra = torch.cuda.max_memory_allocated() - start
print(f"Additional CUDA allocation in postprocessing: {extra / 2**20:.1f} MiB")
return frames
pipe.video_processor.postprocess_video = measure_postprocessing
frames = pipe(
prompt="A cat walking through grass",
height=480,
width=832,
num_frames=81,
num_inference_steps=20,
guidance_scale=5.0,
generator=torch.Generator("cpu").manual_seed(2490),
).frames
print(frames.shape, frames.dtype)Context
A Wan2.2 5B deployment on 24 GB GPUs reported a CUDA OOM during Diffusers' denormalization step after video generation. vLLM-Omni addressed this by moving the decoded video to CPU before calling postprocessing. This report addresses the shared postprocessing path used directly by Diffusers.
Related:
Logs
Additional CUDA allocation in postprocessing on upstream main: 740.4 MiB
Additional CUDA allocation in postprocessing with the patch: 0.0 MiB
Returned frames: (1, 81, 480, 832, 3) float32System Info
• Diffusers 0.44.0.dev0, upstream main 12d5c7a
• Python 3.11.15, PyTorch 2.7.1+cu126, Transformers 5.23.0, Accelerate 1.11.0
• Hugging Face Hub 1.33.0, Safetensors 0.8.0
• Linux x86-64, one NVIDIA A100-SXM4-80GB, NVIDIA driver 615.71.10
Activity
cloudgpuapp commentedon Dec 3, 2026
Great catch — this is a very common OOM trigger on 24 GB GPUs right after Wan2.1 720p VAE decode, because the VAE output tensor is still resident on CUDA while
denormalize()allocates another full-video intermediate buffer on the same device.For anyone hitting this on current
diffusersbefore a fix lands inVideoProcessor.postprocess_video, a clean workaround is to requestoutput_type="pt"from the pipeline and move the tensor to CPU before postprocessing:For the upstream fix itself, moving to CPU (or processing in small frame chunks on CPU) when
output_type in ("np", "pil")andvideo.device.type != "cpu"avoids the extra GPU peak without changingoutput_type="pt"behavior.