我们设计并实现了Open-Sora,这是一项致力于高效生成高质量视频的计划。我们希望将模型、工具及所有细节开放给所有人。秉持开源理念,Open-Sora不仅让先进的视频生成技术得以普及,还提供了一个简化视频生成复杂性的、流线型且用户友好的平台。借助Open-Sora,我们旨在促进内容创作领域的创新、创造力与包容性。
Github:https://github.com/hpcaitech/Open-Sora
📍 由于Open-Sora处于积极开发中,我们为不同版本保留了不同的分支。最新版本为main。旧版本包括:v1.0、v1.1、v1.2、v1.3。
# create a virtual env and activate (conda as an example)
conda create -n opensora python=3.10
conda activate opensora
# download the repo
git clone https://github.com/hpcaitech/Open-Sora
cd Open-Sora
# Ensure torch >= 2.4.0
pip install -v . # for development mode, `pip install -v -e .`
pip install xformers==0.0.27.post2 --index-url https://download.pytorch.org/whl/cu121 # install xformers according to your cuda version
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我们的模型针对图像到视频生成进行了优化,但也可用于文本到视频生成。为生成高质量视频,我们借助 flux 文本到图像模型,构建了一条文本到图像再到视频的流水线。对于 256x256 分辨率:
# Generate one given prompt
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_256px.py --save-dir samples --prompt "raining, sea"
# Generation with 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 分辨率:
# One GPU
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/t2i2v_768px.py --save-dir samples --prompt "raining, sea"
# Multi-GPU with colossalai sp
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。
您也可以直接运行文本转视频:
# One GPU for 256px
torchrun --nproc_per_node 1 --standalone scripts/diffusion/inference.py configs/diffusion/inference/256px.py --prompt "raining, sea"
# Multi-GPU for 768px
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 with 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
# Multi-GPU 768px
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 的张量并行。对于 768x768 分辨率,我们使用 colossalai 的序列并行。所有测试均使用 50 步。结果以 格式呈现。
| 分辨率 | 1x GPU | 2x GPUs | 4x GPUs | 8x GPUs |
|---|---|---|---|---|
| 256x256 | ||||
| 768x768 |
在 VBench 上,Open-Sora 2.0 显著缩小了与 OpenAI Sora 的差距,与 Open-Sora 1.2 相比,差距从 4.52% 降至 0.69%。

人类偏好结果显示,我们的模型与 HunyuanVideo 14B 和 Step-Video 30B 相当。

感谢以下杰出的贡献者:
如果您希望为该项目做出贡献,请参考 贡献指南。
这里我们仅列出部分项目。其他相关工作和数据集,请参考我们的报告。
@software{opensora,
author = {Zangwei Zheng and Xiangyu Peng and Tianji Yang and Chenhui Shen and Shenggui Li and Hongxin Liu and Yukun Zhou and Tianyi Li and Yang You},
title = {Open-Sora: Democratizing Efficient Video Production for All},
month = {March},
year = {2024},
url = {https://github.com/hpcaitech/Open-Sora}
}