diffusers/tools
1128
1#!/usr/bin/env python32import torch3from diffusers import DiffusionPipeline, DPMSolverMultistepScheduler4from diffusers.utils import export_to_video5from PIL import Image6 7# Make sure CUDA has < 13GB VRAM8# torch.cuda.set_per_process_memory_fraction(0.5)9 10pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_576w", torch_dtype=torch.float16)11pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)12# pipe.enable_model_cpu_offload()13pipe.to("cuda")14pipe.enable_vae_slicing()15 16pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)17 18prompt = "Darth Vader is surfing on waves"19video_frames = pipe(prompt, num_inference_steps=40, height=320, width=576, num_frames=36).frames20video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/video_576_darth_vader_36.mp4")21 22pipe = DiffusionPipeline.from_pretrained("cerspense/zeroscope_v2_XL", torch_dtype=torch.float16)23pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)24pipe.enable_model_cpu_offload()25pipe.enable_vae_slicing()26 27video = [Image.fromarray(frame).resize((1024, 576)) for frame in video_frames]28 29video_frames = pipe(prompt, video=video, strength=0.6).frames30video_path = export_to_video(video_frames, output_video_path="/home/patrick/videos/video_1024_darth_vader_36.mp4")31 