文件最后提交记录最后更新时间
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6793 [PyTorch][built-in][OpenSora]turn on PYTORCH_NPU_ALLOC_CONF Merge pull request !6793 from liuqiyuan/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
fix link validity Co-authored-by: frozenleaves<914814442@qq.com> # message auto-generated for no-merge-commit merge: !7517 merge master into master fix link validity Created-by: frozenn Commit-by: frozenleaves Merged-by: ascend-robot Description: ## Motivation Please describe the motivation of this PR and the goal you want to achieve through this PR. ## Modification Please briefly describe what modification is made in this PR. ## Self-test (Optional) If modifications to this PR may cause/fix function/accuracy/performance DTSs/issues, a self-inspection record needs to be attached. ## BC-breaking (Optional) If there are compatibility issues, such as dependencies on cann/torch_npu versions, they need to be explained in the PR. ## Checklist **Before PR**: - [ ] The new code needs to comply with the Clean Code specification. - [ ] The PR content is self-checked, and the expression can be clear and the writing standardized **After PR**: - [ ] CLA has been signed and all committers have signed the CLA in this PR. - [ ] The ci-pipeline is passed, Code Check is passed. See merge request: Ascend/ModelZoo-PyTorch!75171 个月前
!6719 [built-in][Pytorch] 调整多模态模型存放目录 Merge pull request !6719 from zhangjunyi08/master 1 年前
README.md

OpenSora for PyTorch

注意: 本仓库OpenSora-master模型将不再进行维护,请使用MindSpeed-MM

目录

简介

模型介绍

OpenSora是HPC AI Tech开发的开源高效复现类Sora视频生成方案。OpenSora不仅实现了先进视频生成技术的低成本普及,还提供了一个精简且用户友好的方案,简化了视频制作的复杂性。 本仓库主要将OpenSora1.1的STDiT2模型和OpenSora1.2的STDiT3模型的任务迁移到了昇腾NPU上,并进行极致性能优化。

注:OpenSora主线从此目录演进,包含OpenSora1.1和OpenSora1.2,OpenSora1.0单独维护,见 PyTorch/built-in/mlm/OpenSora1.0 · Ascend/ModelZoo-PyTorch - 码云 - 开源中国 (gitcode.com)

注意: OpenSora-master目录下面的OpenSora1.2模型已经集成到MindSpeed-MM中,当前目录下的OpenSora1.2模型不再维护,MindSpeed-MM是面向大规模分布式训练的昇腾多模态大模型套件,同时支持多模态生成及多模态理解,欢迎大家使用。

支持任务列表

本仓已经支持以下模型任务类型

模型 任务列表 是否支持
STDiT2-XL/2 预训练
STDiT2-XL/2 在线推理
STDiT3-XL/2 预训练
STDiT3-XL/2 在线推理

代码实现

  • 参考实现:

    url=https://github.com/hpcaitech/Open-Sora
    commit_id=1295446e08ecdfe3a42ac93efd876dffacc76d5f
    
  • 适配昇腾 AI 处理器的实现:

    url=https://gitcode.com/ascend/ModelZoo-PyTorch.git
    code_path=PyTorch/built-in/mm/OpenSora-master
    

准备环境

安装模型环境

表 3 三方库版本支持表

三方库 支持版本
PyTorch 2.1.0
TorchVision 0.16.0

在模型根目录下执行以下命令,安装模型对应PyTorch版本需要的依赖。

source ${cann_install_path}/ascend-toolkit/set_env.sh              # 激活cann环境
cd OpenSora-master
pip install -v -e .                                                # 安装本地代码仓,同时自动安装依赖

安装mindspeed:

git clone https://gitcode.com/ascend/MindSpeed.git
pip install -e MindSpeed

安装昇腾环境

请参考昇腾社区中《Pytorch框架训练环境准备》文档搭建昇腾环境,本仓已支持表4中软件版本。

表 4 昇腾软件版本支持表

软件类型 支持版本
FrameworkPTAdapter 在研版本
CANN 在研版本
昇腾NPU固件 在研版本
昇腾NPU驱动 在研版本

准备数据集

训练数据集准备

训练数据集准备请参考官网,链接如下:

https://github.com/hpcaitech/Open-Sora?tab=readme-ov-file#data-processing

训练数据处理

处理数据并得到包含数据信息的csv文件,放在模型文件夹下,如下:

$OpenSora-master
├── train_data.csv
└── ...

其中train_data.csv中必须要包含的字段及含义如下:

path		# 视频绝对路径
text		# 视频文本标注
num_frames	# 视频帧数
width			# 视频宽度
height		# 视频高度

STDiT2(在研版本)

获取预训练模型

  1. 联网情况下,预训练模型会自动下载。

  2. 无网络时,用户可访问huggingface官网自行下载,文件namespace如下:

    PixArt-alpha/PixArt-alpha   # PixArt-XL-2-512x512模型(训练用)
    stabilityai/sd-vae-ft-ema   # vae模型
    DeepFloyd/t5-v1_1-xxl       # t5模型
    hpcai-tech/OpenSora-STDiT-v2-stage2        # 预训练权重(推理用)
    hpcai-tech/OpenSora-STDiT-v2-stage3        # 预训练权重(推理用)
    
  3. 获取对应的预训练模型后,在以下配置文件中将modelvaefrom_pretrained参数设置为本地预训练模型绝对路径。

    configs/opensora-v1-1/inference/sample.py
    configs/opensora-v1-1/train/stage1.py
    configs/opensora-v1-1/train/stage2.py
    configs/opensora-v1-1/train/stage3.py
    
  4. 将下载好的t5模型放在本工程目录下的DeepFloyd目录下,组织结构如下:

    $OpenSora-master
    ├── DeepFloyd
    ├── ├── t5-v1_1-xxl
    ├── ├── ├── config.json
    ├── ├── ├── pytorch_model-00001-of-00002.bin
    ├── ├── ├── ...
    └── ...
    

快速开始

训练任务

本任务主要以预训练模型为主,展示训练任务,包含单机单卡和单机多卡的训练。

开始训练

  1. 进入解压后的源码包根目录。

    cd /${模型文件夹名称} 
    
  2. 准备训练数据。 按照官网流程,准备对应数据集,获取对应数据集后,在以下配置文件中将datasetdata_path设置为数据集的绝对路径

    configs/opensora-v1-1/train/stage1.py
    configs/opensora-v1-1/train/stage2.py
    configs/opensora-v1-1/train/stage3.py
    
  3. 运行训练脚本。

    用户可以按照自己训练需要进行参数配置,以下给出单卡和多卡的一种训练示例。

    bash test/train_full_1p_opensorav1_1.sh
    # 混合精度BF16,单卡训练,stage1
    
    bash test/train_full_8p_opensorav1_1.sh
    # 混合精度BF16,八卡训练,stage1
    

训练结果

性能
Stage 芯片 卡数 平均单步耗时 AMP_Type Torch_Version
Stage1 竞品 8 1.59 s bf16 2.1
Stage1 Atlas 800T A2 8 1.46 s bf16 2.1
Stage2 竞品 8 11.10 s bf16 2.1
Stage2 Atlas 800T A2 8 12.97 s bf16 2.1
Stage3 竞品 8 16.12 s bf16 2.1
Stage3 Atlas 800T A2 8 18.97 s bf16 2.1

注:动态分辨率端到端耗时与数据集强相关,该性能仅供参考,stage1/2/3对应训练的三个阶段,可以在train_full_8p_opensorav1_1.sh中修改

推理任务

本任务主要以预训练模型为主,展示推理任务,包括单卡在线推理。

开始推理

  1. 进入解压后的源码包根目录。

    cd /${模型文件夹名称} 
    
  2. 运行推理的脚本。

  • 单机单卡推理
    bash test/infer_full_1p_opensorav1_1.sh  # 混精bf16 在线推理
    
  • 推理脚本参数说明如下
    test/infer_full_1p_opensorav1_1.sh
    --batch_size                         //设置batch_size
    --prompt                             //测试用的prompt
    --num_frames                         //生成视频的总帧数
    --img_h                              //生成视频的宽
    --img_w                              //生成视频的高
      
    scripts/inference.py
    config                               //配置文件路径
    --seed                               //随机种子    
    --batch-size                         //设置batch_size
    --prompt-path                        //推理使用的prompt文件路径
    --prompt                             //测试用的prompt
    --num-frames                         //生成视频的总帧数
    --image-size                         //生成视频的分辨率
    --fps                                //生成视频的帧率
    --save-dir                           //输出视频的路径
    --num-sampling-steps                 //推理的采样步数
    --cfg-scale                          //无分类器引导的权重系数
    

STDiT3 (在研版本)

获取预训练模型

  1. 联网情况下,预训练模型会自动下载。

  2. 无网络时,用户可访问huggingface官网自行下载,文件namespace如下:

    PixArt-alpha/PixArt-Sigma   		# PixArt-Sigma-XL-2-2K-MS模型(训练用)
    PixArt-alpha/pixart_sigma_sdxlvae_T5_diffusers	# vae模型
    hpcai-tech/OpenSora-VAE-v1.2   		# vae模型
    DeepFloyd/t5-v1_1-xxl      	 		# t5模型
    hpcai-tech/OpenSora-STDiT-v3        # 预训练权重(推理用)
    
  3. 获取对应的预训练模型后,在以下配置文件中将modelvaefrom_pretrained参数设置为本地预训练模型绝对路径。

    configs/opensora-v1-2/inference/sample.py
    configs/opensora-v1-2/train/stage1.py
    configs/opensora-v1-2/train/stage2.py
    configs/opensora-v1-2/train/stage3.py
    
  4. 将下载好的t5模型放在本工程目录下的DeepFloyd目录下,组织结构如下:

    $OpenSora-master
    ├── DeepFloyd
    ├── ├── t5-v1_1-xxl
    ├── ├── ├── config.json
    ├── ├── ├── pytorch_model-00001-of-00002.bin
    ├── ├── ├── ...
    └── ...
    

    将下载好的pixart_sigma_sdxlvae_T5_diffusers模型放在PixArt-alpha目录下(只需要有其中的vae文件夹)

    $OpenSora-master
    ├── PixArt-alpha
    ├── ├── pixart_sigma_sdxlvae_T5_diffusers
    ├── ├── ├── vae
    ├── ├── ├── ├── config.json
    ├── ├── ├── ├── ...
    

快速开始

训练任务

本任务主要以预训练模型为主,展示训练任务,包含单机单卡和单机多卡的训练。

开始训练

  1. 进入解压后的源码包根目录。

    cd /${模型文件夹名称} 
    
  2. 准备训练数据。 按照官网流程,准备对应数据集,获取对应数据集后,在以下配置文件中将datasetdata_path设置为数据集的绝对路径

    configs/opensora-v1-2/train/stage1.py
    configs/opensora-v1-2/train/stage2.py
    configs/opensora-v1-2/train/stage3.py
    
  3. 运行训练脚本。

    用户可以按照自己训练需要进行参数配置,以下给出单卡和多卡的一种训练示例。

    bash test/train_full_1p_opensorav1_2.sh
    # 混合精度BF16,单卡训练,stage1
    
    bash test/train_full_8p_opensorav1_2.sh
    # 混合精度BF16,八卡训练,stage1
    

推理任务

本任务主要以预训练模型为主,展示推理任务,包括单卡在线推理。

开始推理

  1. 进入解压后的源码包根目录。

    cd /${模型文件夹名称} 
    
  2. 运行推理的脚本。

  • 单机单卡推理
    bash test/infer_full_1p_opensorav1_2.sh  # 混精bf16 在线推理
    
  • 推理脚本参数说明如下
    test/infer_full_1p_opensorav1_2.sh
    --batch_size                         //设置batch_size
    --prompt                             //测试用的prompt
    --num_frames                         //生成视频的总帧数
    --img_h                              //生成视频的宽
    --img_w                              //生成视频的高
      
    scripts/inference.py
    config                               //配置文件路径
    --seed                               //随机种子    
    --batch-size                         //设置batch_size
    --prompt-path                        //推理使用的prompt文件路径
    --prompt                             //测试用的prompt
    --num-frames                         //生成视频的总帧数
    --image-size                         //生成视频的分辨率
    --fps                                //生成视频的帧率
    --save-dir                           //输出视频的路径
    --num-sampling-steps                 //推理的采样步数
    --cfg-scale                          //无分类器引导的权重系数
    

公网地址说明

代码涉及公网地址参考 public_address_statement.md

变更说明

变更

2024.04.29:OpenSora1.1 STDiT2 bf16训练和推理任务首次发布。

2024.08.13:OpenSora1.2 STDiT3 bf16训练和推理任务首次发布。

FAQ