联创首发-基于昇腾MindSpeed MM玩转Open-Sora Plan V1.5模型
发表于 2025/06/05
Open-Sora Plan V1.5模型介绍
Open-Sora Plan系列是大型多模态生成模型,使用当前比较前沿的DiT (Diffusion Transformer) 生成模型架构,该模型根据各种用户输入生成所需的高分辨率长时视频。Open-Sora Plan V1.5模型具有以下特征。
创新U型Sparse DiT(稀疏扩散Transformer)模型结构:
l 引入稀疏注意力机制,实现计算速度提升45%,推理速度提升35%
l 通过U形变化的稀疏度,提取多尺度交互信息,保证信息不损失
优化WFVAE模型结构:
l 通过因果卷积缓存技术,实现无损时域分块推理;
l 支持图和视频统一编码,重建效果媲美主流VAE(Variational Auto Encoder)模型,压缩比8*8*8,实现视频编码显存2~5倍降低,速度提升2倍
后训练:
l 原生支持DPO强化学习算法(正在迭代中),进一步增强画面细节,优化动作连贯性。
基于MindSpeed MM的Open-Sora Plan V1.5模型训练优化特性
Open-Sora Plan系列模型需要处理异构的长序列数据,对模型训练的内存开销和训练性能提出了挑战。为了应对这些挑战,MindSpeed MM对Open-Sora Plan V1.5模型使用了RMSNorm、ROPE融合算子、分布式优化器及流水调度优化等特性,实现了性能大幅度优化。
支持TP/SP混合并行策略,内存占用降低75%:
Open-Sora Plan v1.5模型参数量扩大为8.5B,模型训练容易因内存不足出现OOM问题,训练任务易中断。MindSpeed MM通过TP(张量并行)切分,按照行或者列对线性层的权重进行切分,在不同的device上并行计算不同部分的结果。当进一步扩大视频的分辨率时,模型需要处理的数据序列长度变长,激活值占用的显存增加,因此在TP切分的基础上进行SP(序列并行)切分,进一步对线性层之外的norm层计算时的激活值进行序列维度的切分,进一步减少单个device的显存占用和冗余计算,实现整体内存占用降低75%。
支持Encoder DP策略,提升训练性能15%:
在训练过程中,不同的模块(如VAE、Text Encoder 和 DiT)会共享相同的计算资源。为了最大化资源利用,不同模块采用了不同的分布式策略,其中VAE和Text Encoder使用DP,而DiT 采用DP + TP的混合策略,如果 VAE 和 Text Encoder 按照DiT的并行组(DP+TP)读取数据,就会有冗余的计算。因此,使用了Encoder DP策略,在VAE和 Text Encoder 阶段基于DP域读取数据,并将编码结果进行缓存,在数据进入DiT模块之前,会进行一轮广播,确保每个TP域内所有的设备都拿到一致的输入数据。通过减少VAE和Text Encoder模块的冗余计算,实现训练性能提升15%。
使用昇腾CANN亲和基础算子和高性能融合算子,提升训练性能和稳定性,MFU提升幅度达170%
开启AdamW EMA融合算子,缓解Diffusion Model训练后期,loss震荡问题,收敛效果更稳定;采用Rope昇腾融合算子,训练速度提升6.2%;采用RMS Norm昇腾融合算子,训练速度提升11.2%;整体MFU提升达170%。
基于MindSpeed MM的Open-Sora Plan V1.5文生视频体验
Prompt1:
A fluffy white rabbit with soft, velvety fur and twitching pink nose sits curiously near a rustic wooden fence, surrounded by a lush garden of vibrant wildflowers and tall grasses swaying gently in the breeze. The rabbit's large, expressive eyes scan the environment, reflecting the golden hues of the setting sun. As it nibbles on a patch of clover, its ears perk up at the distant sound of chirping birds. The fence, weathered and covered in patches of moss, adds a charming, pastoral backdrop to this serene scene, capturing the essence of a peaceful countryside moment.
(一只毛绒绒的白兔,毛绒绒的,粉红色的鼻子抽搐着,好奇地坐在乡村木栅栏附近,周围是郁郁葱葱的花园,有生机勃勃的野花和高大的草,在微风中轻轻摇曳。兔子那双富有表情的大眼睛扫视着周围的环境,反射出夕阳的金色。当它啃食一片三叶草时,它的耳朵听着远处鸟叫的声音就会竖起来。栅栏,风化和覆盖着成片的苔藓,为这宁静的场景增添了迷人的田园背景,捕捉了宁静的乡村时刻的精髓。)
输出结果1:
Open-Sora Plan V1.3的生成结果
Open-Sora Plan V1.5的生成结果
V1.3和V1.5的效果对比:V1.5生成的视频更清晰,画面生动且动作更加协调。
Prompt2:
A majestic Berlin tower stands tall against the night sky, its structure bathed in a mesmerizing array of vibrant lights, casting a kaleidoscope of colors across the cityscape. The tower's intricate architectural details are highlighted by the illumination, creating a stunning contrast against the deep indigo sky. As the camera pans upward, the lights shift, revealing a dynamic play of shadows and hues that dance across the tower's surface. The surrounding city lights twinkle in harmony, enhancing the tower's grandeur and creating a breathtaking visual symphony that captures the essence of Berlin's vibrant nightlife.
(一座雄伟的柏林塔在夜空的映照下巍然屹立,其结构沐浴在迷人的充满活力的灯光中,为城市景观投下万花筒般的色彩。塔楼错综复杂的建筑细节被照明突出,与深邃的靛蓝天空形成了惊人的对比。当摄影机向上平移时,灯光会移动,呈现出阴影和色调在塔的表面上舞动的动态游戏。周围的城市灯光和谐地闪烁,增强了塔的宏伟气派,并创造了令人叹为观止的视觉交响乐,捕捉了柏林充满活力的夜生活的精髓。)
输出结果2:
Open-Sora Plan V1.3的生成结果
Open-Sora Plan V1.5的生成结果
V1.3和V1.5的效果对比:V1.5生成的视频,运镜效果更加流畅,夜景更清晰。
Prompt3:
A beautifully plated pumpkin dish sits elegantly on a rustic wooden table, showcasing vibrant orange hues and a delicate garnish of fresh herbs. The dish is artfully arranged with roasted pumpkin cubes, drizzled with a rich, golden-brown glaze that glistens under soft, ambient lighting. Surrounding the pumpkin are sprigs of rosemary and a sprinkle of toasted seeds, adding texture and aroma. The plate itself is a simple, white ceramic, allowing the colors of the dish to pop. In the background, a faint hint of autumn leaves and a cozy, warm atmosphere enhance the seasonal essence of this culinary masterpiece.
一道精美的南瓜盘优雅地摆放在质朴的木桌上,展示着充满活力的橙色色调和新鲜香草的精致装饰。这道菜巧妙地安排了烤南瓜块,淋上浓郁的金棕色釉,在柔和的环境灯光下闪闪发光。围绕着南瓜的是迷迭香小枝和烤过的种子,增加了口感和香气。盘子本身是一个简单的白色陶瓷,让菜肴的颜色流行。背景中,淡淡的秋叶和舒适温馨的氛围增强了这一美食杰作的季节性精髓。
输出结果3:
Open-Sora Plan V1.3的生成结果
Open-Sora Plan V1.5的生成结果
V1.3和V1.5的效果对比:V1.5生成的视频,物体呈现更准确。
更多Open-Sora Plan V1.5文生视频:
快速上手 基于MindSpeed MM 玩转Open-Sora Plan V1.5
【环境安装】
模型开发时推荐使用配套的环境版本,详见仓库中的“环境安装”
1、仓库拉取:
见以下链接的”仓库拉取”章节
https://gitee.com/ascend/MindSpeed-MM/blob/master/examples/opensoraplan1.5/README.md
torch_npu与CANN包安装参考链接:
# python3.10
conda create -n test python=3.10
conda activate test
# 安装 torch 和 torch_npu,注意要选择对应python版本、x86或arm的torch、torch_npu及apex包
pip install torch-2.1.0-cp310-cp310m-manylinux2014_aarch64.whl
pip install torch_npu-2.1.0*-cp310-cp310m-linux_aarch64.whl
# apex for Ascend 参考 https://gitee.com/ascend/apex
# 建议从原仓编译安装
# 将shell脚本中的环境变量路径修改为真实路径,下面为参考路径
source /usr/local/Ascend/ascend-toolkit/set_env.sh
# 安装加速库
git clone https://gitee.com/ascend/MindSpeed.git
cd MindSpeed
# checkout commit from MindSpeed core_r0.8.0
git checkout 1ada966f33d6fab6eff7c95b197aae51f8790926
pip install -r requirements.txt
pip install -e .
cd ..
# 安装其余依赖库
pip install -e .
【权重下载及转换】
权重链接:https://modelers.cn/models/PKU-YUAN-Group/Open-Sora-Plan-v1.5.0
权重转换:MindSpeed MM在重构过程中修改了部分网络的结构名称,使用下面的脚本对原始预训练权重进行转换,该脚本实现了权重的转换和TP切分
python example/opensoraplan1.5/convert_to_mm.py \
--source_path <your_source_path> \
--target_path <your_target_path> \
--tp_size <tp_size>
【数据集准备处理】
用户需要将自己的数据集处理成如下格式
</dataset>
├──data.json
├──videos
│ ├──video0001.mp4
│ ├──video0002.mp4
其中,videos/下存放视频,data.json中包含该数据集中所有的视频-文本对信息,具体示例如下:
[
{
"path": "videos/video0001.mp4",
"cap": "Video discrimination1.",
"num_frames": 81,
"fps": 24,
"resolution": {
"height": 480,
"width": 832
}
},
{
"path": "videos/video0002.mp4",
"cap": "Video discrimination2.",
"num_frames": 81,
"fps": 24,
"resolution": {
"height": 480,
"width": 832
}
},
......
]
修改examples/opensoraplan1.5/data.txt文件,其中每一行表示个数据集,第一个参数表示数据文件夹的路径,第二个参数表示data.json文件的路径,用,分隔
【全参微调】
bash examples/opensoraplan1.5/pretrain.sh
【推理】
bash examples/opensoraplan1.5/inference.sh
【更多详细信息请见模型指导链接】
MindSpeed MM仓库readme链接:https://gitee.com/ascend/MindSpeed-MM/blob/master/examples/opensoraplan1.5/README.md
魔乐社区模型链接:https://modelers.cn/models/PKU-YUAN-Group/Open-Sora-Plan-v1.5.0
结语
Open-Sora Plan是由北大-兔展AIGC联合实验室发起的一个开源项目,其目标是复现OpenAI强大的视频生成模型Sora(T2V模型),并深入研究Video-VQVAE(VideoGPT)和DiT技术。Open-Sora Plan系列多模态模型会持续迭代,MindSpeed MM也将上线更加丰富的特性,敬请期待。
欢迎关注MindSpeed MM:https://gitee.com/ascend/MindSpeed-MM