CogVideo

zai-orgApache-2.0长期未更新

开源文生视频和图生视频模型,CogVideoX 支持从文本或图片生成视频,适合搭建视频生成推理服务。

text and image to video generation: CogVideoX (2024) and CogVideo (ICLR 2023)

v1.0发布于 2024-11-08 05:32 UTC13,190star +4 / 7 天1,391fork同步于 2026-11-10 05:27 UTC

怎么上手

由 README 提炼,执行前请确认
pip install -r requirements.txt
硬件要求按 README 说明

README 称 CogVideoX-2B 可在 GTX 1080Ti 等较老 GPU 上运行,CogVideoX-5B 可在 RTX 3060 等桌面 GPU 上运行;量化推理可降低显存占用,具体显存数值 README 未说明。

支持 Apple Silicon需要 CUDA多卡 / 张量并行
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

智谱开源文生视频与图生视频模型,CogVideoX 系列可本地推理和微调

开源文生视频和图生视频模型,CogVideoX 支持从文本或图片生成视频,适合搭建视频生成推理服务。

核心能力

  • 用 3D 因果 VAE 近乎无损重建视频
  • 支持文生视频、图生视频和视频续写三类任务
  • 提供 SAT 与 diffusers 两套推理和微调代码
  • 集成量化推理与多卡并行推理工具
  • 附带 Gradio Web Demo 和提示词优化脚本

容易踩的坑

Python 版本需在 3.10 到 3.12 之间;模型训练使用长提示词,建议先用 GLM-4 等大模型做提示词优化;需按 requirements.txt 严格安装依赖,否则可能无法运行。

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

1 个版本v1.0
  1. v1.0CogVideoX-1.0最新正式版2024-11-08 · 2024-11-08 05:32 UTC

    If you are using the following models:

    • CogVideoX-2B
    • CogVideoX-5B
    • CogVideoX-5B-I2V

    Please use this release version of the SAT code to run.

    If you are using the following models:

    • CogVideoX1.5-5B
    • CogVideoX1.5-5B-I2V

    Please use the main branch or the updated release version of the code to run.


    如果你使用的模型是:

    • CogVideoX-2B
    • CogVideoX-5B
    • CogVideoX-5B-I2V

    请使用这个发布版的SAT代码进行运行。

    如果你使用的模型是:

    • CogVideoX1.5-5B
    • CogVideoX1.5-5B-I2V

    请使用 main 分支或更新发行版代码运行。

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    CogVideo & CogVideoX

    中文阅读

    日本語で読む

    Project Updates

    • 🔥🔥 News: 2025/03/24: We have launched CogKit, a fine-tuning and inference framework for the CogView4 and CogVideoX series. This toolkit allows you to fully explore and utilize our multimodal generation models.
    • 🔥 News: 2025/02/28: DDIM Inverse is now supported in CogVideoX-5B and CogVideoX1.5-5B. Check here.
    • 🔥 News: 2025/01/08: We have updated the code for Lora fine-tuning based on the diffusers version model, which uses less GPU memory. For more details, please see here.
    • 🔥 News: 2024/11/15: We released the CogVideoX1.5 model in the diffusers version. Only minor parameter adjustments are needed to continue using previous code.
    • 🔥 News: 2024/11/08: We have released the CogVideoX1.5 model. CogVideoX1.5 is an upgraded version of the open-source model CogVideoX. The CogVideoX1.5-5B series supports 10-second videos with higher resolution, and CogVideoX1.5-5B-I2V supports video generation at any resolution. The SAT code has already been updated, while the diffusers version is still under adaptation. Download the SAT version code here.
    • 🔥 News: 2024/10/13: A more cost-effective fine-tuning framework for CogVideoX-5B that works with a single 4090 GPU, cogvideox-factory, has been released. It supports fine-tuning with multiple resolutions. Feel free to use it!
    • 🔥 News: 2024/10/10: We have updated our technical report. Please click here to view it. More training details and a demo have been added. To see the demo, click here.- 🔥 News: 2024/10/09: We have publicly released the technical documentation for CogVideoX fine-tuning on Feishu, further increasing distribution flexibility. All examples in the public documentation can be fully reproduced.
    • 🔥 News: 2024/9/19: We have open-sourced the CogVideoX series image-to-video model CogVideoX-5B-I2V. This model can take an image as a background input and generate a video combined with prompt words, offering greater controllability. With this, the CogVideoX series models now support three tasks: text-to-video generation, video continuation, and image-to-video generation. Welcome to try it online at Experience.
    • 🔥 2024/9/19: The Caption model CogVLM2-Caption, used in the training process of CogVideoX to convert video data into text descriptions, has been open-sourced. Welcome to download and use it.
    • 🔥 2024/8/27: We have open-sourced a larger model in the CogVideoX series, CogVideoX-5B. We have significantly optimized the model's inference performance, greatly lowering the inference threshold. You can run CogVideoX-2B on older GPUs like GTX 1080TI, and CogVideoX-5B on desktop GPUs like RTX 3060. Please strictly follow the requirements to update and install dependencies, and refer to cli_demo for inference code. Additionally, the open-source license for the CogVideoX-2B model has been changed to the Apache 2.0 License.
    • 🔥 2024/8/6: We have open-sourced 3D Causal VAE, used for CogVideoX-2B, which can reconstruct videos with almost no loss.
    • 🔥 2024/8/6: We have open-sourced the first model of the CogVideoX series video generation models, **CogVideoX-2B **.
    • 🌱 Source: 2022/5/19: We have open-sourced the CogVideo video generation model (now you can see it in the CogVideo branch). This is the first open-source large Transformer-based text-to-video generation model. You can access the ICLR'23 paper for technical details.

    Table of Contents

    Jump to a specific section:

    Quick Start

    Prompt Optimization

    Before running the model, please refer to this guide to see how we use large models like GLM-4 (or other comparable products, such as GPT-4) to optimize the model. This is crucial because the model is trained with long prompts, and a good prompt directly impacts the quality of the video generation.

    SAT

    Please make sure your Python version is between 3.10 and 3.12, inclusive of both 3.10 and 3.12.

    Follow instructions in sat_demo: Contains the inference code and fine-tuning code of SAT weights. It is recommended to improve based on the CogVideoX model structure. Innovative researchers use this code to better perform rapid stacking and development.

    Diffusers

    Please make sure your Python version is between 3.10 and 3.12, inclusive of both 3.10 and 3.12.

    pip install -r requirements.txt
    

    Then follow diffusers_demo: A more detailed explanation of the inference code, mentioning the significance of common parameters.

    For more details on quantized inference, please refer to diffusers-torchao. With Diffusers and TorchAO, quantized inference is also possible leading to memory-efficient inference as well as speedup in some cases when compiled. A full list of memory and time benchmarks with various settings on A100 and H100 has been published at diffusers-torchao.

    Gallery

    CogVideoX-5B

    CogVideoX-2B

    To view the corresponding prompt words for the gallery, please click here

    Model Introduction

    CogVideoX is an open-source version of the video generation model originating from QingYing. The table below displays the list of video generation models we currently offer, along with their foundational information.

    Data Explanation

    • While testing using the diffusers library, all optimizations included in the diffusers library were enabled. This scheme has not been tested for actual memory usage on devices outside of NVIDIA A100 / H100 architectures. Generally, this scheme can be adapted to all NVIDIA Ampere architecture and above devices. If optimizations are disabled, memory consumption will multiply, with peak memory usage being about 3 times the value in the table. However, speed will increase by about 3-4 times. You can selectively disable some optimizations, including:
    pipe.enable_sequential_cpu_offload()
    pipe.vae.enable_slicing()
    pipe.vae.enable_tiling()
    
    • For multi-GPU inference, the enable_sequential_cpu_offload() optimization needs to be disabled.
    • Using INT8 models will slow down inference, which is done to accommodate lower-memory GPUs while maintaining minimal video quality loss, though inference speed will significantly decrease.
    • The CogVideoX-2B model was trained in FP16 precision, and all CogVideoX-5B models were trained in BF16 precision. We recommend using the precision in which the model was trained for inference.
    • PytorchAO and Optimum-quanto can be used to quantize the text encoder, transformer, and VAE modules to reduce the memory requirements of CogVideoX. This allows the model to run on free T4 Colabs or GPUs with smaller memory! Also, note that TorchAO quantization is fully compatible with torch.compile, which can significantly improve inference speed. FP8 precision must be used on devices with NVIDIA H100 and above, requiring source installation of torch, torchao Python packages. CUDA 12.4 is recommended.
    • The inference speed tests also used the above memory optimization scheme. Without memory optimization, inference speed increases by about 10%. Only the diffusers version of the model supports quantization.
    • The model only supports English input; other languages can be translated into English for use via large model refinement.

    Friendly Links

    We highly welcome contributions from the community and actively contribute to the open-source community. The following works have already been adapted for CogVideoX, and we invite everyone to use them:

    • LeMiCa: a diffusion model inference acceleration solution developed by China Unicom Data Science and Artificial Intelligence Research Institute. By leveraging cache-based techniques and global denoising path optimization, LeMiCa provides efficient inference support for CogVideoX, achieving nearly 2.5x lossless acceleration while maintaining visual consistency and quality.
    • RIFLEx-CogVideoX: RIFLEx extends the video with just one line of code: freq[k-1]=(2np.pi)/(Ls). The framework not only supports training-free inference, but also offers models fine-tuned based on CogVideoX. By fine-tuning the model for just 1,000 steps on original-length videos, RIFLEx significantly enhances its length extrapolation capability.
    • CogVideoX-Fun: CogVideoX-Fun is a modified pipeline based on the CogVideoX architecture, supporting flexible resolutions and multiple launch methods.
    • CogStudio: A separate repository for CogVideo's Gradio Web UI, which supports more functional Web UIs.
    • Xorbits Inference: A powerful and comprehensive distributed inference framework, allowing you to easily deploy your own models or the latest cutting-edge open-source models with just one click.
    • ComfyUI-CogVideoXWrapper Use the ComfyUI framework to integrate CogVideoX into your workflow.
    • VideoSys: VideoSys provides a user-friendly, high-performance infrastructure for video generation, with full pipeline support and continuous integration of the latest models and techniques.
    • AutoDL Space: A one-click deployment Huggingface Space image provided by community members.
    • Interior Design Fine-Tuning Model: is a fine-tuned model based on CogVideoX, specifically designed for interior design.
    • xDiT: xDiT is a scalable inference engine for Diffusion Transformers (DiTs) on multiple GPU Clusters. xDiT supports real-time image and video generations services. cogvideox-factory: A cost-effective fine-tuning framework for CogVideoX, compatible with the diffusers version model. Supports more resolutions, and fine-tuning CogVideoX-5B can be done with a single 4090 GPU.
    • CogVideoX-Interpolation: A pipeline based on the modified CogVideoX structure, aimed at providing greater flexibility for keyframe interpolation generation.
    • DiffSynth-Studio: DiffSynth Studio is a diffusion engine. It has restructured the architecture, including text encoders, UNet, VAE, etc., enhancing computational performance while maintaining compatibility with open-source community models. The framework has been adapted for CogVideoX.
    • CogVideoX-Controlnet: A simple ControlNet module code that includes the CogVideoX model.
    • VideoTuna: VideoTuna is the first repo that integrates multiple AI video generation models for text-to-video, image-to-video, text-to-image generation.
    • ConsisID: An identity-preserving text-to-video generation model, bases on CogVideoX-5B, which keep the face consistent in the generated video by frequency decomposition.
    • A Step by Step Tutorial: A step-by-step guide on installing and optimizing the CogVideoX1.5-5B-I2V model in Windows and cloud environments. Special thanks to the FurkanGozukara for his effort and support!

    Project Structure

    This open-source repository will guide developers to quickly get started with the basic usage and fine-tuning examples of the CogVideoX open-source model.

    Quick Start with Colab

    Here provide three projects that can be run directly on free Colab T4 instances:

    Inference

    • dcli_demo: A more detailed inference code explanation, including the significance of common parameters. All of this is covered here.
    • cli_demo_quantization: Quantized model inference code that can run on devices with lower memory. You can also modify this code to support running CogVideoX models in FP8 precision.
    • diffusers_vae_demo: Code for running VAE inference separately.
    • space demo: The same GUI code as used in the Huggingface Space, with frame interpolation and super-resolution tools integrated.
    • convert_demo: How to convert user input into long-form input suitable for CogVideoX. Since CogVideoX is trained on long texts, we need to transform the input text distribution to match the training data using an LLM. The script defaults to using GLM-4, but it can be replaced with GPT, Gemini, or any other large language model.
    • gradio_web_demo: A simple Gradio web application demonstrating how to use the CogVideoX-2B / 5B model to generate videos. Similar to our Huggingface Space, you can use this script to run a simple web application for video generation.

    finetune

    • finetune_demo: Fine-tuning scheme and details of the diffusers version of the CogVideoX model.

    sat

    • sat_demo: Contains the inference code and fine-tuning code of SAT weights. It is recommended to improve based on the CogVideoX model structure. Innovative researchers use this code to better perform rapid stacking and development.

    Tools

    This folder contains some tools for model conversion / caption generation, etc.

    • convert_weight_sat2hf: Converts SAT model weights to Huggingface model weights.
    • caption_demo: Caption tool, a model that understands videos and outputs descriptions in text.
    • export_sat_lora_weight: SAT fine-tuning model export tool, exports the SAT Lora Adapter in diffusers format.
    • load_cogvideox_lora: Tool code for loading the diffusers version of fine-tuned Lora Adapter.
    • llm_flux_cogvideox: Automatically generate videos using an open-source local large language model + Flux + CogVideoX.
    • parallel_inference_xdit: Supported by xDiT, parallelize the video generation process on multiple GPUs.

    CogVideo(ICLR'23)

    The official repo for the paper: CogVideo: Large-scale Pretraining for Text-to-Video Generation via Transformers is on the CogVideo branch

    CogVideo is able to generate relatively high-frame-rate videos. A 4-second clip of 32 frames is shown below.

    High-frame-rate sample

    Intro images

    The demo for CogVideo is at https://models.aminer.cn/cogvideo, where you can get hands-on practice on text-to-video generation. The original input is in Chinese.

    Citation

    🌟 If you find our work helpful, please leave us a star and cite our paper.

    @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}
    }
    @article{hong2022cogvideo,
      title={CogVideo: Large-scale Pretraining for Text-to-Video Generation via Transformers},
      author={Hong, Wenyi and Ding, Ming and Zheng, Wendi and Liu, Xinghan and Tang, Jie},
      journal={arXiv preprint arXiv:2205.15868},
      year={2022}
    }
    

    Model-License

    The code in this repository is released under the Apache 2.0 License.

    The CogVideoX-2B model (including its corresponding Transformers module and VAE module) is released under the Apache 2.0 License.

    The CogVideoX-5B model (Transformers module, include I2V and T2V) is released under the CogVideoX LICENSE.