Views
No views yet
| Model Name | CogVideoX1.5-5B | CogVideoX1.5-5B-I2V (Current Repository) |
|---|---|---|
| Video Resolution | 1360 * 768 | Min(W, H) = 768 768 ≤ Max(W, H) ≤ 1360 Max(W, H) % 16 = 0 |
| Inference Precision | BF16 (recommended), FP16, FP32, FP8*, INT8, not supported INT4 | |
| Single GPU Inference Memory Consumption | BF16: 9GB minimum* | |
| Multi-GPU Inference Memory Consumption | BF16: 24GB* using diffusers | |
| Inference Speed (Step = 50, FP/BF16) | Single A100: ~1000 seconds (5-second video) Single H100: ~550 seconds (5-second video) | |
| Prompt Language | English* | |
| Max Prompt Length | 224 Tokens | |
| Video Length | 5 or 10 seconds | |
| Frame Rate | 16 frames/second |
diffusers library enabled all optimizations included in the library. This scheme has not been
tested on non-NVIDIA A100/H100 devices. It should generally work with all NVIDIA Ampere architecture or higher
devices. Disabling optimizations can triple VRAM usage but increase speed by 3-4 times. You can selectively disable
certain optimizations, including:pipe.enable_sequential_cpu_offload()
pipe.vae.enable_slicing()
pipe.vae.enable_tiling()enable_sequential_cpu_offload() optimization needs to be disabled.torch.compile,
significantly improving inference speed. FP8 precision is required for NVIDIA H100 and above, which requires source
installation of torch, torchao, diffusers, and accelerate. Using CUDA 12.4 is recommended.diffusers versions of models support quantization.1# diffusers (from source)
2# transformers>=4.46.2
3# accelerate>=1.1.1
4# imageio-ffmpeg>=0.5.1
5pip install git+https://github.com/huggingface/diffusers
6pip install --upgrade transformers accelerate diffusers imageio-ffmpeg1import torch
2from diffusers import CogVideoXImageToVideoPipeline
3from diffusers.utils import export_to_video, load_image
4
5prompt = "A little girl is riding a bicycle at high speed. Focused, detailed, realistic."
6image = load_image(image="input.jpg")
7pipe = CogVideoXImageToVideoPipeline.from_pretrained(
8 "THUDM/CogVideoX1.5-5B-I2V",
9 torch_dtype=torch.bfloat16
10)
11
12pipe.enable_sequential_cpu_offload()
13pipe.vae.enable_tiling()
14pipe.vae.enable_slicing()
15
16video = pipe(
17 prompt=prompt,
18 image=image,
19 num_videos_per_prompt=1,
20 num_inference_steps=50,
21 num_frames=81,
22 guidance_scale=6,
23 generator=torch.Generator(device="cuda").manual_seed(42),
24).frames[0]
25
26export_to_video(video, "output.mp4", fps=8)torch.compile, which can significantly accelerate inference.1# To get started, PytorchAO needs to be installed from the GitHub source and PyTorch Nightly.
2# Source and nightly installation is only required until the next release.
3
4import torch
5from diffusers import AutoencoderKLCogVideoX, CogVideoXTransformer3DModel, CogVideoXImageToVideoPipeline
6from diffusers.utils import export_to_video, load_image
7from transformers import T5EncoderModel
8from torchao.quantization import quantize_, int8_weight_only
9
10quantization = int8_weight_only
11
12text_encoder = T5EncoderModel.from_pretrained("THUDM/CogVideoX1.5-5B-I2V", subfolder="text_encoder",
13 torch_dtype=torch.bfloat16)
14quantize_(text_encoder, quantization())
15
16transformer = CogVideoXTransformer3DModel.from_pretrained("THUDM/CogVideoX1.5-5B-I2V", subfolder="transformer",
17 torch_dtype=torch.bfloat16)
18quantize_(transformer, quantization())
19
20vae = AutoencoderKLCogVideoX.from_pretrained("THUDM/CogVideoX1.5-5B-I2V", subfolder="vae", torch_dtype=torch.bfloat16)
21quantize_(vae, quantization())
22
23# Create pipeline and run inference
24pipe = CogVideoXImageToVideoPipeline.from_pretrained(
25 "THUDM/CogVideoX1.5-5B-I2V",
26 text_encoder=text_encoder,
27 transformer=transformer,
28 vae=vae,
29 torch_dtype=torch.bfloat16,
30)
31
32pipe.enable_model_cpu_offload()
33pipe.vae.enable_tiling()
34pipe.vae.enable_slicing()
35
36prompt = "A little girl is riding a bicycle at high speed. Focused, detailed, realistic."
37image = load_image(image="input.jpg")
38video = pipe(
39 prompt=prompt,
40 image=image,
41 num_videos_per_prompt=1,
42 num_inference_steps=50,
43 num_frames=81,
44 guidance_scale=6,
45 generator=torch.Generator(device="cuda").manual_seed(42),
46).frames[0]
47
48export_to_video(video, "output.mp4", fps=8)@article{yang2024cogvideox,
title={CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer},
author={Yang, Zhuoyi and Teng, Jiayan and Zheng, Wendi and Ding, Ming and Huang, Shiyu and Xu, Jiazheng and Yang, Yuanming and Hong, Wenyi and Zhang, Xiaohan and Feng, Guanyu and others},
journal={arXiv preprint arXiv:2408.06072},
year={2024}
}