CogVideoX Video Generation
Generate 6-second videos from text or images with Zhipu AI's CogVideoX diffusion transformer on Clore.ai GPUs.
Last updated
Was this helpful?
Was this helpful?
# Create environment
pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124
pip install diffusers transformers accelerate sentencepiece imageio[ffmpeg]
# Verify GPU
python -c "import torch; print(torch.cuda.get_device_name(0))"import torch
from diffusers import CogVideoXPipeline
from diffusers.utils import export_to_video
pipe = CogVideoXPipeline.from_pretrained(
"THUDM/CogVideoX-5b",
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
pipe.enable_model_cpu_offload() # saves ~4 GB peak VRAM
pipe.vae.enable_tiling() # required for 720x480 on 24 GB cards
prompt = (
"A golden retriever running through a sunflower field at sunset, "
"cinematic lighting, slow motion, 4K quality"
)
video_frames = pipe(
prompt=prompt,
num_frames=49,
guidance_scale=6.0,
num_inference_steps=50,
generator=torch.Generator("cuda").manual_seed(42),
).frames[0]
export_to_video(video_frames, "retriever_sunset.mp4", fps=8)
print("Saved retriever_sunset.mp4")import torch
from PIL import Image
from diffusers import CogVideoXImageToVideoPipeline
from diffusers.utils import export_to_video
pipe = CogVideoXImageToVideoPipeline.from_pretrained(
"THUDM/CogVideoX-5b-I2V",
torch_dtype=torch.bfloat16,
)
pipe.to("cuda")
pipe.enable_model_cpu_offload()
pipe.vae.enable_tiling()
image = Image.open("reference.png").resize((720, 480))
video_frames = pipe(
prompt="The camera slowly orbits around the subject, gentle wind",
image=image,
num_frames=49,
guidance_scale=6.0,
num_inference_steps=50,
).frames[0]
export_to_video(video_frames, "animated.mp4", fps=8)from diffusers import CogVideoXPipeline
import torch
pipe = CogVideoXPipeline.from_pretrained(
"THUDM/CogVideoX-2b",
torch_dtype=torch.float16,
)
pipe.to("cuda")
pipe.vae.enable_tiling()
frames = pipe(
prompt="Timelapse of a blooming cherry blossom tree",
num_frames=49,
guidance_scale=6.0,
num_inference_steps=30, # fewer steps → faster
).frames[0]