feat: add COSMOS 2.5 DiT implementation
Implement NVIDIA's COSMOS 2.5 Diffusion Transformer (DiT) architecture in FastVideo with verified numerical accuracy against the official cosmos-predict2.5 reference.
Key changes:
-
Model Architecture (fastvideo/models/dits/cosmos2_5.py):
- Implement Cosmos25Transformer3DModel with 28 transformer blocks
- Add AdaLN-LoRA conditioning with proper modulation parameter computation
- Implement 3D RoPE with NTK-aware extrapolation for spatiotemporal encoding
- Add QK normalization using RMSNorm for improved training stability
- Support optional cross-attention projection for high-dimensional embeddings (Qwen 7B)
- Add learnable positional embeddings as optional feature
- Implement proper patch embedding/unpatchification for video processing
-
Configuration (fastvideo/configs/models/dits/cosmos2_5.py):
- Add Cosmos25ArchConfig with complete parameter mapping for checkpoint loading
- Map official checkpoint structure (net.blocks.) to FastVideo structure (transformer_blocks.)
- Support AdaLN modulation layers at block level (adaln_modulation_self_attn/cross_attn/mlp)
- Configure cross-attention projection for 100,352-dim Qwen embeddings
- Add LoRA parameter mappings for fine-tuning support
-
Tests (fastvideo/tests/transformers/test_cosmos2_5.py):
- Add comprehensive parity test against official MinimalV1LVGDiT reference
- Test both single-frame (image) and multi-frame (video) generation
- Verify checkpoint loading and weight consistency
- Achieve 0.173% relative difference in bfloat16 (excellent parity)
- Test video2world conditioning with condition masks
-
Registry (fastvideo/configs/models/dits/init.py):
- Register Cosmos25VideoConfig for model instantiation
Test Results:
- Max difference: 0.046875
- Mean difference: 0.001869
- Relative difference: 0.173% (excellent parity in bfloat16)
Summary of Changes
Hello @KyleShao1016, I'm Gemini Code Assist[^1]! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request integrates NVIDIA's COSMOS 2.5 Diffusion Transformer architecture into the FastVideo framework. The implementation includes key architectural components like AdaLN-LoRA conditioning, 3D Rotary Positional Embeddings, and QK normalization, along with a robust configuration for checkpoint compatibility. Extensive testing confirms high numerical accuracy against the official reference, ensuring reliable video generation capabilities.
Highlights
- COSMOS 2.5 DiT Implementation: Added the NVIDIA COSMOS 2.5 Diffusion Transformer (DiT) architecture to FastVideo, enabling advanced video generation capabilities.
- Numerical Accuracy Verified: Achieved excellent numerical accuracy, with a 0.173% relative difference in bfloat16, against the official COSMOS 2.5 reference implementation.
- Advanced Architectural Features: Implemented key features including 28 transformer blocks, AdaLN-LoRA conditioning, 3D Rotary Positional Embeddings (RoPE) with NTK-aware extrapolation, QK normalization, and optional cross-attention projection for high-dimensional embeddings (e.g., Qwen 7B).
- Comprehensive Configuration and Checkpoint Loading: Introduced
Cosmos25ArchConfigwith detailed parameter mappings to ensure seamless loading of official COSMOS 2.5 checkpoints and support for LoRA fine-tuning. - Robust Testing Suite: Included extensive parity tests covering both single-frame (image) and multi-frame (video) generation, checkpoint loading, and video2world conditioning with condition masks.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
[^1]: Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.
also please run pre-commit and fix lint