# CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer

CogVideoX generates coherent ten-second text-to-video clips with an expert transformer

Zhuoyi Yang, Jiayan Teng, Wendi Zheng, Ming Ding, Shiyu Huang, Jiazheng Xu and 12 more · arXiv · 2024-8-12

- **Problem** Earlier video models produced clips with little movement and short durations. They struggled to build coherent narratives from text, because video is costly to model and the sequence grows with frames and resolution.
- **Method** CogVideoX compresses videos in both space and time with a 3D causal VAE. An expert transformer then fuses text and video tokens in one sequence, using separate normalization for each modality.
- **Results** CogVideoX-5B scored 3.36 on GPT4o-MTScore against 3.09 for CogVideoX-2B. In human evaluation it scored 2.74 against 2.17 for Kling.

## Why long coherent video is hard for diffusion transformers

Diffusion transformers can now produce short clips from text, but a prompt that asks for an event unfolding over time, such as lightning splitting a rock and a person stepping out, is still hard to render as one consistent sequence. Video carries far more data than a single image, because it has both spatial and temporal structure, so the token count a transformer must handle grows quickly with frames and resolution.

A common shortcut is to fine-tune a 2D image VAE on video, but this does not exploit the redundancy between neighbouring frames, and it leaves the sequence long and the frames prone to flicker.

CogVideoX addresses these pressures on several fronts at once: a compression model that works in time as well as space, a transformer that fuses text and vision in one sequence, staged training that packs mixed clips, and a data pipeline that rewrites captions. Each of these choices is tested in its own ablation or comparison, so the sections below follow that structure rather than the order of the pipeline.

## How text and video share one sequence

CogVideoX is a large-scale diffusion transformer that combines a 3D causal VAE, an expert transformer and progressive training, and it is released in 5B and 2B sizes. A clip is first encoded by the 3D causal VAE into a latent, and the latent is patchified and unfolded into one long vision sequence. The prompt is encoded by T5 into text embeddings, and these are concatenated with the vision tokens along the sequence axis before they enter the stack of expert transformer blocks.

After the blocks, the output is unpatchified back to the latent shape and decoded by the 3D causal VAE decoder into frames.

Because both modalities share one sequence, the transformer has to deal with the fact that text and video embeddings can differ in feature space and numerical scale, and most of the later design is aimed at that issue.

## A 3D causal VAE that compresses in time as well as space

The VAE has an encoder, a decoder and a KL regularizer. Each stage of the encoder and decoder is made of ResNet blocks and changes resolution by a factor of 2, and some stages downsample in time as well as space while others act only in space. Taken together, the compression from pixels to latents is 8×8×4. Temporal convolutions use causal padding placed entirely at the start of the sequence, so an output frame never depends on frames that come later.

The authors argue that this compression, compared with fine-tuning a 2D VAE, shortens the sequence and the training compute, and that it also reduces flicker by keeping adjacent frames consistent.

Training runs in two stages: first on 17-frame clips at 256×256 with the frame rate randomly chosen as 8 or 16 fps, then fine-tuned on 161-frame videos with context parallelism along the time axis. Because the convolution is causal, each device only has to send a segment of length k − 1 to the next device, where k is the temporal kernel size, which keeps the communication cost low.

The loss combines an L1 reconstruction term, an LPIPS perceptual term and a KL term, and a 3D discriminator adds a GAN loss after a few thousand steps.

## What the VAE comparisons show

In the ablation, the SDXL 2D VAE baseline with 8×8×1 compression and 4 latent channels reaches a Flickering score of 93.2 and a PSNR of 28.4, where lower Flickering means less frame-to-frame jitter. Variant D has the highest PSNR among the 3D variants at 30.5, but its Flickering is 87.7, and the excerpt does not give a reason for preferring B.

Pushing compression to 16×16×8 with 128 latent channels lowers PSNR to 27.9 and makes convergence extremely difficult, which the authors leave to future work on larger compression ratios.

The comparison is not controlled for latent width, since the other VAEs use fewer latent channels than the proposed one.

## Patches, 3D positions and modality-specific normalization

The latent of shape T × H × W × C is patchified into a sequence whose length the authors write as T\_q · H\_p · W\_p. When q is greater than 1, the first frame of a video, or an image, is repeated at the start of the sequence, which lets images and videos train together. Positions are encoded by extending rotary position embedding to three dimensions: each token has an (x, y, t) coordinate, and a 1D RoPE is applied to each coordinate over 3/8, 3/8 and 2/8 of the hidden channels, with the results concatenated.

Expert Adaptive Layernorm keeps the two modalities separate inside the normalization step. The diffusion timestep t drives the modulation, following DiT, and a vision-specific and a text-specific AdaLN each apply it to their own hidden states. The authors argue that this aligns the two feature spaces while adding few parameters, because the same timestep signal is reused and no second full transformer is needed.

Spatial and temporal attention in separate steps forces information about a moving object to travel through background patches, so a head in frame i+1 cannot attend directly to the same head in frame i. The authors therefore use 3D full attention, a text-video hybrid in which every position attends over the joint space and time grid, and they say FlashAttention keeps the longer sequence affordable.

## Training with mixed durations and staged resolutions

Images are treated as single-frame videos, and training uses v-prediction with zero SNR on the LDM noise schedule. Joint training on images and videos with a fixed frame count has two problems: the model splits into two generative modes depending on token count, and short clips must be dropped or long clips truncated. Multi-Resolution Frame Pack instead puts clips of different durations and resolutions into the same batch so that each batch has a consistent shape, following the Patch'n Pack idea.

Because the batch holds mixed shapes, 3D RoPE must cover varied positions, and the authors choose extrapolation over interpolation, selecting the front portion of a larger position table, since RoPE encodes relative positions.

Progressive training starts at 256px, which the authors use to learn semantic and low-frequency content, and then raises resolution to 512px and 768px while keeping each clip's aspect ratio. Table 5 lists four stages: 256×384 at 6s with batch size 2000 for 400k steps, 480×720 at 6s with batch size 1000 for 220k steps, 768×1360 at 10s with batch size 250 for 120k steps, and a fine-tuning stage at 768×1360 with batch size 100 for 10k steps.

The standard diffusion objective is written as follows, with t drawn uniformly from 1 to T. Explicit Uniform Sampling splits the range from 1 to T into n intervals, where n is the number of data-parallel ranks, and each rank draws its timesteps from its own interval, so the batch covers the timestep range more evenly than independent random draws do.

## Filtering and recaptioning the video corpus

After filtering, about 35M single-shot clips remain, averaging about 6 seconds each, and 2B aesthetically filtered images from LAION-5B and COYO-700M are added to help training. The authors labelled 20,000 sampled videos as positive or negative and trained six classifiers based on Video-LLaMA. Optical flow and aesthetic scores are also computed, and their thresholds are adjusted dynamically during training.

On a randomly labelled 10% test split, the classifier test accuracy is 0.91 for Editing, 0.92 for Static, 0.99 for Lecture, 0.96 for Text, 0.98 for Screenshot and 0.89 for Low Quality.

Existing short captions from Panda70M, COCO Caption and WebVid are usually brief, so the authors build a dense pipeline: short captions from Panda70M, a per-frame description from CogVLM, and a GPT-4 summary. Frames are extracted once every two seconds for image captioning, and 50,000 data points were collected to fine-tune the summary model, which is a LLaMA2 model trained on the GPT-4 summaries to speed up generation.

CogVLM2-Caption is then fine-tuned from CogVLM2-Video and Llama3 on the dense caption data to caption videos end to end. Caption quality is shown through side-by-side examples against Panda-70M captions, and the excerpt reports no quantitative caption metric.

## Architecture and sampling ablations

The 3D RoPE training loss converges significantly faster than the loss of sinusoidal absolute position embedding, which the authors note matches the common choice in LLMs. Three designs are compared on 500 WebVid test videos: MMDiT, Expert AdaLN and no Expert AdaLN, with MMDiT1 matching the parameter count of Expert AdaLN and MMDiT2 having the same number of layers but twice the parameters.

Expert AdaLN beats the variant without it and beats MMDiT1 on FVD, CLIP4Clip score and loss, so the authors conclude that two independent transformers are not needed.

Replacing 3D full attention with 2D + 1D attention gives a much higher FVD in early training. The 2D + 1D variant was also unstable and prone to collapse, and the authors suspect that instability grows with model size, which they say is a hypothesis they did not test at 5B.

With Explicit Uniform Sampling, the loss decreases more steadily, and Table 9 compares validation loss at five timesteps after 40k steps. Validation loss is lower with explicit uniform sampling at every timestep: 0.216 versus 0.222 at timestep 100, 0.126 versus 0.130 at 300, 0.116 versus 0.119 at 500, 0.129 versus 0.133 at 700 and 0.157 versus 0.161 at 900.

The authors attribute the gain to the loss differing strongly across timesteps, so uneven sampling makes the batch loss fluctuate.

## Automated metrics against open models

The evaluation uses VBench dimensions judged consistent with human perception, namely Human Action, Scene, Dynamic Degree, Multiple Objects and Appearance Style, and omits color because color tends to favour simple static videos. Two further measures, Dynamic Quality and GPT4o-MTScore, are used because a model can score well by producing little change between frames.

CogVideoX-5B is best on five of the seven metrics and competitive on the other two, and the authors read this as strength in both quality and dynamic scenes. On GPT4o-MTScore, CogVideoX-5B reaches 3.36 and CogVideoX-2B 3.09, above the next listed model, VideoCrafter-2.0 at 2.68.

## Human scores against Kling

Evaluators score four aspects, Sensory Quality, Instruction Following, Physics Simulation and Cover Quality, with each detail rated 0, 0.5 or 1 and a total up to 5. Against Kling, CogVideoX-5B reaches a total of 2.74 while Kling reaches 2.17, and the authors report that CogVideoX-5B is preferred on every aspect.

## Inference cost at each setting

For CogVideoX-5B at 768×1360 with 5s clips, inference takes 500s and 76GB on H800 with 50 inference steps, and at 480×720 with 6s clips it takes 113s and 26GB. The 2B model takes 220s and 53GB at 768×1360 with 5s clips, and 49s and 18GB at 480×720 with 6s clips, under the same measurement settings.

Per forward step, 3D full attention takes 9.60s at 768×1360 with 5s clips, against 4.17s for 2D + 1D, and 2.11s against 1.26s at 480×720 with 6s clips. At 256×384 with 6s clips the two are close, 0.41s for 3D against 0.38s for 2D + 1D, and the authors credit FlashAttention with keeping the longer sequences acceptable.

## Limits the authors state and the gaps left open

The 16×16×8 VAE does not converge easily, and larger compression ratios are left as future work. The 2D + 1D attention variant is unstable, and the authors' explanation for why it fails at larger sizes is a hypothesis. Fine-tuning on the high-quality subset removes subtitles and watermarks but slightly weakens semantic ability.

The ablations run on 500 WebVid test videos, and the excerpt does not state the model size used for them or the number of seeds behind the loss curves. The timestep sampling evidence is a single validation-loss table at 40k steps.

## Paper info

- **Authors**: Zhuoyi Yang, Jiayan Teng, Wendi Zheng, Ming Ding, Shiyu Huang, Jiazheng Xu, Yuanming Yang, Wenyi Hong, Xiaohan Zhang, Guanyu Feng, Da Yin, Yuxuan Zhang, Weihan Wang, Yean Cheng, Bin Xu, Xiaotao Gu, Yuxiao Dong, Jie Tang
- **Venue**: arXiv · Preprint
- **First published**: 2024-8-12
- **Added**: 2026-11-12
- **Updated**: 2025-3-26
- **Version**: v3
- **arXiv**: 2408.06072
- **Category**: cs.CV
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2408.06072v3) · [PDF ↗](https://arxiv.org/pdf/2408.06072v3)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Zhuoyi Yang, Jiayan Teng, Wendi Zheng, Ming Ding, Shiyu Huang, Jiazheng Xu, Yuanming Yang, Wenyi Hong, Xiaohan Zhang, Guanyu Feng, Da Yin, Yuxuan Zhang, Weihan Wang, Yean Cheng, Bin Xu, Xiaotao Gu, Yuxiao Dong, Jie Tang (2024). CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer. arXiv:2408.06072v3. https://arxiv.org/abs/2408.06072v3

**BibTeX**

```
@misc{yang2024cogvideox,
  title = {{CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer}},
  author = {Zhuoyi Yang and Jiayan Teng and Wendi Zheng and Ming Ding and Shiyu Huang and Jiazheng Xu and Yuanming Yang and Wenyi Hong and Xiaohan Zhang and Guanyu Feng and Da Yin and Yuxuan Zhang and Weihan Wang and Yean Cheng and Bin Xu and Xiaotao Gu and Yuxiao Dong and Jie Tang},
  year = {2024},
  eprint = {2408.06072},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2408.06072v3}
}
```

## Other paper commentary

- [Adversarial Examples: Attacks and Defenses for Deep Learning](https://refivu.com/en/papers/757e3533-c849-4349-8fbc-e8ea84c0b042-adversarial-examples-attacks-and-defenses-for-deep-learning.md)
- [Generative Adversarial Network in Medical Imaging: A Review](https://refivu.com/en/papers/52fe40f2-c64e-4c29-a115-6564288d69f5-generative-adversarial-network-in-medical-imaging-a-review.md)
- [AttnGAN: Fine-Grained Text to Image Generation with Attentional Generative Adversarial Networks](https://refivu.com/en/papers/a0260608-3d36-436c-af24-a535c7e4e5ef-attngan-fine-grained-text-to-image-generation-with.md)
- [Stochastic Variational Inference](https://refivu.com/en/papers/36c9d62c-308d-476e-8657-7d699cf4658e-stochastic-variational-inference.md)
- [Transferability in Machine Learning: from Phenomena to Black-Box Attacks using Adversarial Samples](https://refivu.com/en/papers/0070f617-bee7-4459-b94e-a20f7c1d2de5-transferability-in-machine-learning-from-phenomena-to-black.md)
- [Conditional Adversarial Domain Adaptation](https://refivu.com/en/papers/a233380e-bb76-4fca-bc73-df4e86a220e3-conditional-adversarial-domain-adaptation.md)
- [Neural Combinatorial Optimization with Reinforcement Learning](https://refivu.com/en/papers/428e6cb1-5b5b-43dc-ad1f-c954e953fc5b-neural-combinatorial-optimization-with-reinforcement.md)
- [Towards Open Set Deep Networks](https://refivu.com/en/papers/2821701d-d008-4717-86f5-1119fb0809bf-towards-open-set-deep-networks.md)
- [Graph Embedding Techniques, Applications, and Performance: A Survey](https://refivu.com/en/papers/eeed1384-bf87-452c-b3b1-9ecc6ce7d43b-graph-embedding-techniques-applications-and-performance-a.md)
- [Expanding Performance Boundaries of Open-Source Multimodal Models with Model, Data, and Test-Time Scaling](https://refivu.com/en/papers/90a6655e-9301-4ffa-a598-267663200fa0-expanding-performance-boundaries-of-open-source-multimodal.md)
- [A Multitask, Multilingual, Multimodal Evaluation of ChatGPT on Reasoning, Hallucination, and Interactivity](https://refivu.com/en/papers/a220e44a-f4ac-4a9b-9268-eefcbafeda8e-a-multitask-multilingual-multimodal-evaluation-of-chatgpt-on.md)
- [Image Captioning with Semantic Attention](https://refivu.com/en/papers/1d01d0ec-7423-41cc-9a8a-b002bc483a11-image-captioning-with-semantic-attention.md)

## Terms in this paper

- [GPT-4](https://refivu.com/en/terms/1e2d0d2cdc44-gpt-4)
- [T5](https://refivu.com/en/terms/ae2113eb6c55-t5)
- [Human evaluation](https://refivu.com/en/terms/b64307b0a4d2-human-evaluation)
- [LAION-5B](https://refivu.com/en/terms/c4513407f9c3-laion-5b)
- [Diffusion Transformers (DiT)](https://refivu.com/en/terms/eb4fa20323fe-diffusion-transformers-dit)
- [LLaMA2](https://refivu.com/en/terms/3716d8f794c0-llama2)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/d337167e-74d3-423d-ae74-fbe584f8b441-cogvideox-text-to-video-diffusion-models-with-an)
