模型概述
模型特點
模型能力
使用案例
🚀 Open-Sora:讓高效視頻製作惠及大眾
Open-Sora致力於高效產出高質量視頻,我們期望讓模型、工具及所有細節面向大眾開放。通過秉持開源原則,Open-Sora不僅讓先進的視頻生成技術得以廣泛應用,還打造了一個簡潔易用的平臺,降低了視頻生成的複雜度。我們的目標是在內容創作領域激發創新、創意和包容性。
Github: https://github.com/hpcaitech/Open-Sora
✨ 主要特性
🔆 報告
- Open-Sora 2.0技術報告
- 逐步訓練或微調你自己的模型
- 逐步訓練和評估視頻自動編碼器
- 訪問高壓縮視頻自動編碼器
- 先前版本的報告(建議在相應分支查看):
- Open-Sora 1.3:移位窗口注意力、統一時空VAE等。
- Open-Sora 1.2,技術報告:整流流、3D-VAE、分數條件、評估等。
- Open-Sora 1.1:多分辨率/長度/寬高比、圖像/視頻條件/編輯、數據預處理等。
- Open-Sora 1.0:架構、字幕等。
📍 由於Open-Sora正在積極開發中,我們為不同版本保留了不同的分支。最新版本是main。舊版本包括:v1.0,v1.1,v1.2,v1.3。
📦 安裝指南
安裝環境
# 創建並激活虛擬環境(以conda為例)
conda create -n opensora python=3.10
conda activate opensora
# 下載倉庫
git clone https://github.com/hpcaitech/Open-Sora
cd Open-Sora
# 確保torch >= 2.4.0
pip install -v . # 開發模式,也可使用 `pip install -v -e .`
pip install xformers==0.0.27.post2 --index-url https://download.pytorch.org/whl/cu121 # 根據你的cuda版本安裝xformers
pip install flash-attn --no-build-isolation
你也可以選擇安裝flash attention 3以提高速度:
git clone https://github.com/Dao-AILab/flash-attention # 4f0640d5
cd flash-attention/hopper
python setup.py install
模型下載
我們的11B模型支持256px和768px分辨率,一個模型同時支持文本到視頻(T2V)和圖像到視頻(I2V)。🤗 Huggingface 🤖 ModelScope。
從Huggingface下載:
pip install "huggingface_hub[cli]"
huggingface-cli download hpcai-tech/Open-Sora-v2 --local-dir ./ckpts
從ModelScope下載:
pip install modelscope
modelscope download hpcai-tech/Open-Sora-v2 --local-dir ./ckpts
💻 使用示例
基礎用法
文本到視頻生成
我們的模型針對圖像到視頻生成進行了優化,但也可用於文本到視頻生成。為了生成高質量視頻,藉助通量文本到圖像模型,我們構建了一個文本到圖像再到視頻的管道。
對於256x256分辨率:
# 生成一個給定提示的視頻
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea"
# 使用卸載以節省內存
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea" --offload True
# 使用csv文件進行生成
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --dataset.data-path assets/texts/example.csv
對於768x768分辨率:
# 單GPU
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_768px.py --save-dir samples --prompt "raining, sea"
# 多GPU使用colossalai序列並行
torchrun --nproc_per_node 8 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_768px.py --save-dir samples --prompt "raining, sea"
你可以通過--aspect_ratio
調整生成的寬高比,通過--num_frames
調整生成的幀數。寬高比的可選值包括16:9
、9:16
、1:1
、2.39:1
。幀數的可選值應為4k + 1
且小於129。
你也可以直接進行文本到視頻生成:
# 256px單GPU
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/256px.py --prompt "raining, sea"
# 768px多GPU
torchrun --nproc_per_node 8 --standalone scripts/diffusion/inference.py configs/diffusion/inference/768px.py --prompt "raining, sea"
圖像到視頻生成
給定一個提示和一張參考圖像,你可以使用以下命令生成視頻:
# 256px
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/256px.py --cond_type i2v_head --prompt "A plump pig wallows in a muddy pond on a rustic farm, its pink snout poking out as it snorts contentedly. The camera captures the pig's playful splashes, sending ripples through the water under the midday sun. Wooden fences and a red barn stand in the background, framed by rolling green hills. The pig's muddy coat glistens in the sunlight, showcasing the simple pleasures of its carefree life." --ref assets/texts/i2v.png
# 256px使用csv文件
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/256px.py --cond_type i2v_head --dataset.data-path assets/texts/i2v.csv
# 768px多GPU
torchrun --nproc_per_node 8 --standalone scripts/diffusion/inference.py configs/diffusion/inference/768px.py --cond_type i2v_head --dataset.data-path assets/texts/i2v.csv
高級用法
運動分數
在訓練過程中,我們會在文本提示中加入運動分數。在推理時,你可以使用以下命令生成帶有運動分數的視頻(默認分數為4):
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea" --motion-score 4
我們還提供了一個動態運動分數評估器。設置好你的OpenAI API密鑰後,你可以使用以下命令評估視頻的運動分數:
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea" --motion-score dynamic
分數 | 1 | 4 | 7 |
---|---|---|---|
![]() |
![]() |
![]() |
提示優化
我們利用ChatGPT來優化提示。你可以使用以下命令優化提示,該功能在文本到視頻和圖像到視頻生成中均可用:
export OPENAI_API_KEY=sk-xxxx
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea" --refine-prompt True
可重複性
為了使結果具有可重複性,你可以設置隨機種子:
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea" --sampling_option.seed 42 --seed 42
使用--num-sample k
為每個提示生成k
個樣本。
🔧 技術細節
計算效率
我們在H100/H800 GPU上測試了文本到視頻的計算效率。對於256x256分辨率,我們使用colossalai的張量並行,並開啟--offload True
;對於768x768分辨率,我們使用colossalai的序列並行。所有測試步數均為50。結果以$\color{blue}{\text{總時間 (s)}}/\color{red}{\text{峰值GPU內存 (GB)}}$的格式呈現:
分辨率 | 1x GPU | 2x GPUs | 4x GPUs | 8x GPUs |
---|---|---|---|---|
256x256 | $\color{blue}{60}/\color{red}{52.5}$ | $\color{blue}{40}/\color{red}{44.3}$ | $\color{blue}{34}/\color{red}{44.3}$ | |
768x768 | $\color{blue}{1656}/\color{red}{60.3}$ | $\color{blue}{863}/\color{red}{48.3}$ | $\color{blue}{466}/\color{red}{44.3}$ | $\color{blue}{276}/\color{red}{44.3}$ |
評估
在VBench上,Open-Sora 2.0顯著縮小了與OpenAI的Sora的差距,與Open-Sora 1.2相比,差距從4.52%縮小到0.69%。
人工偏好結果顯示,我們的模型與混元視頻11B和Step-Video 30B相當。
憑藉強大的性能,Open-Sora 2.0具有很高的性價比。
🤝 貢獻
感謝以下優秀的貢獻者:
如果你想為這個項目做出貢獻,請參考貢獻指南。
🙏 致謝
這裡僅列出部分項目,其他工作和數據集請參考我們的報告。
- ColossalAI:一個強大的大模型並行加速和優化系統。
- DiT:基於Transformer的可擴展擴散模型。
- OpenDiT:DiT訓練的加速方案,我們從OpenDiT中採用了有價值的加速策略。
- PixArt:一個基於DiT的開源文本到圖像模型。
- Flux:一個強大的文本到圖像生成模型。
- Latte:一種高效訓練DiT用於視頻的嘗試。
- HunyuanVideo:開源文本到視頻模型。
- StabilityAI VAE:一個強大的圖像VAE模型。
- DC-AE:用於圖像壓縮的深度壓縮自動編碼器。
- CLIP:一個強大的文本-圖像嵌入模型。
- T5:一個強大的文本編碼器。
- LLaVA:基於Mistral-7B和Yi-34B的強大圖像字幕模型。
- PLLaVA:一個強大的視頻字幕模型。
- MiraData:一個大規模、長時長且帶有結構化字幕的視頻數據集。
📄 許可證
本項目採用Apache-2.0許可證。
📖 引用
@article{opensora,
title={Open-sora: Democratizing efficient video production for all},
author={Zheng, Zangwei and Peng, Xiangyu and Yang, Tianji and Shen, Chenhui and Li, Shenggui and Liu, Hongxin and Zhou, Yukun and Li, Tianyi and You, Yang},
journal={arXiv preprint arXiv:2412.20404},
year={2024}
}
@article{opensora2,
title={Open-Sora 2.0: Training a Commercial-Level Video Generation Model in $200k},
author={Xiangyu Peng and Zangwei Zheng and Chenhui Shen and Tom Young and Xinying Guo and Binluo Wang and Hang Xu and Hongxin Liu and Mingyan Jiang and Wenjun Li and Yuhui Wang and Anbang Ye and Gang Ren and Qianran Ma and Wanying Liang and Xiang Lian and Xiwen Wu and Yuting Zhong and Zhuangyan Li and Chaoyu Gong and Guojun Lei and Leijun Cheng and Limin Zhang and Minghao Li and Ruijie Zhang and Silan Hu and Shijie Huang and Xiaokang Wang and Yuanheng Zhao and Yuqi Wang and Ziang Wei and Yang You},
year={2025},
journal={arXiv preprint arXiv:2503.09642},
}
⭐ 星標歷史



