已合并
change ascendspeed to mindspeed #282
jializheng创建于 2024年5月8日
change ascendspeed to mindspeed #282
已合并
从refs/pull/282/head合入到master
共 190 个文件变更+2087-2049
| @@ -2,18 +2,18 @@ | |||
| 2 | 2 | ||
| 3 | # 简介 | 3 | # 简介 |
| 4 | 4 | ||
| 5 | -AscendSpeed 是针对华为昇腾设备的大模型加速库。 | 5 | +MindSpeed 是针对华为昇腾设备的大模型加速库。 |
| 6 | 6 | ||
| 7 | 大模型训练是一种非常复杂的过程,涉及到许多技术和挑战,其中大模型训练需要大量的显存资源是一个难题,对计算卡提出了不小的挑战。 | 7 | 大模型训练是一种非常复杂的过程,涉及到许多技术和挑战,其中大模型训练需要大量的显存资源是一个难题,对计算卡提出了不小的挑战。 |
| 8 | 为了在单个计算卡显存资源不足时,可以通过多张计算卡进行计算,业界出现了类似 Megatron、DeepSpeed 等第三方大模型加速库,对模型、输入数据等进行切分并分配到不同的计算卡上,最后再通过集合通信对结果进行汇总。 | 8 | 为了在单个计算卡显存资源不足时,可以通过多张计算卡进行计算,业界出现了类似 Megatron、DeepSpeed 等第三方大模型加速库,对模型、输入数据等进行切分并分配到不同的计算卡上,最后再通过集合通信对结果进行汇总。 |
| 9 | 9 | ||
| 10 | -昇腾提供 AscendSpeed 加速库,使能客户大模型业务快速迁移至昇腾设备,并且支持昇腾专有算法,确保开箱可用。 | 10 | +昇腾提供 MindSpeed 加速库,使能客户大模型业务快速迁移至昇腾设备,并且支持昇腾专有算法,确保开箱可用。 |
| 11 | 11 | ||
| 12 | # 安装 | 12 | # 安装 |
| 13 | 13 | ||
| 14 | ### 1. 安装依赖 | 14 | ### 1. 安装依赖 |
| 15 | 15 | ||
| 16 | -在安装**AscendSpeed**之前,请参考[版本配套表](#版本配套表),安装最新昇腾软件栈:[https://www.hiascend.com/zh/](https://www.hiascend.com/zh/)。 | 16 | +在安装**MindSpeed**之前,请参考[版本配套表](#版本配套表),安装最新昇腾软件栈:[https://www.hiascend.com/zh/](https://www.hiascend.com/zh/)。 |
| 17 | 17 | ||
| 18 | | 依赖软件 | | 18 | | 依赖软件 | |
| 19 | |-----------| | 19 | |-----------| |
| @@ -26,21 +26,13 @@ AscendSpeed 是针对华为昇腾设备的大模型加速库。 | |||
| 26 | | apex | | 26 | | apex | |
| 27 | 27 | ||
| 28 | 28 | ||
| 29 | -### 2. 安装 AscendSpeed | 29 | +### 2. 安装 MindSpeed |
| 30 | 30 | ||
| 31 | -如有旧版本 AscendSpeed 请先卸载,再进行安装操作。 | 31 | +下载源码安装 |
| 32 | - | ||
| 33 | -方式一:从 git 直接安装 | ||
| 34 | 32 | ||
| 35 | ```shell | 33 | ```shell |
| 36 | - pip install git+https://gitee.com/ascend/AscendSpeed.git | 34 | + git clone https://gitee.com/ascend/MindSpeed.git |
| 37 | - ``` | 35 | + pip install -e MindSpeed |
| 38 | - | ||
| 39 | -方式二:下载源码安装 | ||
| 40 | - | ||
| 41 | - ```shell | ||
| 42 | - git clone https://gitee.com/ascend/AscendSpeed.git | ||
| 43 | - pip install -e AscendSpeed | ||
| 44 | ``` | 36 | ``` |
| 45 | 37 | ||
| 46 | ### 3. 获取 Megatron-LM 并指定 commit id | 38 | ### 3. 获取 Megatron-LM 并指定 commit id |
| @@ -56,12 +48,12 @@ AscendSpeed 是针对华为昇腾设备的大模型加速库。 | |||
| 56 | 48 | ||
| 57 | 以 GPT 模型为例: | 49 | 以 GPT 模型为例: |
| 58 | 50 | ||
| 59 | -1. 在 Megatron-LM 目录下修改`pretrain_gpt.py`文件,在`import torch`下新增一行`import ascendspeed.megatron_adaptor` | 51 | +1. 在 Megatron-LM 目录下修改`pretrain_gpt.py`文件,在`import torch`下新增一行`import mindspeed.megatron_adaptor` |
| 60 | 52 | ||
| 61 | ```diff | 53 | ```diff |
| 62 | import os | 54 | import os |
| 63 | import torch | 55 | import torch |
| 64 | - +import ascendspeed.megatron_adaptor | 56 | + +import mindspeed.megatron_adaptor |
| 65 | from torch import Tensor | 57 | from torch import Tensor |
| 66 | from functools import partial | 58 | from functools import partial |
| 67 | from typing import Union | 59 | from typing import Union |
| @@ -132,7 +124,7 @@ AscendSpeed 是针对华为昇腾设备的大模型加速库。 | |||
| 132 | 124 | ||
| 133 | **PyTorch Extension**版本号采用`{PyTorch版本}-{昇腾版本}`命名规则,前者为**PyTorch Extension**匹配的PyTorch版本,后者用于匹配CANN版本,详细匹配如下: | 125 | **PyTorch Extension**版本号采用`{PyTorch版本}-{昇腾版本}`命名规则,前者为**PyTorch Extension**匹配的PyTorch版本,后者用于匹配CANN版本,详细匹配如下: |
| 134 | 126 | ||
| 135 | -| AscendSpeed版本 | PyTorch版本 | Extension版本 |Python版本 | | 127 | +| MindSpeed版本 | PyTorch版本 | Extension版本 |Python版本 | |
| 136 | | ----------------- | ------------- | ------------- | --------------------------------------- | | 128 | | ----------------- | ------------- | ------------- | --------------------------------------- | |
| 137 | | 1.0 | 2.1.0 | 2.1.0.post3 | Python3.8.x, Python3.9.x, Python3.10.x | | 129 | | 1.0 | 2.1.0 | 2.1.0.post3 | Python3.8.x, Python3.9.x, Python3.10.x | |
| 138 | 130 | ||
| @@ -140,4 +132,4 @@ AscendSpeed 是针对华为昇腾设备的大模型加速库。 | |||
| 140 | 132 | ||
| 141 | # 安全声明 | 133 | # 安全声明 |
| 142 | 134 | ||
| 143 | -[AscendSpeed 安全声明](SECURITYNOTE.md) | 135 | +[MindSpeed 安全声明](SECURITYNOTE.md) |
| @@ -1,4 +1,4 @@ | |||
| 1 | -# AscendSpeed 安全声明 | 1 | +# MindSpeed 安全声明 |
| 2 | 2 | ||
| 3 | ## 系统安全加固 | 3 | ## 系统安全加固 |
| 4 | 4 | ||
| @@ -17,35 +17,35 @@ | |||
| 17 | 17 | ||
| 18 | - 建议用户在主机(包括宿主机)及容器中设置运行系统umask值为0027及以上,保障新增文件夹默认最高权限为750,新增文件默认最高权限为640。 | 18 | - 建议用户在主机(包括宿主机)及容器中设置运行系统umask值为0027及以上,保障新增文件夹默认最高权限为750,新增文件默认最高权限为640。 |
| 19 | - 建议用户对训练所需文件、训练过程中保存的文件、用户个人的隐私数据、商业资产等敏感文件做好权限控制等安全措施,例如多用户共享数据集场景下的数据集文件写权限控制等,设定的权限建议参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)进行设置。 | 19 | - 建议用户对训练所需文件、训练过程中保存的文件、用户个人的隐私数据、商业资产等敏感文件做好权限控制等安全措施,例如多用户共享数据集场景下的数据集文件写权限控制等,设定的权限建议参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)进行设置。 |
| 20 | -- AscendSpeed 中各类融合算子通过调用 PyTorch 中的 cpp_extension 特性进行编译,编译结果会默认缓存到 `~/.cache/torch_extensions` 目录下,建议用户根据自身需要,参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)对生成文件做好权限控制。 | 20 | +- MindSpeed 中各类融合算子通过调用 PyTorch 中的 cpp_extension 特性进行编译,编译结果会默认缓存到 `~/.cache/torch_extensions` 目录下,建议用户根据自身需要,参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)对生成文件做好权限控制。 |
| 21 | - 原生 Megatron-LM 以及 PyTorch 框架运行中所生成的文件权限依赖系统设定,如 Megatron-LM 生成的数据集索引文件、torch.save 接口保存的文件等。建议当前执行脚本的用户根据自身需要,对生成文件做好权限控制,设定的权限可参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)进行设置。 | 21 | - 原生 Megatron-LM 以及 PyTorch 框架运行中所生成的文件权限依赖系统设定,如 Megatron-LM 生成的数据集索引文件、torch.save 接口保存的文件等。建议当前执行脚本的用户根据自身需要,对生成文件做好权限控制,设定的权限可参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)进行设置。 |
| 22 | - 运行时 CANN 可能会缓存算子编译文件,存储在运行目录下的`kernel_meta_*`文件夹内,加快后续训练的运行速度,用户可根据需要自行对生成后的相关文件进行权限控制。 | 22 | - 运行时 CANN 可能会缓存算子编译文件,存储在运行目录下的`kernel_meta_*`文件夹内,加快后续训练的运行速度,用户可根据需要自行对生成后的相关文件进行权限控制。 |
| 23 | - 用户安装和使用过程需要做好权限控制,建议参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)文件权限参考进行设置。如需要保存安装/卸载日志,可在安装/卸载命令后面加上参数 `--log <FILE>`, 注意对`<FILE>`文件及目录做好权限管控。 | 23 | - 用户安装和使用过程需要做好权限控制,建议参考[附录A 文件(夹)各场景权限管控推荐最大值](#A-文件(夹)各场景权限管控推荐最大值)文件权限参考进行设置。如需要保存安装/卸载日志,可在安装/卸载命令后面加上参数 `--log <FILE>`, 注意对`<FILE>`文件及目录做好权限管控。 |
| 24 | 24 | ||
| 25 | ## 数据安全声明 | 25 | ## 数据安全声明 |
| 26 | 26 | ||
| 27 | -- AscendSpeed 依赖 CANN 的基础能力实现 AOE 性能调优、算子 dump、日志记录等功能,用户需要关注上述功能生成文件的权限控制。 | 27 | +- MindSpeed 依赖 CANN 的基础能力实现 AOE 性能调优、算子 dump、日志记录等功能,用户需要关注上述功能生成文件的权限控制。 |
| 28 | 28 | ||
| 29 | ## 运行安全声明 | 29 | ## 运行安全声明 |
| 30 | 30 | ||
| 31 | - 建议用户结合运行环境资源状况编写对应训练脚本。若训练脚本与资源状况不匹配,如数据集加载内存大小超出内存容量限制、训练脚本在本地生成数据超过磁盘空间大小等情况,可能引发错误并导致进程意外退出。 | 31 | - 建议用户结合运行环境资源状况编写对应训练脚本。若训练脚本与资源状况不匹配,如数据集加载内存大小超出内存容量限制、训练脚本在本地生成数据超过磁盘空间大小等情况,可能引发错误并导致进程意外退出。 |
| 32 | -- AscendSpeed 在运行异常时会退出进程并打印报错信息,建议根据报错提示定位具体错误原因,包括设定算子同步执行、查看 CANN 日志、解析生成的 Core Dump 文件等方式。 | 32 | +- MindSpeed 在运行异常时会退出进程并打印报错信息,建议根据报错提示定位具体错误原因,包括设定算子同步执行、查看 CANN 日志、解析生成的 Core Dump 文件等方式。 |
| 33 | 33 | ||
| 34 | ## 公网地址声明 | 34 | ## 公网地址声明 |
| 35 | -- AscendSpeed代码中包含公网地址声明如下表所示: | 35 | +- MindSpeed代码中包含公网地址声明如下表所示: |
| 36 | 36 | ||
| 37 | -| 类型 | 开源代码地址 | 文件名 | 公网IP地址/公网URL地址/域名/邮箱地址 | 用途说明 | | 37 | +| 类型 | 开源代码地址 | 文件名 | 公网IP地址/公网URL地址/域名/邮箱地址 | 用途说明 | |
| 38 | -| :------------: |:-------------------------------------------------------------------------------:|:---------------------------------------------------:| :----------------------------------------------------------: | :-------------------------: | | 38 | +| :------------: |:-------------------------------------------------------------------------------:|:------------------------------------:| :----------------------------------------------------------: | :-------------------------: | |
| 39 | -| 开源引入 | https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/moe/sharded_moe.py | AscendSpeed/ascendspeed/moe/gate.py | https://arxiv.org/pdf/2006.16668.pdf | 开源引入TopKGate类实现 | | 39 | +| 开源引入 | https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/moe/sharded_moe.py | MindSpeed/mindspeed/moe/gate.py | https://arxiv.org/pdf/2006.16668.pdf | 开源引入TopKGate类实现 | |
| 40 | -| 开源引入 | https://github.com/tensorflow/mesh/blob/master/mesh_tensorflow/transformer/moe.py | AscendSpeed/ascendspeed/moe/gate.py | https://arxiv.org/pdf/2202.08906.pdf | 开源引入apply_z_loss实现 | | 40 | +| 开源引入 | https://github.com/tensorflow/mesh/blob/master/mesh_tensorflow/transformer/moe.py | MindSpeed/mindspeed/moe/gate.py | https://arxiv.org/pdf/2202.08906.pdf | 开源引入apply_z_loss实现 | |
| 41 | -| 开源引入 | https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/moe/sharded_moe.py | AscendSpeed/ascendspeed/moe/moe_layer.py | https://arxiv.org/pdf/2006.16668.pdf | 开源引入MOELayer类实现 | | 41 | +| 开源引入 | https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/moe/sharded_moe.py | MindSpeed/mindspeed/moe/moe_layer.py | https://arxiv.org/pdf/2006.16668.pdf | 开源引入MOELayer类实现 | |
| 42 | -| 开源引入 | https://github.com/pytorch/pytorch/pull/40762/files | AscendSpeed/ascendspeed/moe/utils.py | https://github.com/pytorch/pytorch/pull/40762/files | 开源引入_AllToAll类实现 | | 42 | +| 开源引入 | https://github.com/pytorch/pytorch/pull/40762/files | MindSpeed/mindspeed/moe/utils.py | https://github.com/pytorch/pytorch/pull/40762/files | 开源引入_AllToAll类实现 | |
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | ## 公开接口声明 | 46 | ## 公开接口声明 |
| 47 | 47 | ||
| 48 | -- AscendSpeed采用python的装饰器,对原生megatron中的部分接口进行patch,使能原生meagtron在昇腾设备使用,AscendSpeed不暴露任何公开接口,用户实际使用时调用原生megatron接口。 | 48 | +- MindSpeed采用python的装饰器,对原生megatron中的部分接口进行patch,使能原生meagtron在昇腾设备使用,MindSpeed不暴露任何公开接口,用户实际使用时调用原生megatron接口。 |
| 49 | 49 | ||
| 50 | ## 通信安全加固 | 50 | ## 通信安全加固 |
| 51 | 51 | ||
| @@ -30,9 +30,9 @@ | |||
| 30 | 30 | ||
| 31 | ## 使用方法 —— 在ModelLink中进行整网训练 | 31 | ## 使用方法 —— 在ModelLink中进行整网训练 |
| 32 | 32 | ||
| 33 | -计算通信并行优化算法通过在训练脚本(AscendSpeed/tests_extend/xxx/xxx.sh)中配置环境变量来进行使能,需要安装ascendspeed。 | 33 | +计算通信并行优化算法通过在训练脚本(MindSpeed/tests_extend/xxx/xxx.sh)中配置环境变量来进行使能,需要安装mindspeed。 |
| 34 | 34 | ||
| 35 | -当前计算通信并行有两种实现方法:python脚本使能、融合算子使能,两者选其一即可。两个方式都需要替换原Megatron框架中的ColumnParallelLinear和RowParallelLinear这两个class的forward函数,替换脚本已经根据AscendSpeed指定Megatron版本进行编码和适配,位于ascendspeed/core/tensor_parallel/lcal_coc/目录下。 | 35 | +当前计算通信并行有两种实现方法:python脚本使能、融合算子使能,两者选其一即可。两个方式都需要替换原Megatron框架中的ColumnParallelLinear和RowParallelLinear这两个class的forward函数,替换脚本已经根据MindSpeed指定Megatron版本进行编码和适配,位于mindspeed/core/tensor_parallel/lcal_coc/目录下。 |
| 36 | 36 | ||
| 37 | 请根据需要选择下列三种场景中的一个进行使用。(注意:计算通信并行融合算子需要安装ATB后才能使用!) | 37 | 请根据需要选择下列三种场景中的一个进行使用。(注意:计算通信并行融合算子需要安装ATB后才能使用!) |
| 38 | 38 | ||
| @@ -63,7 +63,7 @@ export USE_COC_FUSED_KERNEL=1 | |||
| 63 | 63 | ||
| 64 | ## CFG自定义方法 | 64 | ## CFG自定义方法 |
| 65 | 65 | ||
| 66 | -用户可以自定义ascendspeed/core/tensor_parallel/lcal_coc/user_config.py中的coc_cfgs字典,来达到自定义COC的部分配置。 | 66 | +用户可以自定义mindspeed/core/tensor_parallel/lcal_coc/user_config.py中的coc_cfgs字典,来达到自定义COC的部分配置。 |
| 67 | 67 | ||
| 68 | 【只对通过Python脚本使能的计算通信并行实现适用】 | 68 | 【只对通过Python脚本使能的计算通信并行实现适用】 |
| 69 | 'matmul_soc_friendly':是否对输入matmul的张量做transpose/padding操作,使其以NPU亲和的shape进入Matmul算子从而获得一定性能提升,默认为True; | 69 | 'matmul_soc_friendly':是否对输入matmul的张量做transpose/padding操作,使其以NPU亲和的shape进入Matmul算子从而获得一定性能提升,默认为True; |
| @@ -12,9 +12,9 @@ MC2通过融合算子的方式将matmum计算和集合通信操作进行融合 | |||
| 12 | 12 | ||
| 13 | ### 解决思路: | 13 | ### 解决思路: |
| 14 | 14 | ||
| 15 | -AscendSpeed在python脚本侧将原本串行的matmul和all_gather/reduce_scatter操作通过MC2融合算子接口进行了融合。 | 15 | +MindSpeed在python脚本侧将原本串行的matmul和all_gather/reduce_scatter操作通过MC2融合算子接口进行了融合。 |
| 16 | 16 | ||
| 17 | -具体实现参见[link](../../ascendspeed/core/tensor_parallel/ascend_turbo/mc2_linears_seq_parallel.py)。 | 17 | +具体实现参见[link](../../mindspeed/core/tensor_parallel/ascend_turbo/mc2_linears_seq_parallel.py)。 |
| 18 | 18 | ||
| 19 | MC2算子接口参见[link](https://www.hiascend.com/document/detail/zh/Pytorch/60RC1/apiref/apilist/ptaoplist_000449.html)。 | 19 | MC2算子接口参见[link](https://www.hiascend.com/document/detail/zh/Pytorch/60RC1/apiref/apilist/ptaoplist_000449.html)。 |
| 20 | 20 | ||
| @@ -52,5 +52,5 @@ Tried to allocated 3384.00 MiB (NPU 2; 61.22 GiB total capacity; 53.87 GiB alrea | |||
| 52 | 由于该特性在内存充足时倾向于新申请内存,而非将已申请的内存空间碎片化,因此在少量情况下可能和hccl抢占内存,hccl在内存不足时无法通过torch释放额外预留的空闲空间,<br /> | 52 | 由于该特性在内存充足时倾向于新申请内存,而非将已申请的内存空间碎片化,因此在少量情况下可能和hccl抢占内存,hccl在内存不足时无法通过torch释放额外预留的空闲空间,<br /> |
| 53 | 从而报hccl内存不足的错误。此问题可以通过设置torch_npu.npu.set_per_process_memory_fraction接口来设置允许torch占用的内存上限来解决该问题 <br /> | 53 | 从而报hccl内存不足的错误。此问题可以通过设置torch_npu.npu.set_per_process_memory_fraction接口来设置允许torch占用的内存上限来解决该问题 <br /> |
| 54 | **接口设置**:<br /> | 54 | **接口设置**:<br /> |
| 55 | -位置:AscendSpeed/ascendspeed/core/memory/memory_fragmentation/memory_recorder.py <br /> | 55 | +位置:MindSpeed/mindspeed/core/memory/memory_fragmentation/memory_recorder.py <br /> |
| 56 | 添加:torch_npu.npu.set_per_process_memory_fraction(x),其中x为想要限制torch占用内存的最高比例,例如x设置为0.94,表示torch最多占用"单卡内存*0.94"的内存 <br /> | 56 | 添加:torch_npu.npu.set_per_process_memory_fraction(x),其中x为想要限制torch占用内存的最高比例,例如x设置为0.94,表示torch最多占用"单卡内存*0.94"的内存 <br /> |
| @@ -3,7 +3,7 @@ | |||
| 3 | rms_norm常见于LLaMA、LLaMA2、Baichuan等LLM模型中用于归一化,由于torch侧没有提供rms_norm算子的接口,因此在模型中通常是以自定义的形式出现,这种形式的执行效率相对较低。 | 3 | rms_norm常见于LLaMA、LLaMA2、Baichuan等LLM模型中用于归一化,由于torch侧没有提供rms_norm算子的接口,因此在模型中通常是以自定义的形式出现,这种形式的执行效率相对较低。 |
| 4 | 4 | ||
| 5 | ## 解决方法 | 5 | ## 解决方法 |
| 6 | -Ascendspeed对将rms_norm操作合并成一个算子,减少数据传输和临时存储。算子接口见[link](../ops/rms_norm.md)。 | 6 | +MindSpeed对将rms_norm操作合并成一个算子,减少数据传输和临时存储。算子接口见[link](../ops/rms_norm.md)。 |
| 7 | 7 | ||
| 8 | ## 使用场景 | 8 | ## 使用场景 |
| 9 | 模型使用rms_norm作为归一化方式,脚本中设置了`--normalization RMSNorm`。 | 9 | 模型使用rms_norm作为归一化方式,脚本中设置了`--normalization RMSNorm`。 |
| @@ -7,7 +7,7 @@ Rotary Position Embedding(RoPE)是一种大模型文本位置信息编码( | |||
| 7 | 然而,目前torch并没有针对RoPE做特定的实现和优化,在模型侧通常是通过自定义的方式实现,且Rotary Embedding的计算方式较为复杂,实现方式的计算和内存开销需要优化。 | 7 | 然而,目前torch并没有针对RoPE做特定的实现和优化,在模型侧通常是通过自定义的方式实现,且Rotary Embedding的计算方式较为复杂,实现方式的计算和内存开销需要优化。 |
| 8 | 8 | ||
| 9 | ## 解决方案 | 9 | ## 解决方案 |
| 10 | -`torch_npu`侧将Rotary Embedding操作合并成一个算子,减少数据传输和临时储存,优化模型训练性能。AscendSpeed调用`torch_npu`侧接口实现算子融合。 | 10 | +`torch_npu`侧将Rotary Embedding操作合并成一个算子,减少数据传输和临时储存,优化模型训练性能。MindSpeed调用`torch_npu`侧接口实现算子融合。 |
| 11 | 11 | ||
| 12 | 具体算子接口参见`torch_npu`文档[link](https://www.hiascend.com/document/detail/zh/Pytorch/60RC1/apiref/apilist/ptaoplist_000463.html)。 | 12 | 具体算子接口参见`torch_npu`文档[link](https://www.hiascend.com/document/detail/zh/Pytorch/60RC1/apiref/apilist/ptaoplist_000463.html)。 |
| 13 | 13 | ||
| @@ -4,7 +4,7 @@ | |||
| 4 | swiglu常见于LLaMA、LLaMA2、Baichuan等LLM模型中的激活层,由于torch侧没有提供swiglu算子的接口,因此在模型中通常是以自定义的形式出现,这种形式的执行效率相对较低。 | 4 | swiglu常见于LLaMA、LLaMA2、Baichuan等LLM模型中的激活层,由于torch侧没有提供swiglu算子的接口,因此在模型中通常是以自定义的形式出现,这种形式的执行效率相对较低。 |
| 5 | 5 | ||
| 6 | ## 解决方法 | 6 | ## 解决方法 |
| 7 | -Ascendspeed对将swiglu操作合并成一个算子,减少数据传输和临时存储。算子接口见[link](../ops/swiglu.md)。 | 7 | +MindSpeed对将swiglu操作合并成一个算子,减少数据传输和临时存储。算子接口见[link](../ops/swiglu.md)。 |
| 8 | 8 | ||
| 9 | ## 使用场景 | 9 | ## 使用场景 |
| 10 | 模型使用swiglu作为MLP层激活函数,脚本中设置了`--swiglu`。 | 10 | 模型使用swiglu作为MLP层激活函数,脚本中设置了`--swiglu`。 |
| @@ -84,37 +84,40 @@ npu_fusion_attention( | |||
| 84 | -sparse_mode=7或者8时,不支持可选输入pse。 | 84 | -sparse_mode=7或者8时,不支持可选输入pse。 |
| 85 | 85 | ||
| 86 | ## flash_attention_v2 类的调用方式 | 86 | ## flash_attention_v2 类的调用方式 |
| 87 | + | ||
| 87 | ```python | 88 | ```python |
| 88 | import os | 89 | import os |
| 89 | - import torch | 90 | +import torch |
| 90 | - import torch_npu | 91 | +import torch_npu |
| 91 | - import numpy as np | 92 | +import numpy as np |
| 92 | - import math | 93 | +import math |
| 93 | - import ascendspeed.ops.fusion_attention_v2 import npu_fusion_attention | 94 | +import mindspeed.ops.fusion_attention_v2 |
| 94 | - | 95 | +import npu_fusion_attention |
| 95 | - batch_size, head_num, seq_size, head_dim = 1, 32, 2048, 128 | ||
| 96 | - input_layout = "BNSD" | ||
| 97 | - keep_prob = 1.0 | ||
| 98 | - pre_tokens = 65536 | ||
| 99 | - next_tokens = 1 | ||
| 100 | - scale_value = 0.088 | ||
| 101 | - q_scale = 1.0 | ||
| 102 | 96 | ||
| 103 | - input_shape = (batch_size, head_num, seq_size, head_dim) | 97 | +batch_size, head_num, seq_size, head_dim = 1, 32, 2048, 128 |
| 104 | - softmax_shape = (batch_size, head_num, seq_size) | 98 | +input_layout = "BNSD" |
| 105 | - mask_shape = (1, 1, seq_size, seq_size) | 99 | +keep_prob = 1.0 |
| 106 | - dtype = torch.float16 | 100 | +pre_tokens = 65536 |
| 107 | - attention_score_grad = (torch.rand(input_shape).to(dtype) - 0.5) | 101 | +next_tokens = 1 |
| 108 | - query = (torch.rand(input_shape).to(dtype) - 0.5) * 5 | 102 | +scale_value = 0.088 |
| 109 | - key = (torch.rand(input_shape).to(dtype) - 0.5) * 5 | 103 | +q_scale = 1.0 |
| 110 | - value = (torch.rand(input_shape).to(dtype) - 0.5) * 5 | ||
| 111 | - atten_mask = np.tri(seq_size, k=-next_tokens) + np.tri(seq_size, k=-pre_tokens).transpose() | ||
| 112 | - alibi_mask = torch.zeros((batch_size, head_num, seq_size, seq_size)).to(dtype) | ||
| 113 | - atten_mask = torch.from_numpy(atten_mask).to(torch.bool) | ||
| 114 | 104 | ||
| 115 | - // 正向接口案例 | 105 | +input_shape = (batch_size, head_num, seq_size, head_dim) |
| 116 | - result = npu_fusion_attention(query.npu(), key.npu(), value.npu(), atten_mask.npu(), None, scale_value, q_scale, head_num, input_layout, keep_prob, pre_tokens, next_tokens) | 106 | +softmax_shape = (batch_size, head_num, seq_size) |
| 107 | +mask_shape = (1, 1, seq_size, seq_size) | ||
| 108 | +dtype = torch.float16 | ||
| 109 | +attention_score_grad = (torch.rand(input_shape).to(dtype) - 0.5) | ||
| 110 | +query = (torch.rand(input_shape).to(dtype) - 0.5) * 5 | ||
| 111 | +key = (torch.rand(input_shape).to(dtype) - 0.5) * 5 | ||
| 112 | +value = (torch.rand(input_shape).to(dtype) - 0.5) * 5 | ||
| 113 | +atten_mask = np.tri(seq_size, k=-next_tokens) + np.tri(seq_size, k=-pre_tokens).transpose() | ||
| 114 | +alibi_mask = torch.zeros((batch_size, head_num, seq_size, seq_size)).to(dtype) | ||
| 115 | +atten_mask = torch.from_numpy(atten_mask).to(torch.bool) | ||
| 117 | 116 | ||
| 118 | - // 反向接口案例 | 117 | +// 正向接口案例 |
| 119 | - result.backward(dx) | 118 | +result = npu_fusion_attention(query.npu(), key.npu(), value.npu(), atten_mask.npu(), None, scale_value, q_scale, |
| 119 | + head_num, input_layout, keep_prob, pre_tokens, next_tokens) | ||
| 120 | + | ||
| 121 | +// 反向接口案例 | ||
| 122 | +result.backward(dx) | ||
| 120 | ``` | 123 | ``` |
| @@ -27,30 +27,30 @@ npu_gmm(x, weight, bias=None, group_list=None, group_type=-1) | |||
| 27 | - grad_bias:当前不支持,默认为none | 27 | - grad_bias:当前不支持,默认为none |
| 28 | 28 | ||
| 29 | ## gmm 类的调用方式 | 29 | ## gmm 类的调用方式 |
| 30 | + | ||
| 30 | ```python | 31 | ```python |
| 31 | import os | 32 | import os |
| 32 | - import torch | 33 | +import torch |
| 33 | - import torch_npu | 34 | +import torch_npu |
| 34 | - import numpy as np | 35 | +import numpy as np |
| 35 | - import math | 36 | +import math |
| 36 | - from ascendspeed.ops import gmm | 37 | +from mindspeed.ops import gmm |
| 37 | - | ||
| 38 | - num_expert, seq_len, hidden_dim = 8, 32, 256 | ||
| 39 | - group_list = [1, 3, 6, 10, 15, 21, 28, 32] | ||
| 40 | - group_type = 0 | ||
| 41 | 38 | ||
| 42 | - x_shape = (seq_len, hidden_dim) | 39 | +num_expert, seq_len, hidden_dim = 8, 32, 256 |
| 43 | - weight_shape = (num_expert, hidden_dim, seq_len) | 40 | +group_list = [1, 3, 6, 10, 15, 21, 28, 32] |
| 44 | - dtype = torch.float16 | 41 | +group_type = 0 |
| 45 | - x = (torch.rand(x_shape).to(dtype) - 0.5) | ||
| 46 | - weight = (torch.rand(weight_shape).to(dtype) - 0.5) | ||
| 47 | 42 | ||
| 48 | - // 正向接口案例 | 43 | +x_shape = (seq_len, hidden_dim) |
| 49 | - x.requires_grad = True | 44 | +weight_shape = (num_expert, hidden_dim, seq_len) |
| 50 | - weight.requires_grad = True | 45 | +dtype = torch.float16 |
| 51 | - result = gmm.npu_gmm(x.npu(), weight.npu(), bias=None, group_list=group_list, group_type=group_type) | 46 | +x = (torch.rand(x_shape).to(dtype) - 0.5) |
| 52 | - | 47 | +weight = (torch.rand(weight_shape).to(dtype) - 0.5) |
| 53 | 48 | ||
| 54 | - // 反向接口案例 | 49 | +// 正向接口案例 |
| 55 | - result.backward(torch.ones(result.shape).npu()) | 50 | +x.requires_grad = True |
| 51 | +weight.requires_grad = True | ||
| 52 | +result = gmm.npu_gmm(x.npu(), weight.npu(), bias=None, group_list=group_list, group_type=group_type) | ||
| 53 | + | ||
| 54 | +// 反向接口案例 | ||
| 55 | +result.backward(torch.ones(result.shape).npu()) | ||
| 56 | ``` | 56 | ``` |
| @@ -69,63 +69,67 @@ $$ | |||
| 69 | - 输入中须包含通信域hcomm字符串,它需要从torch.distributed包中的接口获取。 | 69 | - 输入中须包含通信域hcomm字符串,它需要从torch.distributed包中的接口获取。 |
| 70 | 70 | ||
| 71 | ## grouped_mat_mul_all_reduce 类的调用方式 | 71 | ## grouped_mat_mul_all_reduce 类的调用方式 |
| 72 | + | ||
| 72 | ```python | 73 | ```python |
| 73 | import os | 74 | import os |
| 74 | - import torch | 75 | +import torch |
| 75 | - import torch_npu | 76 | +import torch_npu |
| 76 | - import torch.multiprocessing as mp | 77 | +import torch.multiprocessing as mp |
| 77 | - import torch.distributed as dist | 78 | +import torch.distributed as dist |
| 78 | - import numpy as np | 79 | +import numpy as np |
| 79 | - import math | 80 | +import math |
| 80 | - from ascendspeed.ops.grouped_mat_mul_all_reduce import ascend_grouped_mat_mul_all_reduce | 81 | +from mindspeed.ops.grouped_mat_mul_all_reduce import ascend_grouped_mat_mul_all_reduce |
| 81 | - | ||
| 82 | - | ||
| 83 | - def get_hcomm_info(world_size, rank): | ||
| 84 | - dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method='tcp://127.0.0.1:5001') | ||
| 85 | - print(f'device_{rank} init_process_group success.') | ||
| 86 | - if dist.is_available(): | ||
| 87 | - from torch.distributed.distributed_c10d import _get_default_group | ||
| 88 | - default_pg = _get_default_group() | ||
| 89 | - if torch.__version__ > '2.0.1': | ||
| 90 | - hcomm_info = default_pg._get_backend(torch.device('npu')).get_hccl_comm_name(rank) | ||
| 91 | - else: | ||
| 92 | - hcomm_info = default_pg.get_hccl_comm_name(rank) | ||
| 93 | - print(f'device_{rank} get_hccl_comm_name success.') | ||
| 94 | - return dist, hcomm_info | ||
| 95 | 82 | ||
| 96 | - def run(rank, n_device): | ||
| 97 | - torch_npu.npu.set_device(rank) | ||
| 98 | - dist, hcomm_info = get_hcomm_info(n_device, rank) | ||
| 99 | 83 | ||
| 100 | - x1 = torch.randn(32, 256, dtype=torch.float16) | 84 | +def get_hcomm_info(world_size, rank): |
| 101 | - x1_npu = x1.npu() | 85 | + dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method='tcp://127.0.0.1:5001') |
| 102 | - w1 = torch.randn(256, 32, dtype=torch.float16) | 86 | + print(f'device_{rank} init_process_group success.') |
| 103 | - w1_npu = w1.npu() | 87 | + if dist.is_available(): |
| 104 | - | 88 | + from torch.distributed.distributed_c10d import _get_default_group |
| 105 | - x2 = torch.randn(64, 128, dtype=torch.float16) | 89 | + default_pg = _get_default_group() |
| 106 | - x2_npu = x2.npu() | 90 | + if torch.__version__ > '2.0.1': |
| 107 | - w2 = torch.randn(128, 64, dtype=torch.float16) | 91 | + hcomm_info = default_pg._get_backend(torch.device('npu')).get_hccl_comm_name(rank) |
| 108 | - w2_npu = w2.npu() | 92 | + else: |
| 109 | - | 93 | + hcomm_info = default_pg.get_hccl_comm_name(rank) |
| 110 | - group_list = None | 94 | + print(f'device_{rank} get_hccl_comm_name success.') |
| 111 | - split_item = 0 | 95 | + return dist, hcomm_info |
| 112 | - hccl_group = hcomm_info | ||
| 113 | - reduce_op = "sum" | ||
| 114 | - comm_turn = 0 | ||
| 115 | 96 | ||
| 116 | - # 正向接口案例 | ||
| 117 | - x1_npu.requires_grad = False | ||
| 118 | - x2_npu.requires_grad = False | ||
| 119 | - w1_npu.requires_grad = False | ||
| 120 | - w2_npu.requires_grad = False | ||
| 121 | - y_npu = ascend_grouped_mat_mul_all_reduce([x1_npu, x2_npu],[w1_npu, w2_npu], hccl_group, bias=[], group_list=group_list, split_item=split_item, reduce_op=reduce_op, comm_turn=comm_turn) | ||
| 122 | - if rank == 0: | ||
| 123 | - for i, y in enumerate(y_npu): | ||
| 124 | - y.cpu().numpy().tofile(f"./y_{i}.bin") | ||
| 125 | - | ||
| 126 | 97 | ||
| 127 | - if __name__ == '__main__': | 98 | +def run(rank, n_device): |
| 128 | - n_device = 2 | 99 | + torch_npu.npu.set_device(rank) |
| 129 | - mp.spawn(run, args=(n_device,), nprocs=n_device) | 100 | + dist, hcomm_info = get_hcomm_info(n_device, rank) |
| 130 | - | 101 | + |
| 102 | + x1 = torch.randn(32, 256, dtype=torch.float16) | ||
| 103 | + x1_npu = x1.npu() | ||
| 104 | + w1 = torch.randn(256, 32, dtype=torch.float16) | ||
| 105 | + w1_npu = w1.npu() | ||
| 106 | + | ||
| 107 | + x2 = torch.randn(64, 128, dtype=torch.float16) | ||
| 108 | + x2_npu = x2.npu() | ||
| 109 | + w2 = torch.randn(128, 64, dtype=torch.float16) | ||
| 110 | + w2_npu = w2.npu() | ||
| 111 | + | ||
| 112 | + group_list = None | ||
| 113 | + split_item = 0 | ||
| 114 | + hccl_group = hcomm_info | ||
| 115 | + reduce_op = "sum" | ||
| 116 | + comm_turn = 0 | ||
| 117 | + | ||
| 118 | + # 正向接口案例 | ||
| 119 | + x1_npu.requires_grad = False | ||
| 120 | + x2_npu.requires_grad = False | ||
| 121 | + w1_npu.requires_grad = False | ||
| 122 | + w2_npu.requires_grad = False | ||
| 123 | + y_npu = ascend_grouped_mat_mul_all_reduce([x1_npu, x2_npu], [w1_npu, w2_npu], hccl_group, bias=[], | ||
| 124 | + group_list=group_list, split_item=split_item, reduce_op=reduce_op, | ||
| 125 | + comm_turn=comm_turn) | ||
| 126 | + if rank == 0: | ||
| 127 | + for i, y in enumerate(y_npu): | ||
| 128 | + y.cpu().numpy().tofile(f"./y_{i}.bin") | ||
| 129 | + | ||
| 130 | + | ||
| 131 | +if __name__ == '__main__': | ||
| 132 | + n_device = 2 | ||
| 133 | + mp.spawn(run, args=(n_device,), nprocs=n_device) | ||
| 134 | + | ||
| 131 | ``` | 135 | ``` |
| @@ -1,8 +1,10 @@ | |||
| 1 | # LCAL_COC对外接口 | 1 | # LCAL_COC对外接口 |
| 2 | 2 | ||
| 3 | ## MATMUL_ALL_REDUCE接口 | 3 | ## MATMUL_ALL_REDUCE接口 |
| 4 | + | ||
| 4 | ```python | 5 | ```python |
| 5 | -from ascendspeed.ops.lcal_functional import coc_ops | 6 | +from mindspeed.ops.lcal_functional import coc_ops |
| 7 | + | ||
| 6 | coc_ops.matmul_all_reduce(input1, input2, output, bias) | 8 | coc_ops.matmul_all_reduce(input1, input2, output, bias) |
| 7 | ``` | 9 | ``` |
| 8 | 10 | ||
| @@ -24,10 +26,11 @@ coc_ops.matmul_all_reduce(input1, input2, output, bias) | |||
| 24 | - 无 | 26 | - 无 |
| 25 | 27 | ||
| 26 | ### 使用案例 | 28 | ### 使用案例 |
| 29 | + | ||
| 27 | ```python | 30 | ```python |
| 28 | import torch | 31 | import torch |
| 29 | import torch_npu | 32 | import torch_npu |
| 30 | -from ascendspeed.ops.lcal_functional import coc_ops | 33 | +from mindspeed.ops.lcal_functional import coc_ops |
| 31 | 34 | ||
| 32 | m, k, n = 2048, 4096, 8192 | 35 | m, k, n = 2048, 4096, 8192 |
| 33 | dtype = torch.float16 | 36 | dtype = torch.float16 |
| @@ -40,8 +43,10 @@ coc_ops.matmul_all_reduce(input1, input2, output, bias) | |||
| 40 | 43 | ||
| 41 | 44 | ||
| 42 | ## ALL_GATHER_MATMUL接口 | 45 | ## ALL_GATHER_MATMUL接口 |
| 46 | + | ||
| 43 | ```python | 47 | ```python |
| 44 | -from ascendspeed.ops.lcal_functional import coc_ops | 48 | +from mindspeed.ops.lcal_functional import coc_ops |
| 49 | + | ||
| 45 | coc_ops.all_gather_matmul(input1, input2, output, bias) | 50 | coc_ops.all_gather_matmul(input1, input2, output, bias) |
| 46 | ```` | 51 | ```` |
| 47 | 52 | ||
| @@ -63,15 +68,16 @@ coc_ops.all_gather_matmul(input1, input2, output, bias) | |||
| 63 | - 无 | 68 | - 无 |
| 64 | 69 | ||
| 65 | ### 使用案例 | 70 | ### 使用案例 |
| 71 | + | ||
| 66 | ```python | 72 | ```python |
| 67 | import torch | 73 | import torch |
| 68 | import torch_npu | 74 | import torch_npu |
| 69 | -from ascendspeed.ops.lcal_functional import coc_ops | 75 | +from mindspeed.ops.lcal_functional import coc_ops |
| 70 | 76 | ||
| 71 | m, k, n = 2048, 4096, 8192 | 77 | m, k, n = 2048, 4096, 8192 |
| 72 | world_size = 8 | 78 | world_size = 8 |
| 73 | dtype = torch.float16 | 79 | dtype = torch.float16 |
| 74 | -input1 = torch.rand(m // world_size, k, dtype, device=torch.npu.current_device()) | 80 | +input1 = torch.rand(m // world_size, k, dtype, device=torch.npu.current_device()) |
| 75 | input2 = torch.rand(k, n, dtype, device=torch.npu.current_device()) | 81 | input2 = torch.rand(k, n, dtype, device=torch.npu.current_device()) |
| 76 | bias = torch.rand(1, n, dtype, device=torch.npu.current_device()) | 82 | bias = torch.rand(1, n, dtype, device=torch.npu.current_device()) |
| 77 | output = torch.zeros(m, n, dtype, device=torch.npu.current_device()) | 83 | output = torch.zeros(m, n, dtype, device=torch.npu.current_device()) |
| @@ -80,8 +86,10 @@ coc_ops.all_gather_matmul(input1, input2, output, bias) | |||
| 80 | 86 | ||
| 81 | 87 | ||
| 82 | ## ALL_GATHER_MATMUL_V2接口 | 88 | ## ALL_GATHER_MATMUL_V2接口 |
| 89 | + | ||
| 83 | ```python | 90 | ```python |
| 84 | -from ascendspeed.ops.lcal_functional import coc_ops | 91 | +from mindspeed.ops.lcal_functional import coc_ops |
| 92 | + | ||
| 85 | coc_ops.all_gather_matmul_v2(input1, input2, output, comm_output, bias) | 93 | coc_ops.all_gather_matmul_v2(input1, input2, output, comm_output, bias) |
| 86 | ``` | 94 | ``` |
| 87 | 95 | ||
| @@ -104,10 +112,11 @@ coc_ops.all_gather_matmul_v2(input1, input2, output, comm_output, bias) | |||
| 104 | - 无 | 112 | - 无 |
| 105 | 113 | ||
| 106 | ### 使用案例 | 114 | ### 使用案例 |
| 115 | + | ||
| 107 | ```python | 116 | ```python |
| 108 | import torch | 117 | import torch |
| 109 | import torch_npu | 118 | import torch_npu |
| 110 | -from ascendspeed.ops.lcal_functional import coc_ops | 119 | +from mindspeed.ops.lcal_functional import coc_ops |
| 111 | 120 | ||
| 112 | m, k, n = 2048, 4096, 8192 | 121 | m, k, n = 2048, 4096, 8192 |
| 113 | world_size = 8 | 122 | world_size = 8 |
| @@ -116,13 +125,15 @@ input1 = torch.rand(m // world_size, k, dtype, device=torch.npu.current_device() | |||
| 116 | input2 = torch.rand(k, n, dtype, device=torch.npu.current_device()) | 125 | input2 = torch.rand(k, n, dtype, device=torch.npu.current_device()) |
| 117 | bias = torch.rand(1, n, dtype, device=torch.npu.current_device()) | 126 | bias = torch.rand(1, n, dtype, device=torch.npu.current_device()) |
| 118 | output = torch.zeros(m, n, dtype, device=torch.npu.current_device()) | 127 | output = torch.zeros(m, n, dtype, device=torch.npu.current_device()) |
| 119 | -comm_output= torch.zeros(m, k, dtype, device=torch.npu.current_device()) | 128 | +comm_output = torch.zeros(m, k, dtype, device=torch.npu.current_device()) |
| 120 | coc_ops.all_gather_matmul_v2(input1, input2, output, comm_output, bias) | 129 | coc_ops.all_gather_matmul_v2(input1, input2, output, comm_output, bias) |
| 121 | ``` | 130 | ``` |
| 122 | 131 | ||
| 123 | ## MATMUL_REDUCE_SCATTER接口 | 132 | ## MATMUL_REDUCE_SCATTER接口 |
| 133 | + | ||
| 124 | ```python | 134 | ```python |
| 125 | -from ascendspeed.ops.lcal_functional import coc_ops | 135 | +from mindspeed.ops.lcal_functional import coc_ops |
| 136 | + | ||
| 126 | coc_ops.matmul_reduce_scatter(input1, input2, output, bias) | 137 | coc_ops.matmul_reduce_scatter(input1, input2, output, bias) |
| 127 | ```` | 138 | ```` |
| 128 | 139 | ||
| @@ -144,10 +155,11 @@ coc_ops.matmul_reduce_scatter(input1, input2, output, bias) | |||
| 144 | - 无 | 155 | - 无 |
| 145 | 156 | ||
| 146 | ### 使用方法 | 157 | ### 使用方法 |
| 158 | + | ||
| 147 | ```python | 159 | ```python |
| 148 | import torch | 160 | import torch |
| 149 | import torch_npu | 161 | import torch_npu |
| 150 | -from ascendspeed.ops.lcal_functional import coc_ops | 162 | +from mindspeed.ops.lcal_functional import coc_ops |
| 151 | 163 | ||
| 152 | m, k, n = 2048, 4096, 8192 | 164 | m, k, n = 2048, 4096, 8192 |
| 153 | world_size = 8 | 165 | world_size = 8 |
| @@ -161,8 +173,10 @@ coc_ops.matmul_reduce_scatter(input1, input2, output, bias) | |||
| 161 | 173 | ||
| 162 | 174 | ||
| 163 | ## PURE_MATMUL接口 | 175 | ## PURE_MATMUL接口 |
| 176 | + | ||
| 164 | ```python | 177 | ```python |
| 165 | -from ascendspeed.ops.lcal_functional import coc_ops | 178 | +from mindspeed.ops.lcal_functional import coc_ops |
| 179 | + | ||
| 166 | coc_ops.pure_matmul(input1, input2, output, bias) | 180 | coc_ops.pure_matmul(input1, input2, output, bias) |
| 167 | ```` | 181 | ```` |
| 168 | 182 | ||
| @@ -184,10 +198,11 @@ coc_ops.pure_matmul(input1, input2, output, bias) | |||
| 184 | - 无 | 198 | - 无 |
| 185 | 199 | ||
| 186 | ### 使用方法 | 200 | ### 使用方法 |
| 201 | + | ||
| 187 | ```python | 202 | ```python |
| 188 | import torch | 203 | import torch |
| 189 | import torch_npu | 204 | import torch_npu |
| 190 | -from ascendspeed.ops.lcal_functional import coc_ops | 205 | +from mindspeed.ops.lcal_functional import coc_ops |
| 191 | 206 | ||
| 192 | m, k, n = 2048, 4096, 8192 | 207 | m, k, n = 2048, 4096, 8192 |
| 193 | world_size = 8 | 208 | world_size = 8 |
| @@ -32,7 +32,7 @@ norm_result = RMSNorm(Dropout(x0 x rowscale x layerscale) + residual) | |||
| 32 | 32 | ||
| 33 | *** | 33 | *** |
| 34 | 34 | ||
| 35 | -ascendspeed_te_ops.npu_dropout_add_layer_norm(x0, weight, residual=None, bias=None, rowscale=None, layerscale=None, p=0., eps=1e-5, prenorm=False, residual_in_fp32=False, is_rms_norm=False, return_dropout_mask=False) | 35 | +mindspeed_te_ops.npu_dropout_add_layer_norm(x0, weight, residual=None, bias=None, rowscale=None, layerscale=None, p=0., eps=1e-5, prenorm=False, residual_in_fp32=False, is_rms_norm=False, return_dropout_mask=False) |
| 36 | 36 | ||
| 37 | ``` | 37 | ``` |
| 38 | 计算逻辑: | 38 | 计算逻辑: |
| @@ -84,7 +84,7 @@ bf16 bf16 bf16 bf16 | |||
| 84 | ```python | 84 | ```python |
| 85 | import torch | 85 | import torch |
| 86 | import torch_npu | 86 | import torch_npu |
| 87 | -from ascendspeed.te.ops.dropout_add_layer_norm import NPUDropoutAddLayerNorm | 87 | +from mindspeed.te.ops.dropout_add_layer_norm import NPUDropoutAddLayerNorm |
| 88 | 88 | ||
| 89 | batch_size = 8 | 89 | batch_size = 8 |
| 90 | seqlen = 512 | 90 | seqlen = 512 |
| @@ -92,7 +92,7 @@ hidden_size = 192 | |||
| 92 | 92 | ||
| 93 | # 正向接口案例 | 93 | # 正向接口案例 |
| 94 | model = NPUDropoutAddLayerNorm(hidden_size, p=0.37, eps=1e-5, | 94 | model = NPUDropoutAddLayerNorm(hidden_size, p=0.37, eps=1e-5, |
| 95 | - residual_in_fp32=True, dtype=torch.float).npu() | 95 | + residual_in_fp32=True, dtype=torch.float).npu() |
| 96 | torch.nn.init.normal_(model.weight) | 96 | torch.nn.init.normal_(model.weight) |
| 97 | torch.nn.init.normal_(model.bias) | 97 | torch.nn.init.normal_(model.bias) |
| 98 | 98 | ||
| @@ -118,7 +118,7 @@ bias_grad = model.bias.grad | |||
| 118 | ```python | 118 | ```python |
| 119 | import torch | 119 | import torch |
| 120 | import torch_npu | 120 | import torch_npu |
| 121 | -from ascendspeed.te.ops.dropout_add_rms_norm import NPUDropoutAddRMSNorm | 121 | +from mindspeed.te.ops.dropout_add_rms_norm import NPUDropoutAddRMSNorm |
| 122 | 122 | ||
| 123 | batch_size = 8 | 123 | batch_size = 8 |
| 124 | seqlen = 512 | 124 | seqlen = 512 |
| @@ -126,7 +126,7 @@ hidden_size = 192 | |||
| 126 | 126 | ||
| 127 | # 正向接口案例 | 127 | # 正向接口案例 |
| 128 | model = NPUDropoutAddRMSNorm(hidden_size, p=0.37, eps=1e-5, | 128 | model = NPUDropoutAddRMSNorm(hidden_size, p=0.37, eps=1e-5, |
| 129 | - residual_in_fp32=True, dtype=torch.float).npu() | 129 | + residual_in_fp32=True, dtype=torch.float).npu() |
| 130 | torch.nn.init.normal_(model.weight) | 130 | torch.nn.init.normal_(model.weight) |
| 131 | 131 | ||
| 132 | x0 = torch.randn(batch_size, seqlen, hidden_size, dtype=torch.float, requires_grad=True) | 132 | x0 = torch.randn(batch_size, seqlen, hidden_size, dtype=torch.float, requires_grad=True) |
| @@ -148,7 +148,7 @@ weight_grad = model.weight.grad | |||
| 148 | ```python | 148 | ```python |
| 149 | import torch | 149 | import torch |
| 150 | import torch_npu | 150 | import torch_npu |
| 151 | -import ascendspeed_te_ops | 151 | +import mindspeed_te_ops |
| 152 | 152 | ||
| 153 | batch_size = 8 | 153 | batch_size = 8 |
| 154 | seqlen = 512 | 154 | seqlen = 512 |
| @@ -164,7 +164,7 @@ survival_rate = 0.87 | |||
| 164 | rowscale = rowscale.bernoulli_(survival_rate) / survival_rate | 164 | rowscale = rowscale.bernoulli_(survival_rate) / survival_rate |
| 165 | layerscale = torch.randn(hidden_size, dtype=torch.float, requires_grad=True) | 165 | layerscale = torch.randn(hidden_size, dtype=torch.float, requires_grad=True) |
| 166 | 166 | ||
| 167 | -norm_result, pre_norm_result, mask_result = ascendspeed_te_ops.npu_dropout_add_layer_norm( | 167 | +norm_result, pre_norm_result, mask_result = mindspeed_te_ops.npu_dropout_add_layer_norm( |
| 168 | x0.npu(), | 168 | x0.npu(), |
| 169 | weight.npu(), | 169 | weight.npu(), |
| 170 | residual.npu(), | 170 | residual.npu(), |
| @@ -195,9 +195,9 @@ layerscale_grad = layerscale.grad | |||
| 195 | ```python | 195 | ```python |
| 196 | import torch | 196 | import torch |
| 197 | import torch_npu | 197 | import torch_npu |
| 198 | -import ascendspeed_te_ops | 198 | +import mindspeed_te_ops |
| 199 | -from ascendspeed_te_ops import npu_dropout_add_layer_norm | 199 | +from mindspeed_te_ops import npu_dropout_add_layer_norm |
| 200 | -from ascendspeed.te.ops.dropout_add_layer_norm import NPUDropoutAddLayerNorm | 200 | +from mindspeed.te.ops.dropout_add_layer_norm import NPUDropoutAddLayerNorm |
| 201 | 201 | ||
| 202 | batch_size = 8 | 202 | batch_size = 8 |
| 203 | seqlen = 512 | 203 | seqlen = 512 |
| @@ -214,7 +214,7 @@ layerscale = torch.randn(hidden_size, dtype=torch.float, requires_grad=True) | |||
| 214 | layer_norm_cls = NPUDropoutAddLayerNorm | 214 | layer_norm_cls = NPUDropoutAddLayerNorm |
| 215 | layer_norm_func = npu_dropout_add_layer_norm | 215 | layer_norm_func = npu_dropout_add_layer_norm |
| 216 | model = layer_norm_cls(hidden_size, prenorm=True, p=0.37, eps=1e-5, | 216 | model = layer_norm_cls(hidden_size, prenorm=True, p=0.37, eps=1e-5, |
| 217 | - residual_in_fp32=True, dtype=torch.float).npu() | 217 | + residual_in_fp32=True, dtype=torch.float).npu() |
| 218 | 218 | ||
| 219 | torch.nn.init.normal_(model.weight) | 219 | torch.nn.init.normal_(model.weight) |
| 220 | torch.nn.init.normal_(model.bias) | 220 | torch.nn.init.normal_(model.bias) |
| @@ -229,8 +229,8 @@ norm_result, pre_norm_result, mask_result = layer_norm_func( | |||
| 229 | model.eps, | 229 | model.eps, |
| 230 | model.prenorm, | 230 | model.prenorm, |
| 231 | model.residual_in_fp32, | 231 | model.residual_in_fp32, |
| 232 | - False, # is_rms_norm | 232 | + False, # is_rms_norm |
| 233 | - True, # return_dropout_mask | 233 | + True, # return_dropout_mask |
| 234 | ) | 234 | ) |
| 235 | 235 | ||
| 236 | # 反向接口案例 | 236 | # 反向接口案例 |
| @@ -98,16 +98,19 @@ $$ | |||
| 98 | - 伪量化场景下,``antiquant_group_size`` 取值满足取值范围``[32, min(k-1, INT_MAX)]``且为32倍数。 | 98 | - 伪量化场景下,``antiquant_group_size`` 取值满足取值范围``[32, min(k-1, INT_MAX)]``且为32倍数。 |
| 99 | 99 | ||
| 100 | ## npu_mm_all_redcue_add_rms_norm 接口的调用方式 | 100 | ## npu_mm_all_redcue_add_rms_norm 接口的调用方式 |
| 101 | + | ||
| 101 | ```python | 102 | ```python |
| 102 | import torch | 103 | import torch |
| 103 | import torch_npu | 104 | import torch_npu |
| 104 | import torch.distributed as dist | 105 | import torch.distributed as dist |
| 105 | import torch.multiprocessing as mp | 106 | import torch.multiprocessing as mp |
| 106 | -from ascendspeed.ops.npu_mm_all_reduce_add_rms_norm import npu_mm_all_reduce_add_rms_norm | 107 | +from mindspeed.ops.npu_mm_all_reduce_add_rms_norm import npu_mm_all_reduce_add_rms_norm |
| 107 | 108 | ||
| 108 | -def run_mm_all_reduce_add_rms_norm(rank, world_size, master_ip, master_port, x1_shape, x2_shape, residual_shape, gamma_shape, dtype): | 109 | + |
| 110 | +def run_mm_all_reduce_add_rms_norm(rank, world_size, master_ip, master_port, x1_shape, x2_shape, residual_shape, | ||
| 111 | + gamma_shape, dtype): | ||
| 109 | torch_npu.npu.set_device(rank) | 112 | torch_npu.npu.set_device(rank) |
| 110 | - init_method = 'tcp://' + master_ip +':' + master_port | 113 | + init_method = 'tcp://' + master_ip + ':' + master_port |
| 111 | dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method=init_method) | 114 | dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method=init_method) |
| 112 | from torch.distributed.distributed_c10d import _get_default_group | 115 | from torch.distributed.distributed_c10d import _get_default_group |
| 113 | default_pg = _get_default_group() | 116 | default_pg = _get_default_group() |
| @@ -121,10 +124,12 @@ def run_mm_all_reduce_add_rms_norm(rank, world_size, master_ip, master_port, x1_ | |||
| 121 | residual = torch.randn(residual_shape, dtype=dtype).npu() | 124 | residual = torch.randn(residual_shape, dtype=dtype).npu() |
| 122 | gamma = torch.randn(gamma_shape, dtype=dtype).npu() | 125 | gamma = torch.randn(gamma_shape, dtype=dtype).npu() |
| 123 | epsilon = 0.000001 | 126 | epsilon = 0.000001 |
| 124 | - y, norm_out = npu_mm_all_reduce_add_rms_norm(x1=x1, x2=x2, residual=residual, gamma=gamma, hcom=hcom_info, reduce_op='sum', epsilon=epsilon) | 127 | + y, norm_out = npu_mm_all_reduce_add_rms_norm(x1=x1, x2=x2, residual=residual, gamma=gamma, hcom=hcom_info, |
| 128 | + reduce_op='sum', epsilon=epsilon) | ||
| 125 | print("y:", y) | 129 | print("y:", y) |
| 126 | print("norm_out:", norm_out) | 130 | print("norm_out:", norm_out) |
| 127 | 131 | ||
| 132 | + | ||
| 128 | if __name__ == "__main__": | 133 | if __name__ == "__main__": |
| 129 | worksize = 8 | 134 | worksize = 8 |
| 130 | master_ip = "127.0.0.1" | 135 | master_ip = "127.0.0.1" |
| @@ -136,5 +141,7 @@ if __name__ == "__main__": | |||
| 136 | gamma_shape = (n) | 141 | gamma_shape = (n) |
| 137 | dtype = torch.float16 | 142 | dtype = torch.float16 |
| 138 | 143 | ||
| 139 | - mp.spawn(run_mm_all_reduce_add_rms_norm, args=(worksize, master_ip, master_port, x1_shape, x2_shape, residual_shape, gamma_shape, dtype), nprocs=worksize) | 144 | + mp.spawn(run_mm_all_reduce_add_rms_norm, |
| 145 | + args=(worksize, master_ip, master_port, x1_shape, x2_shape, residual_shape, gamma_shape, dtype), | ||
| 146 | + nprocs=worksize) | ||
| 140 | ``` | 147 | ``` |
| @@ -98,16 +98,19 @@ $$ | |||
| 98 | - 伪量化场景下,``antiquant_group_size`` 取值满足取值范围``[32, min(k-1, INT_MAX)]``且为32倍数。 | 98 | - 伪量化场景下,``antiquant_group_size`` 取值满足取值范围``[32, min(k-1, INT_MAX)]``且为32倍数。 |
| 99 | 99 | ||
| 100 | ## npu_mm_all_redcue_add_rms_norm 接口的调用方式 | 100 | ## npu_mm_all_redcue_add_rms_norm 接口的调用方式 |
| 101 | + | ||
| 101 | ```python | 102 | ```python |
| 102 | import torch | 103 | import torch |
| 103 | import torch_npu | 104 | import torch_npu |
| 104 | import torch.distributed as dist | 105 | import torch.distributed as dist |
| 105 | import torch.multiprocessing as mp | 106 | import torch.multiprocessing as mp |
| 106 | -from ascendspeed.ops.npu_mm_all_reduce_add_rms_norm_ import npu_mm_all_reduce_add_rms_norm_ | 107 | +from mindspeed.ops.npu_mm_all_reduce_add_rms_norm_ import npu_mm_all_reduce_add_rms_norm_ |
| 107 | 108 | ||
| 108 | -def run_mm_all_reduce_add_rms_norm(rank, world_size, master_ip, master_port, x1_shape, x2_shape, residual_shape, gamma_shape, dtype): | 109 | + |
| 110 | +def run_mm_all_reduce_add_rms_norm(rank, world_size, master_ip, master_port, x1_shape, x2_shape, residual_shape, | ||
| 111 | + gamma_shape, dtype): | ||
| 109 | torch_npu.npu.set_device(rank) | 112 | torch_npu.npu.set_device(rank) |
| 110 | - init_method = 'tcp://' + master_ip +':' + master_port | 113 | + init_method = 'tcp://' + master_ip + ':' + master_port |
| 111 | dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method=init_method) | 114 | dist.init_process_group(backend='hccl', rank=rank, world_size=world_size, init_method=init_method) |
| 112 | from torch.distributed.distributed_c10d import _get_default_group | 115 | from torch.distributed.distributed_c10d import _get_default_group |
| 113 | default_pg = _get_default_group() | 116 | default_pg = _get_default_group() |
| @@ -121,10 +124,12 @@ def run_mm_all_reduce_add_rms_norm(rank, world_size, master_ip, master_port, x1_ | |||
| 121 | residual = torch.randn(residual_shape, dtype=dtype).npu() | 124 | residual = torch.randn(residual_shape, dtype=dtype).npu() |
| 122 | gamma = torch.randn(gamma_shape, dtype=dtype).npu() | 125 | gamma = torch.randn(gamma_shape, dtype=dtype).npu() |
| 123 | epsilon = 0.000001 | 126 | epsilon = 0.000001 |
| 124 | - y, norm_out = npu_mm_all_reduce_add_rms_norm_(x1=x1, x2=x2, residual=residual, gamma=gamma, hcom=hcom_info, reduce_op='sum', epsilon=epsilon) | 127 | + y, norm_out = npu_mm_all_reduce_add_rms_norm_(x1=x1, x2=x2, residual=residual, gamma=gamma, hcom=hcom_info, |
| 128 | + reduce_op='sum', epsilon=epsilon) | ||
| 125 | print("y:", y) | 129 | print("y:", y) |
| 126 | print("norm_out:", norm_out) | 130 | print("norm_out:", norm_out) |
| 127 | 131 | ||
| 132 | + | ||
| 128 | if __name__ == "__main__": | 133 | if __name__ == "__main__": |
| 129 | worksize = 8 | 134 | worksize = 8 |
| 130 | master_ip = "127.0.0.1" | 135 | master_ip = "127.0.0.1" |
| @@ -136,5 +141,7 @@ if __name__ == "__main__": | |||
| 136 | gamma_shape = (n) | 141 | gamma_shape = (n) |
| 137 | dtype = torch.float16 | 142 | dtype = torch.float16 |
| 138 | 143 | ||
| 139 | - mp.spawn(run_mm_all_reduce_add_rms_norm, args=(worksize, master_ip, master_port, x1_shape, x2_shape, residual_shape, gamma_shape, dtype), nprocs=worksize) | 144 | + mp.spawn(run_mm_all_reduce_add_rms_norm, |
| 145 | + args=(worksize, master_ip, master_port, x1_shape, x2_shape, residual_shape, gamma_shape, dtype), | ||
| 146 | + nprocs=worksize) | ||
| 140 | ``` | 147 | ``` |
| @@ -21,20 +21,21 @@ | |||
| 21 | - dgammma:必选输出,数据类型float32 | 21 | - dgammma:必选输出,数据类型float32 |
| 22 | 22 | ||
| 23 | ## 案例 | 23 | ## 案例 |
| 24 | + | ||
| 24 | ```python | 25 | ```python |
| 25 | import os | 26 | import os |
| 26 | - import torch | 27 | +import torch |
| 27 | - import torch_npu | 28 | +import torch_npu |
| 28 | - import numpy as np | 29 | +import numpy as np |
| 29 | - import math | 30 | +import math |
| 30 | - from ascendspeed.op_builder import RmsNormOpBuilder | 31 | +from mindspeed.op_builder import RmsNormOpBuilder |
| 31 | - | 32 | + |
| 32 | - x = torch.rand([2,4]).to(torch.float).npu() | 33 | +x = torch.rand([2, 4]).to(torch.float).npu() |
| 33 | - gamma = torch.rand([4]).to(torch.float).npu() | 34 | +gamma = torch.rand([4]).to(torch.float).npu() |
| 34 | - // 正向接口案例 | 35 | +// 正向接口案例 |
| 35 | - ascendspeed_ops = RmsNormOpBuilder.load() | 36 | +mindspeed_ops = RmsNormOpBuilder.load() |
| 36 | - out = ascendspeed_ops.rms_norm(x, gamma) | 37 | +out = mindspeed_ops.rms_norm(x, gamma) |
| 37 | - // 反向接口案例 | 38 | +// 反向接口案例 |
| 38 | - out.backward(torch.ones(out.shape).npu()) | 39 | +out.backward(torch.ones(out.shape).npu()) |
| 39 | 40 | ||
| 40 | ``` | 41 | ``` |
| @@ -27,7 +27,7 @@ | |||
| 27 | import torch_npu | 27 | import torch_npu |
| 28 | import numpy as np | 28 | import numpy as np |
| 29 | import math | 29 | import math |
| 30 | - from ascendspeed.op_builder import SwigluOpBuilder | 30 | + from mindspeed.op_builder import SwigluOpBuilder |
| 31 | 31 | ||
| 32 | x = np.random.uniform(-2, 2, (8192,1,3904)) | 32 | x = np.random.uniform(-2, 2, (8192,1,3904)) |
| 33 | x = torch.from_numpy(x).float().npu() | 33 | x = torch.from_numpy(x).float().npu() |
| @@ -36,7 +36,7 @@ | |||
| 36 | 36 | ||
| 37 | x.requires_grad = True | 37 | x.requires_grad = True |
| 38 | // 正向接口案例 | 38 | // 正向接口案例 |
| 39 | - ascendspeed_ops = SwigluOpBuilder.load() | 39 | + mindspeed_ops = SwigluOpBuilder.load() |
| 40 | - result = ascendspeed_ops.swiglu(x, dim=-1) | 40 | + result = mindspeed_ops.swiglu(x, dim=-1) |
| 41 | // 反向接口案例 | 41 | // 反向接口案例 |
| 42 | result.backward(y_grad) | 42 | result.backward(y_grad) |
Rascendspeed/core/context_parallel/ring_context_parallel.py→mindspeed/core/context_parallel/ring_context_parallel.py+1-1
| @@ -1,5 +1,5 @@ | |||
| 1 | # Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | 1 | # Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | import torch | 3 | import torch |
| 4 | import torch_npu | 4 | import torch_npu |
| 5 | from einops import rearrange | 5 | from einops import rearrange |
Rascendspeed/core/context_parallel/ulysses_context_parallel.py→mindspeed/core/context_parallel/ulysses_context_parallel.py+1-1
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # Copyright (c) Microsoft Corporation. | 3 | # Copyright (c) Microsoft Corporation. |
| 4 | # SPDX-License-Identifier: Apache-2.0 | 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | 5 | ||
文件重命名但无更改。
Rascendspeed/core/fusions/rotary_pos_embedding.py→mindspeed/core/fusions/rotary_pos_embedding.py+0-0
文件重命名但无更改。
Rascendspeed/core/memory/adaptive_recomputing/__init__.py→mindspeed/core/memory/adaptive_recomputing/__init__.py+0-0
文件重命名但无更改。
Rascendspeed/core/memory/adaptive_recomputing/adaptive_recompute.py→mindspeed/core/memory/adaptive_recomputing/adaptive_recompute.py+5-5
| @@ -14,11 +14,11 @@ from megatron.training import print_rank_0, get_num_microbatches | |||
| 14 | from megatron.training import get_args | 14 | from megatron.training import get_args |
| 15 | from megatron.core import parallel_state | 15 | from megatron.core import parallel_state |
| 16 | 16 | ||
| 17 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import get_recompute_hook | 17 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import get_recompute_hook |
| 18 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import get_swap_hook | 18 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import get_swap_hook |
| 19 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import register_recursive_apply as apply_adaptive_recompute | 19 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import register_recursive_apply as apply_adaptive_recompute |
| 20 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_solver import get_graph_solver, GraphSolver | 20 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_solver import get_graph_solver, GraphSolver |
| 21 | -from ascendspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager, get_tensor_mem_size | 21 | +from mindspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager, get_tensor_mem_size |
| 22 | 22 | ||
| 23 | 23 | ||
| 24 | class AdaptiveRecomputePolicy: | 24 | class AdaptiveRecomputePolicy: |
Rascendspeed/core/memory/adaptive_recomputing/adaptive_recompute_apply.py→mindspeed/core/memory/adaptive_recomputing/adaptive_recompute_apply.py+1-1
| @@ -1,6 +1,6 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | from megatron.core import tensor_parallel | 2 | from megatron.core import tensor_parallel |
| 3 | -from ascendspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager | 3 | +from mindspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | class RecomputeHook: | 6 | class RecomputeHook: |
Rascendspeed/core/memory/adaptive_recomputing/adaptive_recompute_solver.py→mindspeed/core/memory/adaptive_recomputing/adaptive_recompute_solver.py+1-1
| @@ -9,7 +9,7 @@ import numpy as np | |||
| 9 | from megatron.training import print_rank_0 | 9 | from megatron.training import print_rank_0 |
| 10 | from megatron.core import parallel_state | 10 | from megatron.core import parallel_state |
| 11 | 11 | ||
| 12 | -from ascendspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager | 12 | +from mindspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | class GraphSolver: | 15 | class GraphSolver: |
Rascendspeed/core/memory/adaptive_recomputing/pluggable_allocator_adpator.py→mindspeed/core/memory/adaptive_recomputing/pluggable_allocator_adpator.py+1-1
| @@ -3,7 +3,7 @@ import ctypes | |||
| 3 | 3 | ||
| 4 | import torch | 4 | import torch |
| 5 | import torch_npu | 5 | import torch_npu |
| 6 | -from ascendspeed.op_builder import AdaptiveRecomputingPluggableAllocatorBuilder | 6 | +from mindspeed.op_builder import AdaptiveRecomputingPluggableAllocatorBuilder |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | def change_allocator(): | 9 | def change_allocator(): |
Rascendspeed/core/memory/adaptive_recomputing/swap_manager.py→mindspeed/core/memory/adaptive_recomputing/swap_manager.py+1-1
| @@ -6,7 +6,7 @@ import torch | |||
| 6 | import torch_npu | 6 | import torch_npu |
| 7 | 7 | ||
| 8 | from megatron.training import print_rank_0 | 8 | from megatron.training import print_rank_0 |
| 9 | -from ascendspeed.core.memory.adaptive_recomputing.swappable_tensor import SwappableTensor | 9 | +from mindspeed.core.memory.adaptive_recomputing.swappable_tensor import SwappableTensor |
| 10 | 10 | ||
| 11 | 11 | ||
| 12 | class SwapManagerMeta(type): | 12 | class SwapManagerMeta(type): |
Rascendspeed/core/memory/adaptive_recomputing/swappable_tensor.py→mindspeed/core/memory/adaptive_recomputing/swappable_tensor.py+0-0
文件重命名但无更改。
Rascendspeed/core/memory/auto_pipeline/autopipeline.py→mindspeed/core/memory/auto_pipeline/autopipeline.py+1-1
| @@ -19,7 +19,7 @@ from megatron.training.training import print_datetime | |||
| 19 | from megatron.core.pipeline_parallel import p2p_communication | 19 | from megatron.core.pipeline_parallel import p2p_communication |
| 20 | from megatron.core import mpu, tensor_parallel | 20 | from megatron.core import mpu, tensor_parallel |
| 21 | from megatron.training.initialize import initialize_megatron | 21 | from megatron.training.initialize import initialize_megatron |
| 22 | -from ascendspeed.initialize import set_jit_fusion_options | 22 | +from mindspeed.initialize import set_jit_fusion_options |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | class AutoPipeline: | 25 | class AutoPipeline: |
Rascendspeed/core/memory/auto_pipeline/autopipeline_apply.py→mindspeed/core/memory/auto_pipeline/autopipeline_apply.py+0-0
文件重命名但无更改。
Rascendspeed/core/memory/auto_pipeline/autopipeline_solver.py→mindspeed/core/memory/auto_pipeline/autopipeline_solver.py+0-0
文件重命名但无更改。
Rascendspeed/core/memory/memory_fragmentation/malloc_recorder.py→mindspeed/core/memory/memory_fragmentation/malloc_recorder.py+1-1
| @@ -1,7 +1,7 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | import torch_npu | 2 | import torch_npu |
| 3 | from functools import wraps | 3 | from functools import wraps |
| 4 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 4 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | class MallocRecorder(object): | 7 | class MallocRecorder(object): |
Rascendspeed/core/memory/memory_fragmentation/memory_recorder.py→mindspeed/core/memory/memory_fragmentation/memory_recorder.py+1-1
| @@ -1,7 +1,7 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | import torch_npu | 2 | import torch_npu |
| 3 | from functools import wraps | 3 | from functools import wraps |
| 4 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 4 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 5 | 5 | ||
| 6 | class MemoryRecorder(object): | 6 | class MemoryRecorder(object): |
| 7 | def __init__(self): | 7 | def __init__(self): |
Rascendspeed/core/memory/memory_fragmentation/optimizer_init_precise.py→mindspeed/core/memory/memory_fragmentation/optimizer_init_precise.py+1-1
| @@ -1,7 +1,7 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | import torch_npu | 2 | import torch_npu |
| 3 | from functools import wraps | 3 | from functools import wraps |
| 4 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 4 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 5 | 5 | ||
| 6 | is_optimizer_init_end = False | 6 | is_optimizer_init_end = False |
| 7 | 7 | ||
Rascendspeed/core/memory/memory_fragmentation/pluggable_allocator_adpator.py→mindspeed/core/memory/memory_fragmentation/pluggable_allocator_adpator.py+1-1
| @@ -3,7 +3,7 @@ import ctypes | |||
| 3 | 3 | ||
| 4 | import torch | 4 | import torch |
| 5 | import torch_npu | 5 | import torch_npu |
| 6 | -from ascendspeed.op_builder import MemoryFragmentationBuilder | 6 | +from mindspeed.op_builder import MemoryFragmentationBuilder |
| 7 | 7 | ||
| 8 | class PluggableAllocatorAdaptor(object): | 8 | class PluggableAllocatorAdaptor(object): |
| 9 | MEMORY_FRAGMENTATION_MODULE = None | 9 | MEMORY_FRAGMENTATION_MODULE = None |
文件重命名但无更改。
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | 3 | # Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 4 | # | 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
文件重命名但无更改。
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/ascend_turbo/__init__.py→mindspeed/core/tensor_parallel/ascend_turbo/__init__.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/ascend_turbo/ascend_turbo_cfg.py→mindspeed/core/tensor_parallel/ascend_turbo/ascend_turbo_cfg.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/ascend_turbo/initialize.py→mindspeed/core/tensor_parallel/ascend_turbo/initialize.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/ascend_turbo/mc2_linears_seq_parallel.py→mindspeed/core/tensor_parallel/ascend_turbo/mc2_linears_seq_parallel.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/cross_entropy.py→mindspeed/core/tensor_parallel/cross_entropy.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/__init__.py→mindspeed/core/tensor_parallel/lcal_coc/__init__.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_all_reduce.py→mindspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_all_reduce.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_all_reduce_fused.py→mindspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_all_reduce_fused.py+1-1
| @@ -9,7 +9,7 @@ from .coc_utils import set_context, allocate_for_output, reshape_to_2D, is_grad_ | |||
| 9 | class FusedCOCRowAllReduceFunction(RewriteRowAllReduceFunction): | 9 | class FusedCOCRowAllReduceFunction(RewriteRowAllReduceFunction): |
| 10 | 10 | ||
| 11 | def forward(ctx, input_, weight, bias): | 11 | def forward(ctx, input_, weight, bias): |
| 12 | - from ascendspeed.ops.lcal_functional import coc_ops | 12 | + from mindspeed.ops.lcal_functional import coc_ops |
| 13 | 13 | ||
| 14 | set_context(ctx, input_, weight, bias) | 14 | set_context(ctx, input_, weight, bias) |
| 15 | parallel_num = get_parallel_num(m=reduce(lambda x, y: x * y, input_.shape[:-1]), | 15 | parallel_num = get_parallel_num(m=reduce(lambda x, y: x * y, input_.shape[:-1]), |
Rascendspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_sequence_parallel.py→mindspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_sequence_parallel.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_sequence_parallel_fused.py→mindspeed/core/tensor_parallel/lcal_coc/coc_parallel_linears_sequence_parallel_fused.py+4-4
| @@ -14,7 +14,7 @@ ALIGN_SIZE = 512 | |||
| 14 | class FusedCOCColumnSeqParallelFunction(torch.autograd.Function): | 14 | class FusedCOCColumnSeqParallelFunction(torch.autograd.Function): |
| 15 | 15 | ||
| 16 | def forward(ctx, input_, weight, bias): | 16 | def forward(ctx, input_, weight, bias): |
| 17 | - from ascendspeed.ops.lcal_functional import coc_ops | 17 | + from mindspeed.ops.lcal_functional import coc_ops |
| 18 | 18 | ||
| 19 | set_context(ctx, input_, weight, bias) | 19 | set_context(ctx, input_, weight, bias) |
| 20 | 20 | ||
| @@ -39,7 +39,7 @@ class FusedCOCColumnSeqParallelFunction(torch.autograd.Function): | |||
| 39 | 39 | ||
| 40 | 40 | ||
| 41 | def backward(ctx, grad_output): | 41 | def backward(ctx, grad_output): |
| 42 | - from ascendspeed.ops.lcal_functional import coc_ops | 42 | + from mindspeed.ops.lcal_functional import coc_ops |
| 43 | 43 | ||
| 44 | input_, weight = ctx.saved_tensors | 44 | input_, weight = ctx.saved_tensors |
| 45 | check_equal(grad_output.shape[0] % min_comm_config.tp_world_size, 0, | 45 | check_equal(grad_output.shape[0] % min_comm_config.tp_world_size, 0, |
| @@ -91,7 +91,7 @@ class FusedCOCColumnSeqParallelFunction(torch.autograd.Function): | |||
| 91 | class FusedCOCRowSeqParallelFunction(torch.autograd.Function): | 91 | class FusedCOCRowSeqParallelFunction(torch.autograd.Function): |
| 92 | 92 | ||
| 93 | def forward(ctx, input_, weight, bias): | 93 | def forward(ctx, input_, weight, bias): |
| 94 | - from ascendspeed.ops.lcal_functional import coc_ops | 94 | + from mindspeed.ops.lcal_functional import coc_ops |
| 95 | 95 | ||
| 96 | set_context(ctx, input_, weight, bias) | 96 | set_context(ctx, input_, weight, bias) |
| 97 | ctx.world_size = min_comm_config.tp_world_size | 97 | ctx.world_size = min_comm_config.tp_world_size |
| @@ -115,7 +115,7 @@ class FusedCOCRowSeqParallelFunction(torch.autograd.Function): | |||
| 115 | 115 | ||
| 116 | 116 | ||
| 117 | def backward(ctx, grad_output): | 117 | def backward(ctx, grad_output): |
| 118 | - from ascendspeed.ops.lcal_functional import coc_ops | 118 | + from mindspeed.ops.lcal_functional import coc_ops |
| 119 | 119 | ||
| 120 | total_input, weight = ctx.saved_tensors | 120 | total_input, weight = ctx.saved_tensors |
| 121 | 121 | ||
Rascendspeed/core/tensor_parallel/lcal_coc/coc_utils.py→mindspeed/core/tensor_parallel/lcal_coc/coc_utils.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/matmul_soc_friendly.py→mindspeed/core/tensor_parallel/lcal_coc/matmul_soc_friendly.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/min_comm_cfg.py→mindspeed/core/tensor_parallel/lcal_coc/min_comm_cfg.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/rewrite_parallel_linears_all_reduce.py→mindspeed/core/tensor_parallel/lcal_coc/rewrite_parallel_linears_all_reduce.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/rewrite_parallel_linears_sequence_parallel.py→mindspeed/core/tensor_parallel/lcal_coc/rewrite_parallel_linears_sequence_parallel.py+0-0
文件重命名但无更改。
Rascendspeed/core/tensor_parallel/lcal_coc/user_config.py→mindspeed/core/tensor_parallel/lcal_coc/user_config.py+0-0
文件重命名但无更改。
| @@ -1,5 +1,5 @@ | |||
| 1 | # Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | 1 | # Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. |
| 2 | - | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | """Pretrain utilities.""" | 3 | """Pretrain utilities.""" |
| 4 | 4 | ||
| 5 | import gc | 5 | import gc |
| @@ -11,10 +11,10 @@ from megatron.training import get_timers | |||
| 11 | from megatron.core import parallel_state | 11 | from megatron.core import parallel_state |
| 12 | from megatron.training import print_rank_0 | 12 | from megatron.training import print_rank_0 |
| 13 | from megatron.training.arguments import parse_args | 13 | from megatron.training.arguments import parse_args |
| 14 | -from ascendspeed.core.memory.auto_pipeline.autopipeline import autopipeline_profiling | 14 | +from mindspeed.core.memory.auto_pipeline.autopipeline import autopipeline_profiling |
| 15 | -from ascendspeed.core.memory.auto_pipeline.autopipeline_apply import apply_autopipeline | 15 | +from mindspeed.core.memory.auto_pipeline.autopipeline_apply import apply_autopipeline |
| 16 | -from ascendspeed.core.memory.auto_pipeline.autopipeline_solver import solve_autopipeline, broadcast_policy_in_ranks, destroy_global_vars | 16 | +from mindspeed.core.memory.auto_pipeline.autopipeline_solver import solve_autopipeline, broadcast_policy_in_ranks, destroy_global_vars |
| 17 | -from ascendspeed.arguments import parse_args_wrapper | 17 | +from mindspeed.arguments import parse_args_wrapper |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | policy = None | 20 | policy = None |
| @@ -1,7 +1,7 @@ | |||
| 1 | from functools import wraps | 1 | from functools import wraps |
| 2 | from megatron.training import get_args | 2 | from megatron.training import get_args |
| 3 | from megatron.core import mpu | 3 | from megatron.core import mpu |
| 4 | -from ascendspeed.core.context_parallel.ulysses_context_parallel import UlyssesContextAttention | 4 | +from mindspeed.core.context_parallel.ulysses_context_parallel import UlyssesContextAttention |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | def attention_init_wrapper(fn): | 7 | def attention_init_wrapper(fn): |
Rascendspeed/core/transformer/custom_layers/transformer_engine.py→mindspeed/core/transformer/custom_layers/transformer_engine.py+0-0
文件重命名但无更改。
Rascendspeed/core/transformer/dot_product_attention.py→mindspeed/core/transformer/dot_product_attention.py+4-0
| @@ -1,3 +1,7 @@ | |||
| 1 | +# coding=utf-8 | ||
| 2 | +# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | ||
| 3 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. | ||
| 4 | + | ||
| 1 | import math | 5 | import math |
| 2 | from functools import wraps | 6 | from functools import wraps |
| 3 | 7 | ||
文件重命名但无更改。
Rascendspeed/core/transformer/transformer_block.py→mindspeed/core/transformer/transformer_block.py+0-0
文件重命名但无更改。
| @@ -4,7 +4,7 @@ import torch | |||
| 4 | import torch_npu | 4 | import torch_npu |
| 5 | from megatron.training import get_args | 5 | from megatron.training import get_args |
| 6 | from megatron.training.initialize import _warmup_jit_function | 6 | from megatron.training.initialize import _warmup_jit_function |
| 7 | -from ascendspeed.core.tensor_parallel.ascend_turbo.initialize import initialize_cfg_from_args | 7 | +from mindspeed.core.tensor_parallel.ascend_turbo.initialize import initialize_cfg_from_args |
| 8 | 8 | ||
| 9 | 9 | ||
| 10 | def _compile_dependencies(): | 10 | def _compile_dependencies(): |
| @@ -49,7 +49,7 @@ def coc_registration_wrapper(fn): | |||
| 49 | 49 | ||
| 50 | def wrapper(*args, **kwargs): | 50 | def wrapper(*args, **kwargs): |
| 51 | res = fn(*args, **kwargs) | 51 | res = fn(*args, **kwargs) |
| 52 | - from ascendspeed.core.tensor_parallel.lcal_coc.user_config import initialize_coc_from_cfg | 52 | + from mindspeed.core.tensor_parallel.lcal_coc.user_config import initialize_coc_from_cfg |
| 53 | args = get_args() | 53 | args = get_args() |
| 54 | initialize_coc_from_cfg(args) | 54 | initialize_coc_from_cfg(args) |
| 55 | return res | 55 | return res |
| @@ -122,10 +122,10 @@ def megatron_core_adaptation(aspm): | |||
| 122 | from .core.fusions.rotary_pos_embedding import apply_fused_rotary_pos_emb_wrapper, rotary_embedding_init_wrapper | 122 | from .core.fusions.rotary_pos_embedding import apply_fused_rotary_pos_emb_wrapper, rotary_embedding_init_wrapper |
| 123 | from .core.transformer.attention import attention_init_wrapper | 123 | from .core.transformer.attention import attention_init_wrapper |
| 124 | from .core.tensor_parallel.layers import row_parallel_nocomm_optimizer_wrapper | 124 | from .core.tensor_parallel.layers import row_parallel_nocomm_optimizer_wrapper |
| 125 | - from ascendspeed.core.transformer.custom_layers.transformer_engine import PTNorm | 125 | + from mindspeed.core.transformer.custom_layers.transformer_engine import PTNorm |
| 126 | - from ascendspeed.core.transformer.dot_product_attention import dot_product_attention_forward_wrapper | 126 | + from mindspeed.core.transformer.dot_product_attention import dot_product_attention_forward_wrapper |
| 127 | from megatron.core.models.gpt.gpt_layer_specs import get_gpt_layer_local_spec | 127 | from megatron.core.models.gpt.gpt_layer_specs import get_gpt_layer_local_spec |
| 128 | - from ascendspeed.core.models.gpt.gpt_layer_specs import get_gpt_layer_local_spec_wrapper | 128 | + from mindspeed.core.models.gpt.gpt_layer_specs import get_gpt_layer_local_spec_wrapper |
| 129 | from .core.parallel_state import initialize_model_parallel | 129 | from .core.parallel_state import initialize_model_parallel |
| 130 | from .core.parallel_state import initialize_model_parallel_wrapper | 130 | from .core.parallel_state import initialize_model_parallel_wrapper |
| 131 | from .core.parallel_state import destroy_model_parallel_wrapper | 131 | from .core.parallel_state import destroy_model_parallel_wrapper |
| @@ -299,7 +299,7 @@ def ascend_adaptation(aspm): | |||
| 299 | 299 | ||
| 300 | 300 | ||
| 301 | def exe_adaptation(): | 301 | def exe_adaptation(): |
| 302 | - from ascendspeed.patch_utils import AscendSpeedPatchesManager as aspm | 302 | + from mindspeed.patch_utils import MindSpeedPatchesManager as aspm |
| 303 | te_adaptation(aspm) | 303 | te_adaptation(aspm) |
| 304 | apex_adaptation(aspm) | 304 | apex_adaptation(aspm) |
| 305 | torch_adaptation(aspm) | 305 | torch_adaptation(aspm) |
| @@ -1,5 +1,6 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. |
| 3 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. | ||
| 3 | # | 4 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. | 6 | # you may not use this file except in compliance with the License. |
Rascendspeed/op_builder/adaptive_recomputing_builder.py→mindspeed/op_builder/adaptive_recomputing_builder.py+2-2
| @@ -1,9 +1,9 @@ | |||
| 1 | import os | 1 | import os |
| 2 | 2 | ||
| 3 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 3 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 4 | 4 | ||
| 5 | 5 | ||
| 6 | -class AdaptiveRecomputingPluggableAllocatorBuilder(AscendSpeedOpBuilder): | 6 | +class AdaptiveRecomputingPluggableAllocatorBuilder(MindSpeedOpBuilder): |
| 7 | NAME = "AdaptiveRecomputing" | 7 | NAME = "AdaptiveRecomputing" |
| 8 | _torch_path = None | 8 | _torch_path = None |
| 9 | 9 | ||
| @@ -1,7 +1,7 @@ | |||
| 1 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 1 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -class AlgorithmOpBuilder(AscendSpeedOpBuilder): | 4 | +class AlgorithmOpBuilder(MindSpeedOpBuilder): |
| 5 | OP_NAME = "algorithm" | 5 | OP_NAME = "algorithm" |
| 6 | 6 | ||
| 7 | def __init__(self): | 7 | def __init__(self): |
| @@ -1,17 +1,17 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import site | 2 | import site |
| 3 | from torch.utils.cpp_extension import load | 3 | from torch.utils.cpp_extension import load |
| 4 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 4 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -class AtbOpBuilder(AscendSpeedOpBuilder): | 7 | +class AtbOpBuilder(MindSpeedOpBuilder): |
| 8 | def __init__(self, name): | 8 | def __init__(self, name): |
| 9 | super(AtbOpBuilder, self).__init__(name) | 9 | super(AtbOpBuilder, self).__init__(name) |
| 10 | 10 | ||
| 11 | def get_atb_path(self): | 11 | def get_atb_path(self): |
| 12 | - import ascendspeed | 12 | + import mindspeed |
| 13 | - ascendspeed_path = ascendspeed.__file__ | 13 | + mindspeed_path = mindspeed.__file__ |
| 14 | - full_path = os.path.join(os.path.dirname(ascendspeed_path), 'atb', 'atb') | 14 | + full_path = os.path.join(os.path.dirname(mindspeed_path), 'atb', 'atb') |
| 15 | return full_path | 15 | return full_path |
| 16 | 16 | ||
| 17 | def include_paths(self): | 17 | def include_paths(self): |
| @@ -4,13 +4,13 @@ from abc import ABC, abstractmethod | |||
| 4 | from torch.utils.cpp_extension import load | 4 | from torch.utils.cpp_extension import load |
| 5 | from torch.library import Library | 5 | from torch.library import Library |
| 6 | import torch_npu | 6 | import torch_npu |
| 7 | -import ascendspeed | 7 | +import mindspeed |
| 8 | 8 | ||
| 9 | ASCEND_HOME_PATH = "ASCEND_HOME_PATH" | 9 | ASCEND_HOME_PATH = "ASCEND_HOME_PATH" |
| 10 | -AS_LIBRARY = Library("ascendspeed", "DEF") | 10 | +AS_LIBRARY = Library("mindspeed", "DEF") |
| 11 | 11 | ||
| 12 | 12 | ||
| 13 | -class AscendSpeedOpBuilder(ABC): | 13 | +class MindSpeedOpBuilder(ABC): |
| 14 | _cann_path = None | 14 | _cann_path = None |
| 15 | _torch_npu_path = None | 15 | _torch_npu_path = None |
| 16 | _cann_version = None | 16 | _cann_version = None |
| @@ -27,8 +27,8 @@ class AscendSpeedOpBuilder(ABC): | |||
| 27 | return None | 27 | return None |
| 28 | 28 | ||
| 29 | def get_absolute_paths(self, paths): | 29 | def get_absolute_paths(self, paths): |
| 30 | - ascendspeed_path = os.path.abspath(os.path.dirname(ascendspeed.__file__)) | 30 | + mindspeed_path = os.path.abspath(os.path.dirname(mindspeed.__file__)) |
| 31 | - return [os.path.join(ascendspeed_path, path) for path in paths] | 31 | + return [os.path.join(mindspeed_path, path) for path in paths] |
| 32 | 32 | ||
| 33 | def register_op_proto(self, op_proto: str): | 33 | def register_op_proto(self, op_proto: str): |
| 34 | AS_LIBRARY.define(op_proto) | 34 | AS_LIBRARY.define(op_proto) |
Rascendspeed/op_builder/fusion_attention_builder.py→mindspeed/op_builder/fusion_attention_builder.py+2-2
| @@ -1,7 +1,7 @@ | |||
| 1 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 1 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -class FusionAttentionOpBuilder(AscendSpeedOpBuilder): | 4 | +class FusionAttentionOpBuilder(MindSpeedOpBuilder): |
| 5 | OP_NAME = "fusion_attention" | 5 | OP_NAME = "fusion_attention" |
| 6 | 6 | ||
| 7 | def __init__(self): | 7 | def __init__(self): |
Rascendspeed/op_builder/fusion_attention_v2_builder.py→mindspeed/op_builder/fusion_attention_v2_builder.py+2-2
| @@ -1,7 +1,7 @@ | |||
| 1 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 1 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -class FusionAttentionV2OpBuilder(AscendSpeedOpBuilder): | 4 | +class FusionAttentionV2OpBuilder(MindSpeedOpBuilder): |
| 5 | OP_NAME = "fusion_attention_v2" | 5 | OP_NAME = "fusion_attention_v2" |
| 6 | 6 | ||
| 7 | def __init__(self): | 7 | def __init__(self): |
| @@ -1,8 +1,8 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 2 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -class GMMOpBuilder(AscendSpeedOpBuilder): | 5 | +class GMMOpBuilder(MindSpeedOpBuilder): |
| 6 | OP_NAME = "grouped_matmul" | 6 | OP_NAME = "grouped_matmul" |
| 7 | TORCH_MAJOR, TORCH_MINOR = map(int, torch.__version__.split('.')[:2]) | 7 | TORCH_MAJOR, TORCH_MINOR = map(int, torch.__version__.split('.')[:2]) |
| 8 | 8 | ||
Rascendspeed/op_builder/grouped_mat_mul_all_reduce_builder.py→mindspeed/op_builder/grouped_mat_mul_all_reduce_builder.py+2-2
| @@ -1,8 +1,8 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 2 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | -class GroupedMatMulAllReduceOpBuilder(AscendSpeedOpBuilder): | 5 | +class GroupedMatMulAllReduceOpBuilder(MindSpeedOpBuilder): |
| 6 | OP_NAME = "grouped_mat_mul_all_reduce" | 6 | OP_NAME = "grouped_mat_mul_all_reduce" |
| 7 | TORCH_MAJOR, TORCH_MINOR = map(int, torch.__version__.split('.')[:2]) | 7 | TORCH_MAJOR, TORCH_MINOR = map(int, torch.__version__.split('.')[:2]) |
| 8 | 8 | ||
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.op_builder.atb_builder import AtbOpBuilder | 1 | +from mindspeed.op_builder.atb_builder import AtbOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class LcalOpBuilder(AtbOpBuilder): | 4 | class LcalOpBuilder(AtbOpBuilder): |
Rascendspeed/op_builder/memory_fragmentation_builder.py→mindspeed/op_builder/memory_fragmentation_builder.py+2-2
| @@ -1,10 +1,10 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | import os | 2 | import os |
| 3 | 3 | ||
| 4 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 4 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 5 | 5 | ||
| 6 | 6 | ||
| 7 | -class MemoryFragmentationBuilder(AscendSpeedOpBuilder): | 7 | +class MemoryFragmentationBuilder(MindSpeedOpBuilder): |
| 8 | NAME = "MemoryFragmentation" | 8 | NAME = "MemoryFragmentation" |
| 9 | _torch_path = None | 9 | _torch_path = None |
| 10 | _python_path = None | 10 | _python_path = None |
Rascendspeed/op_builder/npu_dropout_add_layer_norm_builder.py→mindspeed/op_builder/npu_dropout_add_layer_norm_builder.py+2-2
| @@ -1,7 +1,7 @@ | |||
| 1 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder | 1 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | -class NpuDropoutAddLayerNormOpBuilder(AscendSpeedOpBuilder): | 4 | +class NpuDropoutAddLayerNormOpBuilder(MindSpeedOpBuilder): |
| 5 | OP_NAME = "npu_dropout_add_layer_norm" | 5 | OP_NAME = "npu_dropout_add_layer_norm" |
| 6 | 6 | ||
| 7 | def __init__(self): | 7 | def __init__(self): |
Rascendspeed/op_builder/npu_inplace_mm_all_reduce_add_rms_norm_builder.py→mindspeed/op_builder/npu_inplace_mm_all_reduce_add_rms_norm_builder.py+4-4
| @@ -23,11 +23,11 @@ from torchair.ge_concrete_graph.ge_graph import Tensor, TensorSpec | |||
| 23 | from torchair.ge_concrete_graph.ge_graph import get_default_ge_graph, next_unique_name | 23 | from torchair.ge_concrete_graph.ge_graph import get_default_ge_graph, next_unique_name |
| 24 | from torchair.ge_concrete_graph.ge_graph import compat_as_bytes | 24 | from torchair.ge_concrete_graph.ge_graph import compat_as_bytes |
| 25 | from torchair.ge_concrete_graph.ge_graph import get_invalid_desc | 25 | from torchair.ge_concrete_graph.ge_graph import get_invalid_desc |
| 26 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder, AS_LIBRARY | 26 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder, AS_LIBRARY |
| 27 | -from ascendspeed.op_builder.npu_mm_all_reduce_add_rms_norm_builder import MatmulAllReduceAddRmsNorm | 27 | +from mindspeed.op_builder.npu_mm_all_reduce_add_rms_norm_builder import MatmulAllReduceAddRmsNorm |
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | -class InplaceMatmulAllReduceAddRmsNormOpBuilder(AscendSpeedOpBuilder): | 30 | +class InplaceMatmulAllReduceAddRmsNormOpBuilder(MindSpeedOpBuilder): |
| 31 | OP_NAME = "npu_mm_all_reduce_add_rms_norm_" | 31 | OP_NAME = "npu_mm_all_reduce_add_rms_norm_" |
| 32 | OP_PROTO = "npu_mm_all_reduce_add_rms_norm_(Tensor x1, Tensor x2, Tensor residual, Tensor gamma, \ | 32 | OP_PROTO = "npu_mm_all_reduce_add_rms_norm_(Tensor x1, Tensor x2, Tensor residual, Tensor gamma, \ |
| 33 | str hcom, *, str reduce_op='sum', float epsilon=1e-06, Tensor? bias=None, Tensor? antiquant_scale=None, \ | 33 | str hcom, *, str reduce_op='sum', float epsilon=1e-06, Tensor? bias=None, Tensor? antiquant_scale=None, \ |
| @@ -66,7 +66,7 @@ class InplaceMatmulAllReduceAddRmsNormOpBuilder(AscendSpeedOpBuilder): | |||
| 66 | return (torch.empty_like(residual, dtype=residual.dtype), | 66 | return (torch.empty_like(residual, dtype=residual.dtype), |
| 67 | torch.empty_like(residual, dtype=residual.dtype)) | 67 | torch.empty_like(residual, dtype=residual.dtype)) |
| 68 | 68 | ||
| 69 | - @register_fx_node_ge_converter(torch.ops.ascendspeed.npu_mm_all_reduce_add_rms_norm_.default) | 69 | + @register_fx_node_ge_converter(torch.ops.mindspeed.npu_mm_all_reduce_add_rms_norm_.default) |
| 70 | def convert_npu_mm_all_reduce_add_rms_norm_( | 70 | def convert_npu_mm_all_reduce_add_rms_norm_( |
| 71 | x1: Tensor, | 71 | x1: Tensor, |
| 72 | x2: Tensor, | 72 | x2: Tensor, |
Rascendspeed/op_builder/npu_mm_all_reduce_add_rms_norm_builder.py→mindspeed/op_builder/npu_mm_all_reduce_add_rms_norm_builder.py+3-3
| @@ -22,10 +22,10 @@ from torchair.ge_concrete_graph.ge_graph import Tensor, TensorSpec | |||
| 22 | from torchair.ge_concrete_graph.ge_graph import get_default_ge_graph, next_unique_name | 22 | from torchair.ge_concrete_graph.ge_graph import get_default_ge_graph, next_unique_name |
| 23 | from torchair.ge_concrete_graph.ge_graph import compat_as_bytes | 23 | from torchair.ge_concrete_graph.ge_graph import compat_as_bytes |
| 24 | from torchair.ge_concrete_graph.ge_graph import get_invalid_desc | 24 | from torchair.ge_concrete_graph.ge_graph import get_invalid_desc |
| 25 | -from ascendspeed.op_builder.builder import AscendSpeedOpBuilder, AS_LIBRARY | 25 | +from mindspeed.op_builder.builder import MindSpeedOpBuilder, AS_LIBRARY |
| 26 | 26 | ||
| 27 | 27 | ||
| 28 | -class MatmulAllReduceAddRmsNormOpBuilder(AscendSpeedOpBuilder): | 28 | +class MatmulAllReduceAddRmsNormOpBuilder(MindSpeedOpBuilder): |
| 29 | OP_NAME = "npu_mm_all_reduce_add_rms_norm" | 29 | OP_NAME = "npu_mm_all_reduce_add_rms_norm" |
| 30 | OP_PROTO = "npu_mm_all_reduce_add_rms_norm(Tensor x1, Tensor x2, Tensor residual, Tensor gamma, str hcom, *, \ | 30 | OP_PROTO = "npu_mm_all_reduce_add_rms_norm(Tensor x1, Tensor x2, Tensor residual, Tensor gamma, str hcom, *, \ |
| 31 | str reduce_op='sum', float epsilon=1e-06, Tensor? bias=None, Tensor? antiquant_scale=None, Tensor? \ | 31 | str reduce_op='sum', float epsilon=1e-06, Tensor? bias=None, Tensor? antiquant_scale=None, Tensor? \ |
| @@ -63,7 +63,7 @@ class MatmulAllReduceAddRmsNormOpBuilder(AscendSpeedOpBuilder): | |||
| 63 | return (torch.empty_like(residual, dtype=residual.dtype), | 63 | return (torch.empty_like(residual, dtype=residual.dtype), |
| 64 | torch.empty_like(residual, dtype=residual.dtype)) | 64 | torch.empty_like(residual, dtype=residual.dtype)) |
| 65 | 65 | ||
| 66 | - @register_fx_node_ge_converter(torch.ops.ascendspeed.npu_mm_all_reduce_add_rms_norm.default) | 66 | + @register_fx_node_ge_converter(torch.ops.mindspeed.npu_mm_all_reduce_add_rms_norm.default) |
| 67 | def convert_npu_mm_all_reduce_add_rms_norm( | 67 | def convert_npu_mm_all_reduce_add_rms_norm( |
| 68 | x1: Tensor, | 68 | x1: Tensor, |
| 69 | x2: Tensor, | 69 | x2: Tensor, |
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.op_builder.atb_builder import AtbOpBuilder | 1 | +from mindspeed.op_builder.atb_builder import AtbOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class RmsNormOpBuilder(AtbOpBuilder): | 4 | class RmsNormOpBuilder(AtbOpBuilder): |
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.op_builder.atb_builder import AtbOpBuilder | 1 | +from mindspeed.op_builder.atb_builder import AtbOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class SwigluOpBuilder(AtbOpBuilder): | 4 | class SwigluOpBuilder(AtbOpBuilder): |
文件重命名但无更改。
文件重命名但无更改。
| @@ -13,8 +13,8 @@ | |||
| 13 | * See the License for the specific language governing permissions and | 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. | 14 | * limitations under the License. |
| 15 | */ | 15 | */ |
| 16 | -#ifndef ASCENDSPEED_OPS_CSRC_ATB_INC_ATB_ADAPTER_H | 16 | +#ifndef MINDSPEED_OPS_CSRC_ATB_INC_ATB_ADAPTER_H |
| 17 | -#define ASCENDSPEED_OPS_CSRC_ATB_INC_ATB_ADAPTER_H | 17 | +#define MINDSPEED_OPS_CSRC_ATB_INC_ATB_ADAPTER_H |
| 18 | 18 | ||
| 19 | 19 | ||
| 20 | 20 | ||
文件重命名但无更改。
文件重命名但无更改。
Rascendspeed/ops/csrc/cann/fusion_attention_v2.cpp→mindspeed/ops/csrc/cann/fusion_attention_v2.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/cann/grouped_mat_mul_all_reduce.cpp→mindspeed/ops/csrc/cann/grouped_mat_mul_all_reduce.cpp+0-0
文件重命名但无更改。
| @@ -1,593 +1,593 @@ | |||
| 1 | -/****************************************************************************** | 1 | +/****************************************************************************** |
| 2 | - * Copyright (c) 2022 Huawei Technologies Co., Ltd | 2 | + * Copyright (c) 2022 Huawei Technologies Co., Ltd |
| 3 | - * All rights reserved. | 3 | + * All rights reserved. |
| 4 | - * | 4 | + * |
| 5 | - * Licensed under the BSD 3-Clause License (the "License"); | 5 | + * Licensed under the BSD 3-Clause License (the "License"); |
| 6 | - * you may not use this file except in compliance with the License. | 6 | + * you may not use this file except in compliance with the License. |
| 7 | - * You may obtain a copy of the License at | 7 | + * You may obtain a copy of the License at |
| 8 | - * | 8 | + * |
| 9 | - * https://opensource.org/licenses/BSD-3-Clause | 9 | + * https://opensource.org/licenses/BSD-3-Clause |
| 10 | - * | 10 | + * |
| 11 | - * Unless required by applicable law or agreed to in writing, software | 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | - * distributed under the License is distributed on an "AS IS" BASIS, | 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | - * See the License for the specific language governing permissions and | 14 | + * See the License for the specific language governing permissions and |
| 15 | - * limitations under the License. | 15 | + * limitations under the License. |
| 16 | - ******************************************************************************/ | 16 | + ******************************************************************************/ |
| 17 | - | 17 | + |
| 18 | -#ifndef ASCENDSPEED_OPS_CSRC_CANN_INC_ACL_COMMON_H | 18 | +#ifndef MINDSPEED_OPS_CSRC_CANN_INC_ACL_COMMON_H |
| 19 | -#define ASCENDSPEED_OPS_CSRC_CANN_INC_ACL_COMMON_H | 19 | +#define MINDSPEED_OPS_CSRC_CANN_INC_ACL_COMMON_H |
| 20 | - | 20 | + |
| 21 | -#include <torch_npu/csrc/framework/utils/OpAdapter.h> | 21 | +#include <torch_npu/csrc/framework/utils/OpAdapter.h> |
| 22 | -#include <dlfcn.h> | 22 | +#include <dlfcn.h> |
| 23 | -#include <vector> | 23 | +#include <vector> |
| 24 | -#include <functional> | 24 | +#include <functional> |
| 25 | -#include <type_traits> | 25 | +#include <type_traits> |
| 26 | -#include <ATen/Tensor.h> | 26 | +#include <ATen/Tensor.h> |
| 27 | -#include <acl/acl_base.h> | 27 | +#include <acl/acl_base.h> |
| 28 | -#include <acl/acl_rt.h> | 28 | +#include <acl/acl_rt.h> |
| 29 | -#include <c10/util/Exception.h> | 29 | +#include <c10/util/Exception.h> |
| 30 | -#include "torch_npu/csrc/core/npu/NPUStream.h" | 30 | +#include "torch_npu/csrc/core/npu/NPUStream.h" |
| 31 | -#include "torch_npu/csrc/framework/OpCommand.h" | 31 | +#include "torch_npu/csrc/framework/OpCommand.h" |
| 32 | -#include "torch_npu/csrc/framework/interface/EnvVariables.h" | 32 | +#include "torch_npu/csrc/framework/interface/EnvVariables.h" |
| 33 | -#include "torch_npu/csrc/aten/NPUNativeFunctions.h" | 33 | +#include "torch_npu/csrc/aten/NPUNativeFunctions.h" |
| 34 | -#include "torch_npu/csrc/core/npu/DeviceUtils.h" | 34 | +#include "torch_npu/csrc/core/npu/DeviceUtils.h" |
| 35 | - | 35 | + |
| 36 | -#define NPU_NAME_SPACE at_npu::native | 36 | +#define NPU_NAME_SPACE at_npu::native |
| 37 | - | 37 | + |
| 38 | -using aclOpExecutor = struct aclOpExecutor; | 38 | +using aclOpExecutor = struct aclOpExecutor; |
| 39 | -using aclTensor = struct aclTensor; | 39 | +using aclTensor = struct aclTensor; |
| 40 | -using aclScalar = struct aclScalar; | 40 | +using aclScalar = struct aclScalar; |
| 41 | -using aclIntArray = struct aclIntArray; | 41 | +using aclIntArray = struct aclIntArray; |
| 42 | -using aclFloatArray = struct aclFloatArray; | 42 | +using aclFloatArray = struct aclFloatArray; |
| 43 | -using aclBoolArray = struct aclBoolArray; | 43 | +using aclBoolArray = struct aclBoolArray; |
| 44 | -using aclTensorList = struct aclTensorList; | 44 | +using aclTensorList = struct aclTensorList; |
| 45 | - | 45 | + |
| 46 | -using _aclCreateTensor = aclTensor *(*)(const int64_t *view_dims, uint64_t view_dims_num, aclDataType data_type, | 46 | +using _aclCreateTensor = aclTensor *(*)(const int64_t *view_dims, uint64_t view_dims_num, aclDataType data_type, |
| 47 | - const int64_t *stride, int64_t offset, aclFormat format, const int64_t *storage_dims, uint64_t storage_dims_num, | 47 | + const int64_t *stride, int64_t offset, aclFormat format, const int64_t *storage_dims, uint64_t storage_dims_num, |
| 48 | - void *tensor_data); | 48 | + void *tensor_data); |
| 49 | -using _aclCreateScalar = aclScalar *(*)(void *value, aclDataType data_type); | 49 | +using _aclCreateScalar = aclScalar *(*)(void *value, aclDataType data_type); |
| 50 | -using _aclCreateIntArray = aclIntArray *(*)(const int64_t *value, uint64_t size); | 50 | +using _aclCreateIntArray = aclIntArray *(*)(const int64_t *value, uint64_t size); |
| 51 | -using _aclCreateFloatArray = aclFloatArray *(*)(const float *value, uint64_t size); | 51 | +using _aclCreateFloatArray = aclFloatArray *(*)(const float *value, uint64_t size); |
| 52 | -using _aclCreateBoolArray = aclBoolArray *(*)(const bool *value, uint64_t size); | 52 | +using _aclCreateBoolArray = aclBoolArray *(*)(const bool *value, uint64_t size); |
| 53 | -using _aclCreateTensorList = aclTensorList *(*)(const aclTensor *const *value, uint64_t size); | 53 | +using _aclCreateTensorList = aclTensorList *(*)(const aclTensor *const *value, uint64_t size); |
| 54 | - | 54 | + |
| 55 | -using _aclDestroyTensor = int (*)(const aclTensor *tensor); | 55 | +using _aclDestroyTensor = int (*)(const aclTensor *tensor); |
| 56 | -using _aclDestroyScalar = int (*)(const aclScalar *scalar); | 56 | +using _aclDestroyScalar = int (*)(const aclScalar *scalar); |
| 57 | -using _aclDestroyIntArray = int (*)(const aclIntArray *array); | 57 | +using _aclDestroyIntArray = int (*)(const aclIntArray *array); |
| 58 | -using _aclDestroyFloatArray = int (*)(const aclFloatArray *array); | 58 | +using _aclDestroyFloatArray = int (*)(const aclFloatArray *array); |
| 59 | -using _aclDestroyBoolArray = int (*)(const aclBoolArray *array); | 59 | +using _aclDestroyBoolArray = int (*)(const aclBoolArray *array); |
| 60 | -using _aclDestroyTensorList = int (*)(const aclTensorList *array); | 60 | +using _aclDestroyTensorList = int (*)(const aclTensorList *array); |
| 61 | - | 61 | + |
| 62 | -constexpr int kHashBufSize = 8192; | 62 | +constexpr int kHashBufSize = 8192; |
| 63 | -constexpr int kHashBufMaxSize = kHashBufSize + 1024; | 63 | +constexpr int kHashBufMaxSize = kHashBufSize + 1024; |
| 64 | -extern thread_local char g_hashBuf[kHashBufSize]; | 64 | +extern thread_local char g_hashBuf[kHashBufSize]; |
| 65 | -extern thread_local int g_hashOffset; | 65 | +extern thread_local int g_hashOffset; |
| 66 | - | 66 | + |
| 67 | -#define AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(_) \ | 67 | +#define AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(_) \ |
| 68 | - _(at::ScalarType::Byte, ACL_UINT8) \ | 68 | + _(at::ScalarType::Byte, ACL_UINT8) \ |
| 69 | - _(at::ScalarType::Char, ACL_INT8) \ | 69 | + _(at::ScalarType::Char, ACL_INT8) \ |
| 70 | - _(at::ScalarType::Short, ACL_INT16) \ | 70 | + _(at::ScalarType::Short, ACL_INT16) \ |
| 71 | - _(at::ScalarType::Int, ACL_INT32) \ | 71 | + _(at::ScalarType::Int, ACL_INT32) \ |
| 72 | - _(at::ScalarType::Long, ACL_INT64) \ | 72 | + _(at::ScalarType::Long, ACL_INT64) \ |
| 73 | - _(at::ScalarType::Half, ACL_FLOAT16) \ | 73 | + _(at::ScalarType::Half, ACL_FLOAT16) \ |
| 74 | - _(at::ScalarType::Float, ACL_FLOAT) \ | 74 | + _(at::ScalarType::Float, ACL_FLOAT) \ |
| 75 | - _(at::ScalarType::Double, ACL_DOUBLE) \ | 75 | + _(at::ScalarType::Double, ACL_DOUBLE) \ |
| 76 | - _(at::ScalarType::ComplexHalf, ACL_DT_UNDEFINED) \ | 76 | + _(at::ScalarType::ComplexHalf, ACL_DT_UNDEFINED) \ |
| 77 | - _(at::ScalarType::ComplexFloat, ACL_COMPLEX64) \ | 77 | + _(at::ScalarType::ComplexFloat, ACL_COMPLEX64) \ |
| 78 | - _(at::ScalarType::ComplexDouble, ACL_COMPLEX128) \ | 78 | + _(at::ScalarType::ComplexDouble, ACL_COMPLEX128) \ |
| 79 | - _(at::ScalarType::Bool, ACL_BOOL) \ | 79 | + _(at::ScalarType::Bool, ACL_BOOL) \ |
| 80 | - _(at::ScalarType::QInt8, ACL_DT_UNDEFINED) \ | 80 | + _(at::ScalarType::QInt8, ACL_DT_UNDEFINED) \ |
| 81 | - _(at::ScalarType::QUInt8, ACL_DT_UNDEFINED) \ | 81 | + _(at::ScalarType::QUInt8, ACL_DT_UNDEFINED) \ |
| 82 | - _(at::ScalarType::QInt32, ACL_DT_UNDEFINED) \ | 82 | + _(at::ScalarType::QInt32, ACL_DT_UNDEFINED) \ |
| 83 | - _(at::ScalarType::BFloat16, ACL_BF16) \ | 83 | + _(at::ScalarType::BFloat16, ACL_BF16) \ |
| 84 | - _(at::ScalarType::QUInt4x2, ACL_DT_UNDEFINED) \ | 84 | + _(at::ScalarType::QUInt4x2, ACL_DT_UNDEFINED) \ |
| 85 | - _(at::ScalarType::QUInt2x4, ACL_DT_UNDEFINED) \ | 85 | + _(at::ScalarType::QUInt2x4, ACL_DT_UNDEFINED) \ |
| 86 | - _(at::ScalarType::Undefined, ACL_DT_UNDEFINED) \ | 86 | + _(at::ScalarType::Undefined, ACL_DT_UNDEFINED) \ |
| 87 | - _(at::ScalarType::NumOptions, ACL_DT_UNDEFINED) | 87 | + _(at::ScalarType::NumOptions, ACL_DT_UNDEFINED) |
| 88 | - | 88 | + |
| 89 | -constexpr aclDataType kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(at::ScalarType::NumOptions) + 1] = { | 89 | +constexpr aclDataType kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(at::ScalarType::NumOptions) + 1] = { |
| 90 | -#define DEFINE_ENUM(_1, n) n, | 90 | +#define DEFINE_ENUM(_1, n) n, |
| 91 | - AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(DEFINE_ENUM) | 91 | + AT_ALL_SCALAR_TYPE_AND_ACL_DATATYPE_PAIR(DEFINE_ENUM) |
| 92 | -#undef DEFINE_ENUM | 92 | +#undef DEFINE_ENUM |
| 93 | -}; | 93 | +}; |
| 94 | - | 94 | + |
| 95 | -#define GET_OP_API_FUNC(apiName) reinterpret_cast<_##apiName>(GetOpApiFuncAddr(#apiName)) | 95 | +#define GET_OP_API_FUNC(apiName) reinterpret_cast<_##apiName>(GetOpApiFuncAddr(#apiName)) |
| 96 | - | 96 | + |
| 97 | -#define MEMCPY_TO_BUF(data_expression, size_expression) \ | 97 | +#define MEMCPY_TO_BUF(data_expression, size_expression) \ |
| 98 | - if (g_hashOffset + (size_expression) > kHashBufSize) { \ | 98 | + if (g_hashOffset + (size_expression) > kHashBufSize) { \ |
| 99 | - g_hashOffset = kHashBufMaxSize; \ | 99 | + g_hashOffset = kHashBufMaxSize; \ |
| 100 | - return; \ | 100 | + return; \ |
| 101 | - } \ | 101 | + } \ |
| 102 | - memcpy_s(g_hashBuf + g_hashOffset, size_expression, data_expression, size_expression); \ | 102 | + memcpy_s(g_hashBuf + g_hashOffset, size_expression, data_expression, size_expression); \ |
| 103 | - g_hashOffset += size_expression; | 103 | + g_hashOffset += size_expression; |
| 104 | - | 104 | + |
| 105 | -inline const char *GetOpApiLibName(void) | 105 | +inline const char *GetOpApiLibName(void) |
| 106 | -{ | 106 | +{ |
| 107 | - return "libopapi.so"; | 107 | + return "libopapi.so"; |
| 108 | -} | 108 | +} |
| 109 | - | 109 | + |
| 110 | -inline const char *GetCustOpApiLibName(void) | 110 | +inline const char *GetCustOpApiLibName(void) |
| 111 | -{ | 111 | +{ |
| 112 | - return "libcust_opapi.so"; | 112 | + return "libcust_opapi.so"; |
| 113 | -} | 113 | +} |
| 114 | - | 114 | + |
| 115 | -inline void *GetOpApiFuncAddrInLib(void *handler, const char *libName, const char *apiName) | 115 | +inline void *GetOpApiFuncAddrInLib(void *handler, const char *libName, const char *apiName) |
| 116 | -{ | 116 | +{ |
| 117 | - auto funcAddr = dlsym(handler, apiName); | 117 | + auto funcAddr = dlsym(handler, apiName); |
| 118 | - if (funcAddr == nullptr) { | 118 | + if (funcAddr == nullptr) { |
| 119 | - ASCEND_LOGW("dlsym %s from %s failed, error:%s.", apiName, libName, dlerror()); | 119 | + ASCEND_LOGW("dlsym %s from %s failed, error:%s.", apiName, libName, dlerror()); |
| 120 | - } | 120 | + } |
| 121 | - return funcAddr; | 121 | + return funcAddr; |
| 122 | -} | 122 | +} |
| 123 | - | 123 | + |
| 124 | -inline void *GetOpApiLibHandler(const char *libName) | 124 | +inline void *GetOpApiLibHandler(const char *libName) |
| 125 | -{ | 125 | +{ |
| 126 | - auto handler = dlopen(libName, RTLD_LAZY); | 126 | + auto handler = dlopen(libName, RTLD_LAZY); |
| 127 | - if (handler == nullptr) { | 127 | + if (handler == nullptr) { |
| 128 | - ASCEND_LOGW("dlopen %s failed, error:%s.", libName, dlerror()); | 128 | + ASCEND_LOGW("dlopen %s failed, error:%s.", libName, dlerror()); |
| 129 | - } | 129 | + } |
| 130 | - return handler; | 130 | + return handler; |
| 131 | -} | 131 | +} |
| 132 | - | 132 | + |
| 133 | -inline void *GetOpApiFuncAddr(const char *apiName) | 133 | +inline void *GetOpApiFuncAddr(const char *apiName) |
| 134 | -{ | 134 | +{ |
| 135 | - static auto custOpApiHandler = GetOpApiLibHandler(GetCustOpApiLibName()); | 135 | + static auto custOpApiHandler = GetOpApiLibHandler(GetCustOpApiLibName()); |
| 136 | - if (custOpApiHandler != nullptr) { | 136 | + if (custOpApiHandler != nullptr) { |
| 137 | - auto funcAddr = GetOpApiFuncAddrInLib(custOpApiHandler, GetCustOpApiLibName(), apiName); | 137 | + auto funcAddr = GetOpApiFuncAddrInLib(custOpApiHandler, GetCustOpApiLibName(), apiName); |
| 138 | - if (funcAddr != nullptr) { | 138 | + if (funcAddr != nullptr) { |
| 139 | - return funcAddr; | 139 | + return funcAddr; |
| 140 | - } | 140 | + } |
| 141 | - } | 141 | + } |
| 142 | - | 142 | + |
| 143 | - static auto opApiHandler = GetOpApiLibHandler(GetOpApiLibName()); | 143 | + static auto opApiHandler = GetOpApiLibHandler(GetOpApiLibName()); |
| 144 | - if (opApiHandler == nullptr) { | 144 | + if (opApiHandler == nullptr) { |
| 145 | - return nullptr; | 145 | + return nullptr; |
| 146 | - } | 146 | + } |
| 147 | - return GetOpApiFuncAddrInLib(opApiHandler, GetOpApiLibName(), apiName); | 147 | + return GetOpApiFuncAddrInLib(opApiHandler, GetOpApiLibName(), apiName); |
| 148 | -} | 148 | +} |
| 149 | - | 149 | + |
| 150 | -inline c10::Scalar ConvertTensorToScalar(const at::Tensor &tensor) | 150 | +inline c10::Scalar ConvertTensorToScalar(const at::Tensor &tensor) |
| 151 | -{ | 151 | +{ |
| 152 | - c10::Scalar expScalar; | 152 | + c10::Scalar expScalar; |
| 153 | - const at::Tensor *aclInput = &tensor; | 153 | + const at::Tensor *aclInput = &tensor; |
| 154 | - if (aclInput->scalar_type() == at::ScalarType::Double) { | 154 | + if (aclInput->scalar_type() == at::ScalarType::Double) { |
| 155 | - double value = *(double *)aclInput->data_ptr(); | 155 | + double value = *(double *)aclInput->data_ptr(); |
| 156 | - c10::Scalar scalar(value); | 156 | + c10::Scalar scalar(value); |
| 157 | - expScalar = scalar; | 157 | + expScalar = scalar; |
| 158 | - } else if (aclInput->scalar_type() == at::ScalarType::Long) { | 158 | + } else if (aclInput->scalar_type() == at::ScalarType::Long) { |
| 159 | - int64_t value = *(int64_t *)aclInput->data_ptr(); | 159 | + int64_t value = *(int64_t *)aclInput->data_ptr(); |
| 160 | - c10::Scalar scalar(value); | 160 | + c10::Scalar scalar(value); |
| 161 | - expScalar = scalar; | 161 | + expScalar = scalar; |
| 162 | - } else if (aclInput->scalar_type() == at::ScalarType::Float) { | 162 | + } else if (aclInput->scalar_type() == at::ScalarType::Float) { |
| 163 | - float value = *(float *)aclInput->data_ptr(); | 163 | + float value = *(float *)aclInput->data_ptr(); |
| 164 | - c10::Scalar scalar(value); | 164 | + c10::Scalar scalar(value); |
| 165 | - expScalar = scalar; | 165 | + expScalar = scalar; |
| 166 | - } else if (aclInput->scalar_type() == at::ScalarType::Int) { | 166 | + } else if (aclInput->scalar_type() == at::ScalarType::Int) { |
| 167 | - int value = *(int *)aclInput->data_ptr(); | 167 | + int value = *(int *)aclInput->data_ptr(); |
| 168 | - c10::Scalar scalar(value); | 168 | + c10::Scalar scalar(value); |
| 169 | - expScalar = scalar; | 169 | + expScalar = scalar; |
| 170 | - } else if (aclInput->scalar_type() == at::ScalarType::Half) { | 170 | + } else if (aclInput->scalar_type() == at::ScalarType::Half) { |
| 171 | - c10::Half value = *(c10::Half *)aclInput->data_ptr(); | 171 | + c10::Half value = *(c10::Half *)aclInput->data_ptr(); |
| 172 | - c10::Scalar scalar(value); | 172 | + c10::Scalar scalar(value); |
| 173 | - expScalar = scalar; | 173 | + expScalar = scalar; |
| 174 | - } else if (aclInput->scalar_type() == at::ScalarType::Bool) { | 174 | + } else if (aclInput->scalar_type() == at::ScalarType::Bool) { |
| 175 | - int8_t value = *(int8_t *)aclInput->data_ptr(); | 175 | + int8_t value = *(int8_t *)aclInput->data_ptr(); |
| 176 | - c10::Scalar scalar(value); | 176 | + c10::Scalar scalar(value); |
| 177 | - expScalar = scalar; | 177 | + expScalar = scalar; |
| 178 | - } else if (aclInput->scalar_type() == at::ScalarType::ComplexDouble) { | 178 | + } else if (aclInput->scalar_type() == at::ScalarType::ComplexDouble) { |
| 179 | - c10::complex<double> value = *(c10::complex<double> *)aclInput->data_ptr(); | 179 | + c10::complex<double> value = *(c10::complex<double> *)aclInput->data_ptr(); |
| 180 | - c10::Scalar scalar(value); | 180 | + c10::Scalar scalar(value); |
| 181 | - expScalar = scalar; | 181 | + expScalar = scalar; |
| 182 | - } else if (aclInput->scalar_type() == at::ScalarType::ComplexFloat) { | 182 | + } else if (aclInput->scalar_type() == at::ScalarType::ComplexFloat) { |
| 183 | - c10::complex<float> value = *(c10::complex<float> *)aclInput->data_ptr(); | 183 | + c10::complex<float> value = *(c10::complex<float> *)aclInput->data_ptr(); |
| 184 | - c10::Scalar scalar(value); | 184 | + c10::Scalar scalar(value); |
| 185 | - expScalar = scalar; | 185 | + expScalar = scalar; |
| 186 | - } else if (aclInput->scalar_type() == at::ScalarType::BFloat16) { | 186 | + } else if (aclInput->scalar_type() == at::ScalarType::BFloat16) { |
| 187 | - c10::BFloat16 value = *(c10::BFloat16 *)aclInput->data_ptr(); | 187 | + c10::BFloat16 value = *(c10::BFloat16 *)aclInput->data_ptr(); |
| 188 | - c10::Scalar scalar(value); | 188 | + c10::Scalar scalar(value); |
| 189 | - expScalar = scalar; | 189 | + expScalar = scalar; |
| 190 | - } else { | 190 | + } else { |
| 191 | - ASCEND_LOGE("unsupported scalar type! "); | 191 | + ASCEND_LOGE("unsupported scalar type! "); |
| 192 | - } | 192 | + } |
| 193 | - return expScalar; | 193 | + return expScalar; |
| 194 | -} | 194 | +} |
| 195 | - | 195 | + |
| 196 | -inline at::Tensor CopyTensorHostToDevice(const at::Tensor &cpu_tensor) | 196 | +inline at::Tensor CopyTensorHostToDevice(const at::Tensor &cpu_tensor) |
| 197 | -{ | 197 | +{ |
| 198 | - at::Tensor cpuPinMemTensor = cpu_tensor.pin_memory(); | 198 | + at::Tensor cpuPinMemTensor = cpu_tensor.pin_memory(); |
| 199 | - int deviceIndex = 0; | 199 | + int deviceIndex = 0; |
| 200 | - return cpuPinMemTensor.to( | 200 | + return cpuPinMemTensor.to( |
| 201 | - c10::Device(torch_npu::utils::get_npu_device_type(), deviceIndex), cpuPinMemTensor.scalar_type(), true, true); | 201 | + c10::Device(torch_npu::utils::get_npu_device_type(), deviceIndex), cpuPinMemTensor.scalar_type(), true, true); |
| 202 | -} | 202 | +} |
| 203 | - | 203 | + |
| 204 | -inline at::Tensor CopyScalarToDevice(const c10::Scalar &cpu_scalar, at::ScalarType scalar_data_type) | 204 | +inline at::Tensor CopyScalarToDevice(const c10::Scalar &cpu_scalar, at::ScalarType scalar_data_type) |
| 205 | -{ | 205 | +{ |
| 206 | - return CopyTensorHostToDevice(scalar_to_tensor(cpu_scalar).to(scalar_data_type)); | 206 | + return CopyTensorHostToDevice(scalar_to_tensor(cpu_scalar).to(scalar_data_type)); |
| 207 | -} | 207 | +} |
| 208 | - | 208 | + |
| 209 | -inline aclTensor *ConvertType(const at::Tensor &at_tensor) | 209 | +inline aclTensor *ConvertType(const at::Tensor &at_tensor) |
| 210 | -{ | 210 | +{ |
| 211 | - static const auto aclCreateTensor = GET_OP_API_FUNC(aclCreateTensor); | 211 | + static const auto aclCreateTensor = GET_OP_API_FUNC(aclCreateTensor); |
| 212 | - if (aclCreateTensor == nullptr) { | 212 | + if (aclCreateTensor == nullptr) { |
| 213 | - return nullptr; | 213 | + return nullptr; |
| 214 | - } | 214 | + } |
| 215 | - | 215 | + |
| 216 | - if (!at_tensor.defined()) { | 216 | + if (!at_tensor.defined()) { |
| 217 | - return nullptr; | 217 | + return nullptr; |
| 218 | - } | 218 | + } |
| 219 | - at::ScalarType scalar_data_type = at_tensor.scalar_type(); | 219 | + at::ScalarType scalar_data_type = at_tensor.scalar_type(); |
| 220 | - aclDataType acl_data_type = kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(scalar_data_type)]; | 220 | + aclDataType acl_data_type = kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(scalar_data_type)]; |
| 221 | - TORCH_CHECK( | 221 | + TORCH_CHECK( |
| 222 | - acl_data_type != ACL_DT_UNDEFINED, std::string(c10::toString(scalar_data_type)) + " has not been supported") | 222 | + acl_data_type != ACL_DT_UNDEFINED, std::string(c10::toString(scalar_data_type)) + " has not been supported") |
| 223 | - c10::SmallVector<int64_t, 5> storageDims; | 223 | + c10::SmallVector<int64_t, 5> storageDims; |
| 224 | - // if acl_data_type is ACL_STRING, storageDims is empty. | 224 | + // if acl_data_type is ACL_STRING, storageDims is empty. |
| 225 | - auto itemsize = at_tensor.itemsize(); | 225 | + auto itemsize = at_tensor.itemsize(); |
| 226 | - if (itemsize == 0) { | 226 | + if (itemsize == 0) { |
| 227 | - AT_ERROR("When ConvertType, tensor item size of cannot be zero."); | 227 | + AT_ERROR("When ConvertType, tensor item size of cannot be zero."); |
| 228 | - return nullptr; | 228 | + return nullptr; |
| 229 | - } | 229 | + } |
| 230 | - if (acl_data_type != ACL_STRING) { | 230 | + if (acl_data_type != ACL_STRING) { |
| 231 | - storageDims.push_back(at_tensor.storage().nbytes() / itemsize); | 231 | + storageDims.push_back(at_tensor.storage().nbytes() / itemsize); |
| 232 | - } | 232 | + } |
| 233 | - | 233 | + |
| 234 | - const auto dimNum = at_tensor.sizes().size(); | 234 | + const auto dimNum = at_tensor.sizes().size(); |
| 235 | - aclFormat format = ACL_FORMAT_ND; | 235 | + aclFormat format = ACL_FORMAT_ND; |
| 236 | - switch (dimNum) { | 236 | + switch (dimNum) { |
| 237 | - case 3: | 237 | + case 3: |
| 238 | - format = ACL_FORMAT_NCL; | 238 | + format = ACL_FORMAT_NCL; |
| 239 | - break; | 239 | + break; |
| 240 | - case 4: | 240 | + case 4: |
| 241 | - format = ACL_FORMAT_NCHW; | 241 | + format = ACL_FORMAT_NCHW; |
| 242 | - break; | 242 | + break; |
| 243 | - case 5: | 243 | + case 5: |
| 244 | - format = ACL_FORMAT_NCDHW; | 244 | + format = ACL_FORMAT_NCDHW; |
| 245 | - break; | 245 | + break; |
| 246 | - default: | 246 | + default: |
| 247 | - format = ACL_FORMAT_ND; | 247 | + format = ACL_FORMAT_ND; |
| 248 | - } | 248 | + } |
| 249 | - | 249 | + |
| 250 | - if (at_tensor.unsafeGetTensorImpl()->is_wrapped_number()) { | 250 | + if (at_tensor.unsafeGetTensorImpl()->is_wrapped_number()) { |
| 251 | - c10::Scalar expScalar = ConvertTensorToScalar(at_tensor); | 251 | + c10::Scalar expScalar = ConvertTensorToScalar(at_tensor); |
| 252 | - at::Tensor aclInput = CopyScalarToDevice(expScalar, scalar_data_type); | 252 | + at::Tensor aclInput = CopyScalarToDevice(expScalar, scalar_data_type); |
| 253 | - return aclCreateTensor(aclInput.sizes().data(), | 253 | + return aclCreateTensor(aclInput.sizes().data(), |
| 254 | - aclInput.sizes().size(), | 254 | + aclInput.sizes().size(), |
| 255 | - acl_data_type, | 255 | + acl_data_type, |
| 256 | - aclInput.strides().data(), | 256 | + aclInput.strides().data(), |
| 257 | - aclInput.storage_offset(), | 257 | + aclInput.storage_offset(), |
| 258 | - format, | 258 | + format, |
| 259 | - storageDims.data(), | 259 | + storageDims.data(), |
| 260 | - storageDims.size(), | 260 | + storageDims.size(), |
| 261 | - const_cast<void *>(aclInput.storage().data())); | 261 | + const_cast<void *>(aclInput.storage().data())); |
| 262 | - } | 262 | + } |
| 263 | - | 263 | + |
| 264 | - auto acl_tensor = aclCreateTensor(at_tensor.sizes().data(), | 264 | + auto acl_tensor = aclCreateTensor(at_tensor.sizes().data(), |
| 265 | - at_tensor.sizes().size(), | 265 | + at_tensor.sizes().size(), |
| 266 | - acl_data_type, | 266 | + acl_data_type, |
| 267 | - at_tensor.strides().data(), | 267 | + at_tensor.strides().data(), |
| 268 | - at_tensor.storage_offset(), | 268 | + at_tensor.storage_offset(), |
| 269 | - format, | 269 | + format, |
| 270 | - storageDims.data(), | 270 | + storageDims.data(), |
| 271 | - storageDims.size(), | 271 | + storageDims.size(), |
| 272 | - const_cast<void *>(at_tensor.storage().data())); | 272 | + const_cast<void *>(at_tensor.storage().data())); |
| 273 | - return acl_tensor; | 273 | + return acl_tensor; |
| 274 | -} | 274 | +} |
| 275 | - | 275 | + |
| 276 | -inline aclScalar *ConvertType(const at::Scalar &at_scalar) | 276 | +inline aclScalar *ConvertType(const at::Scalar &at_scalar) |
| 277 | -{ | 277 | +{ |
| 278 | - static const auto aclCreateScalar = GET_OP_API_FUNC(aclCreateScalar); | 278 | + static const auto aclCreateScalar = GET_OP_API_FUNC(aclCreateScalar); |
| 279 | - if (aclCreateScalar == nullptr) { | 279 | + if (aclCreateScalar == nullptr) { |
| 280 | - return nullptr; | 280 | + return nullptr; |
| 281 | - } | 281 | + } |
| 282 | - | 282 | + |
| 283 | - at::ScalarType scalar_data_type = at_scalar.type(); | 283 | + at::ScalarType scalar_data_type = at_scalar.type(); |
| 284 | - aclDataType acl_data_type = kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(scalar_data_type)]; | 284 | + aclDataType acl_data_type = kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(scalar_data_type)]; |
| 285 | - TORCH_CHECK( | 285 | + TORCH_CHECK( |
| 286 | - acl_data_type != ACL_DT_UNDEFINED, std::string(c10::toString(scalar_data_type)) + " has not been supported") | 286 | + acl_data_type != ACL_DT_UNDEFINED, std::string(c10::toString(scalar_data_type)) + " has not been supported") |
| 287 | - aclScalar *acl_scalar = nullptr; | 287 | + aclScalar *acl_scalar = nullptr; |
| 288 | - switch (scalar_data_type) { | 288 | + switch (scalar_data_type) { |
| 289 | - case at::ScalarType::Double: { | 289 | + case at::ScalarType::Double: { |
| 290 | - double value = at_scalar.toDouble(); | 290 | + double value = at_scalar.toDouble(); |
| 291 | - acl_scalar = aclCreateScalar(&value, acl_data_type); | 291 | + acl_scalar = aclCreateScalar(&value, acl_data_type); |
| 292 | - break; | 292 | + break; |
| 293 | - } | 293 | + } |
| 294 | - case at::ScalarType::Long: { | 294 | + case at::ScalarType::Long: { |
| 295 | - int64_t value = at_scalar.toLong(); | 295 | + int64_t value = at_scalar.toLong(); |
| 296 | - acl_scalar = aclCreateScalar(&value, acl_data_type); | 296 | + acl_scalar = aclCreateScalar(&value, acl_data_type); |
| 297 | - break; | 297 | + break; |
| 298 | - } | 298 | + } |
| 299 | - case at::ScalarType::Bool: { | 299 | + case at::ScalarType::Bool: { |
| 300 | - bool value = at_scalar.toBool(); | 300 | + bool value = at_scalar.toBool(); |
| 301 | - acl_scalar = aclCreateScalar(&value, acl_data_type); | 301 | + acl_scalar = aclCreateScalar(&value, acl_data_type); |
| 302 | - break; | 302 | + break; |
| 303 | - } | 303 | + } |
| 304 | - case at::ScalarType::ComplexDouble: { | 304 | + case at::ScalarType::ComplexDouble: { |
| 305 | - auto value = at_scalar.toComplexDouble(); | 305 | + auto value = at_scalar.toComplexDouble(); |
| 306 | - acl_scalar = aclCreateScalar(&value, acl_data_type); | 306 | + acl_scalar = aclCreateScalar(&value, acl_data_type); |
| 307 | - break; | 307 | + break; |
| 308 | - } | 308 | + } |
| 309 | - default: | 309 | + default: |
| 310 | - acl_scalar = nullptr; | 310 | + acl_scalar = nullptr; |
| 311 | - break; | 311 | + break; |
| 312 | - } | 312 | + } |
| 313 | - return acl_scalar; | 313 | + return acl_scalar; |
| 314 | -} | 314 | +} |
| 315 | - | 315 | + |
| 316 | -inline aclIntArray *ConvertType(const at::IntArrayRef &at_array) | 316 | +inline aclIntArray *ConvertType(const at::IntArrayRef &at_array) |
| 317 | -{ | 317 | +{ |
| 318 | - static const auto aclCreateIntArray = GET_OP_API_FUNC(aclCreateIntArray); | 318 | + static const auto aclCreateIntArray = GET_OP_API_FUNC(aclCreateIntArray); |
| 319 | - if (aclCreateIntArray == nullptr) { | 319 | + if (aclCreateIntArray == nullptr) { |
| 320 | - return nullptr; | 320 | + return nullptr; |
| 321 | - } | 321 | + } |
| 322 | - auto array = aclCreateIntArray(at_array.data(), at_array.size()); | 322 | + auto array = aclCreateIntArray(at_array.data(), at_array.size()); |
| 323 | - return array; | 323 | + return array; |
| 324 | -} | 324 | +} |
| 325 | - | 325 | + |
| 326 | -template <std::size_t N> | 326 | +template <std::size_t N> |
| 327 | -inline aclBoolArray *ConvertType(const std::array<bool, N> &value) | 327 | +inline aclBoolArray *ConvertType(const std::array<bool, N> &value) |
| 328 | -{ | 328 | +{ |
| 329 | - static const auto aclCreateBoolArray = GET_OP_API_FUNC(aclCreateBoolArray); | 329 | + static const auto aclCreateBoolArray = GET_OP_API_FUNC(aclCreateBoolArray); |
| 330 | - if (aclCreateBoolArray == nullptr) { | 330 | + if (aclCreateBoolArray == nullptr) { |
| 331 | - return nullptr; | 331 | + return nullptr; |
| 332 | - } | 332 | + } |
| 333 | - | 333 | + |
| 334 | - auto array = aclCreateBoolArray(value.data(), value.size()); | 334 | + auto array = aclCreateBoolArray(value.data(), value.size()); |
| 335 | - return array; | 335 | + return array; |
| 336 | -} | 336 | +} |
| 337 | - | 337 | + |
| 338 | -inline aclBoolArray *ConvertType(const at::ArrayRef<bool> &value) | 338 | +inline aclBoolArray *ConvertType(const at::ArrayRef<bool> &value) |
| 339 | -{ | 339 | +{ |
| 340 | - static const auto aclCreateBoolArray = GET_OP_API_FUNC(aclCreateBoolArray); | 340 | + static const auto aclCreateBoolArray = GET_OP_API_FUNC(aclCreateBoolArray); |
| 341 | - if (aclCreateBoolArray == nullptr) { | 341 | + if (aclCreateBoolArray == nullptr) { |
| 342 | - return nullptr; | 342 | + return nullptr; |
| 343 | - } | 343 | + } |
| 344 | - | 344 | + |
| 345 | - auto array = aclCreateBoolArray(value.data(), value.size()); | 345 | + auto array = aclCreateBoolArray(value.data(), value.size()); |
| 346 | - return array; | 346 | + return array; |
| 347 | -} | 347 | +} |
| 348 | - | 348 | + |
| 349 | -inline aclTensorList *ConvertType(const at::TensorList &at_tensor_list) | 349 | +inline aclTensorList *ConvertType(const at::TensorList &at_tensor_list) |
| 350 | -{ | 350 | +{ |
| 351 | - static const auto aclCreateTensorList = GET_OP_API_FUNC(aclCreateTensorList); | 351 | + static const auto aclCreateTensorList = GET_OP_API_FUNC(aclCreateTensorList); |
| 352 | - if (aclCreateTensorList == nullptr) { | 352 | + if (aclCreateTensorList == nullptr) { |
| 353 | - return nullptr; | 353 | + return nullptr; |
| 354 | - } | 354 | + } |
| 355 | - | 355 | + |
| 356 | - std::vector<const aclTensor *> tensor_list(at_tensor_list.size()); | 356 | + std::vector<const aclTensor *> tensor_list(at_tensor_list.size()); |
| 357 | - for (size_t i = 0; i < at_tensor_list.size(); i++) { | 357 | + for (size_t i = 0; i < at_tensor_list.size(); i++) { |
| 358 | - tensor_list[i] = ConvertType(at_tensor_list[i]); | 358 | + tensor_list[i] = ConvertType(at_tensor_list[i]); |
| 359 | - } | 359 | + } |
| 360 | - auto acl_tensor_list = aclCreateTensorList(tensor_list.data(), tensor_list.size()); | 360 | + auto acl_tensor_list = aclCreateTensorList(tensor_list.data(), tensor_list.size()); |
| 361 | - return acl_tensor_list; | 361 | + return acl_tensor_list; |
| 362 | -} | 362 | +} |
| 363 | - | 363 | + |
| 364 | -inline aclTensor *ConvertType(const c10::optional<at::Tensor> &opt_tensor) | 364 | +inline aclTensor *ConvertType(const c10::optional<at::Tensor> &opt_tensor) |
| 365 | -{ | 365 | +{ |
| 366 | - if (opt_tensor.has_value() && opt_tensor.value().defined()) { | 366 | + if (opt_tensor.has_value() && opt_tensor.value().defined()) { |
| 367 | - return ConvertType(opt_tensor.value()); | 367 | + return ConvertType(opt_tensor.value()); |
| 368 | - } | 368 | + } |
| 369 | - return nullptr; | 369 | + return nullptr; |
| 370 | -} | 370 | +} |
| 371 | - | 371 | + |
| 372 | -inline aclIntArray *ConvertType(const c10::optional<at::IntArrayRef> &opt_array) | 372 | +inline aclIntArray *ConvertType(const c10::optional<at::IntArrayRef> &opt_array) |
| 373 | -{ | 373 | +{ |
| 374 | - if (opt_array.has_value()) { | 374 | + if (opt_array.has_value()) { |
| 375 | - return ConvertType(opt_array.value()); | 375 | + return ConvertType(opt_array.value()); |
| 376 | - } | 376 | + } |
| 377 | - return nullptr; | 377 | + return nullptr; |
| 378 | -} | 378 | +} |
| 379 | - | 379 | + |
| 380 | -inline aclScalar *ConvertType(const c10::optional<at::Scalar> &opt_scalar) | 380 | +inline aclScalar *ConvertType(const c10::optional<at::Scalar> &opt_scalar) |
| 381 | -{ | 381 | +{ |
| 382 | - if (opt_scalar.has_value()) { | 382 | + if (opt_scalar.has_value()) { |
| 383 | - return ConvertType(opt_scalar.value()); | 383 | + return ConvertType(opt_scalar.value()); |
| 384 | - } | 384 | + } |
| 385 | - return nullptr; | 385 | + return nullptr; |
| 386 | -} | 386 | +} |
| 387 | - | 387 | + |
| 388 | -inline aclDataType ConvertType(const at::ScalarType scalarType) | 388 | +inline aclDataType ConvertType(const at::ScalarType scalarType) |
| 389 | -{ | 389 | +{ |
| 390 | - return kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(scalarType)]; | 390 | + return kATenScalarTypeToAclDataTypeTable[static_cast<int64_t>(scalarType)]; |
| 391 | -} | 391 | +} |
| 392 | - | 392 | + |
| 393 | -template <typename T> | 393 | +template <typename T> |
| 394 | -T ConvertType(T value) | 394 | +T ConvertType(T value) |
| 395 | -{ | 395 | +{ |
| 396 | - return value; | 396 | + return value; |
| 397 | -} | 397 | +} |
| 398 | - | 398 | + |
| 399 | -template <typename Tuple, size_t... I> | 399 | +template <typename Tuple, size_t... I> |
| 400 | -auto ConvertToOpApiFunc(const Tuple ¶ms, void *opApiAddr, std::index_sequence<I...>) | 400 | +auto ConvertToOpApiFunc(const Tuple ¶ms, void *opApiAddr, std::index_sequence<I...>) |
| 401 | -{ | 401 | +{ |
| 402 | - using OpApiFunc = int (*)(typename std::decay<decltype(std::get<I>(params))>::type...); | 402 | + using OpApiFunc = int (*)(typename std::decay<decltype(std::get<I>(params))>::type...); |
| 403 | - auto func = reinterpret_cast<OpApiFunc>(opApiAddr); | 403 | + auto func = reinterpret_cast<OpApiFunc>(opApiAddr); |
| 404 | - return func; | 404 | + return func; |
| 405 | -} | 405 | +} |
| 406 | - | 406 | + |
| 407 | -template <typename Tuple> | 407 | +template <typename Tuple> |
| 408 | -auto ConvertToOpApiFunc(const Tuple ¶ms, void *opApiAddr) | 408 | +auto ConvertToOpApiFunc(const Tuple ¶ms, void *opApiAddr) |
| 409 | -{ | 409 | +{ |
| 410 | - static constexpr auto size = std::tuple_size<Tuple>::value; | 410 | + static constexpr auto size = std::tuple_size<Tuple>::value; |
| 411 | - return ConvertToOpApiFunc(params, opApiAddr, std::make_index_sequence<size>{}); | 411 | + return ConvertToOpApiFunc(params, opApiAddr, std::make_index_sequence<size>{}); |
| 412 | -} | 412 | +} |
| 413 | - | 413 | + |
| 414 | -inline void Release(aclTensor *p) | 414 | +inline void Release(aclTensor *p) |
| 415 | -{ | 415 | +{ |
| 416 | - static const auto aclDestroyTensor = GET_OP_API_FUNC(aclDestroyTensor); | 416 | + static const auto aclDestroyTensor = GET_OP_API_FUNC(aclDestroyTensor); |
| 417 | - if (aclDestroyTensor == nullptr) { | 417 | + if (aclDestroyTensor == nullptr) { |
| 418 | - return; | 418 | + return; |
| 419 | - } | 419 | + } |
| 420 | - aclDestroyTensor(p); | 420 | + aclDestroyTensor(p); |
| 421 | -} | 421 | +} |
| 422 | - | 422 | + |
| 423 | -inline void Release(aclScalar *p) | 423 | +inline void Release(aclScalar *p) |
| 424 | -{ | 424 | +{ |
| 425 | - static const auto aclDestroyScalar = GET_OP_API_FUNC(aclDestroyScalar); | 425 | + static const auto aclDestroyScalar = GET_OP_API_FUNC(aclDestroyScalar); |
| 426 | - if (aclDestroyScalar == nullptr) { | 426 | + if (aclDestroyScalar == nullptr) { |
| 427 | - return; | 427 | + return; |
| 428 | - } | 428 | + } |
| 429 | - aclDestroyScalar(p); | 429 | + aclDestroyScalar(p); |
| 430 | -} | 430 | +} |
| 431 | - | 431 | + |
| 432 | -inline void Release(aclIntArray *p) | 432 | +inline void Release(aclIntArray *p) |
| 433 | -{ | 433 | +{ |
| 434 | - static const auto aclDestroyIntArray = GET_OP_API_FUNC(aclDestroyIntArray); | 434 | + static const auto aclDestroyIntArray = GET_OP_API_FUNC(aclDestroyIntArray); |
| 435 | - if (aclDestroyIntArray == nullptr) { | 435 | + if (aclDestroyIntArray == nullptr) { |
| 436 | - return; | 436 | + return; |
| 437 | - } | 437 | + } |
| 438 | - | 438 | + |
| 439 | - aclDestroyIntArray(p); | 439 | + aclDestroyIntArray(p); |
| 440 | -} | 440 | +} |
| 441 | - | 441 | + |
| 442 | -inline void Release(aclBoolArray *p) | 442 | +inline void Release(aclBoolArray *p) |
| 443 | -{ | 443 | +{ |
| 444 | - static const auto aclDestroyBoolArray = GET_OP_API_FUNC(aclDestroyBoolArray); | 444 | + static const auto aclDestroyBoolArray = GET_OP_API_FUNC(aclDestroyBoolArray); |
| 445 | - if (aclDestroyBoolArray == nullptr) { | 445 | + if (aclDestroyBoolArray == nullptr) { |
| 446 | - return; | 446 | + return; |
| 447 | - } | 447 | + } |
| 448 | - | 448 | + |
| 449 | - aclDestroyBoolArray(p); | 449 | + aclDestroyBoolArray(p); |
| 450 | -} | 450 | +} |
| 451 | - | 451 | + |
| 452 | -inline void Release(aclTensorList *p) | 452 | +inline void Release(aclTensorList *p) |
| 453 | -{ | 453 | +{ |
| 454 | - static const auto aclDestroyTensorList = GET_OP_API_FUNC(aclDestroyTensorList); | 454 | + static const auto aclDestroyTensorList = GET_OP_API_FUNC(aclDestroyTensorList); |
| 455 | - if (aclDestroyTensorList == nullptr) { | 455 | + if (aclDestroyTensorList == nullptr) { |
| 456 | - return; | 456 | + return; |
| 457 | - } | 457 | + } |
| 458 | - | 458 | + |
| 459 | - aclDestroyTensorList(p); | 459 | + aclDestroyTensorList(p); |
| 460 | -} | 460 | +} |
| 461 | - | 461 | + |
| 462 | -template <typename T> | 462 | +template <typename T> |
| 463 | -void Release(T value) | 463 | +void Release(T value) |
| 464 | -{ | 464 | +{ |
| 465 | - (void)value; | 465 | + (void)value; |
| 466 | -} | 466 | +} |
| 467 | - | 467 | + |
| 468 | -template <typename Tuple, size_t... I> | 468 | +template <typename Tuple, size_t... I> |
| 469 | -void CallRelease(Tuple t, std::index_sequence<I...>) | 469 | +void CallRelease(Tuple t, std::index_sequence<I...>) |
| 470 | -{ | 470 | +{ |
| 471 | - (void)std::initializer_list<int>{(Release(std::get<I>(t)), 0)...}; | 471 | + (void)std::initializer_list<int>{(Release(std::get<I>(t)), 0)...}; |
| 472 | -} | 472 | +} |
| 473 | - | 473 | + |
| 474 | -template <typename Tuple> | 474 | +template <typename Tuple> |
| 475 | -void ReleaseConvertTypes(Tuple &t) | 475 | +void ReleaseConvertTypes(Tuple &t) |
| 476 | -{ | 476 | +{ |
| 477 | - static constexpr auto size = std::tuple_size<Tuple>::value; | 477 | + static constexpr auto size = std::tuple_size<Tuple>::value; |
| 478 | - CallRelease(t, std::make_index_sequence<size>{}); | 478 | + CallRelease(t, std::make_index_sequence<size>{}); |
| 479 | -} | 479 | +} |
| 480 | - | 480 | + |
| 481 | -template <typename... Ts> | 481 | +template <typename... Ts> |
| 482 | -constexpr auto ConvertTypes(Ts &...args) | 482 | +constexpr auto ConvertTypes(Ts &...args) |
| 483 | -{ | 483 | +{ |
| 484 | - return std::make_tuple(ConvertType(args)...); | 484 | + return std::make_tuple(ConvertType(args)...); |
| 485 | -} | 485 | +} |
| 486 | - | 486 | + |
| 487 | -template <typename Function, typename Tuple, size_t... I> | 487 | +template <typename Function, typename Tuple, size_t... I> |
| 488 | -auto call(Function f, Tuple t, std::index_sequence<I...>) | 488 | +auto call(Function f, Tuple t, std::index_sequence<I...>) |
| 489 | -{ | 489 | +{ |
| 490 | - return f(std::get<I>(t)...); | 490 | + return f(std::get<I>(t)...); |
| 491 | -} | 491 | +} |
| 492 | - | 492 | + |
| 493 | -template <typename Function, typename Tuple> | 493 | +template <typename Function, typename Tuple> |
| 494 | -auto call(Function f, Tuple t) | 494 | +auto call(Function f, Tuple t) |
| 495 | -{ | 495 | +{ |
| 496 | - static constexpr auto size = std::tuple_size<Tuple>::value; | 496 | + static constexpr auto size = std::tuple_size<Tuple>::value; |
| 497 | - return call(f, t, std::make_index_sequence<size>{}); | 497 | + return call(f, t, std::make_index_sequence<size>{}); |
| 498 | -} | 498 | +} |
| 499 | - | 499 | + |
| 500 | -template <std::size_t N> | 500 | +template <std::size_t N> |
| 501 | -void AddParamToBuf(const std::array<bool, N> &value) | 501 | +void AddParamToBuf(const std::array<bool, N> &value) |
| 502 | -{ | 502 | +{ |
| 503 | - MEMCPY_TO_BUF(value.data(), value.size() * sizeof(bool)); | 503 | + MEMCPY_TO_BUF(value.data(), value.size() * sizeof(bool)); |
| 504 | -} | 504 | +} |
| 505 | - | 505 | + |
| 506 | -template <typename T> | 506 | +template <typename T> |
| 507 | -void AddParamToBuf(const T &value) | 507 | +void AddParamToBuf(const T &value) |
| 508 | -{ | 508 | +{ |
| 509 | - MEMCPY_TO_BUF(&value, sizeof(T)); | 509 | + MEMCPY_TO_BUF(&value, sizeof(T)); |
| 510 | -} | 510 | +} |
| 511 | - | 511 | + |
| 512 | -void AddParamToBuf(const at::Tensor &); | 512 | +void AddParamToBuf(const at::Tensor &); |
| 513 | -void AddParamToBuf(const at::Scalar &); | 513 | +void AddParamToBuf(const at::Scalar &); |
| 514 | -void AddParamToBuf(const at::IntArrayRef &); | 514 | +void AddParamToBuf(const at::IntArrayRef &); |
| 515 | -void AddParamToBuf(const at::ArrayRef<bool> &); | 515 | +void AddParamToBuf(const at::ArrayRef<bool> &); |
| 516 | -void AddParamToBuf(const at::TensorList &); | 516 | +void AddParamToBuf(const at::TensorList &); |
| 517 | -void AddParamToBuf(const c10::optional<at::Tensor> &); | 517 | +void AddParamToBuf(const c10::optional<at::Tensor> &); |
| 518 | -void AddParamToBuf(const c10::optional<at::IntArrayRef> &); | 518 | +void AddParamToBuf(const c10::optional<at::IntArrayRef> &); |
| 519 | -void AddParamToBuf(const c10::optional<at::Scalar> &); | 519 | +void AddParamToBuf(const c10::optional<at::Scalar> &); |
| 520 | -void AddParamToBuf(const at::ScalarType); | 520 | +void AddParamToBuf(const at::ScalarType); |
| 521 | -void AddParamToBuf(const string &); | 521 | +void AddParamToBuf(const string &); |
| 522 | -void AddParamToBuf(); | 522 | +void AddParamToBuf(); |
| 523 | - | 523 | + |
| 524 | -template <typename T, typename... Args> | 524 | +template <typename T, typename... Args> |
| 525 | -void AddParamToBuf(const T &arg, Args &...args) | 525 | +void AddParamToBuf(const T &arg, Args &...args) |
| 526 | -{ | 526 | +{ |
| 527 | - AddParamToBuf(arg); | 527 | + AddParamToBuf(arg); |
| 528 | - AddParamToBuf(args...); | 528 | + AddParamToBuf(args...); |
| 529 | -} | 529 | +} |
| 530 | - | 530 | + |
| 531 | -uint64_t CalcHashId(); | 531 | +uint64_t CalcHashId(); |
| 532 | -using InitHugeMemThreadLocal = int (*)(void *, bool); | 532 | +using InitHugeMemThreadLocal = int (*)(void *, bool); |
| 533 | -using UnInitHugeMemThreadLocal = void (*)(void *, bool); | 533 | +using UnInitHugeMemThreadLocal = void (*)(void *, bool); |
| 534 | -using ReleaseHugeMem = void (*)(void *, bool); | 534 | +using ReleaseHugeMem = void (*)(void *, bool); |
| 535 | - | 535 | + |
| 536 | -#define ACLNN_CMD(aclnn_api, ...) \ | 536 | +#define ACLNN_CMD(aclnn_api, ...) \ |
| 537 | - do { \ | 537 | + do { \ |
| 538 | - static const auto getWorkspaceSizeFuncAddr = GetOpApiFuncAddr(#aclnn_api "GetWorkspaceSize"); \ | 538 | + static const auto getWorkspaceSizeFuncAddr = GetOpApiFuncAddr(#aclnn_api "GetWorkspaceSize"); \ |
| 539 | - static const auto opApiFuncAddr = GetOpApiFuncAddr(#aclnn_api); \ | 539 | + static const auto opApiFuncAddr = GetOpApiFuncAddr(#aclnn_api); \ |
| 540 | - static const auto initMemAddr = GetOpApiFuncAddr("InitHugeMemThreadLocal"); \ | 540 | + static const auto initMemAddr = GetOpApiFuncAddr("InitHugeMemThreadLocal"); \ |
| 541 | - static const auto unInitMemAddr = GetOpApiFuncAddr("UnInitHugeMemThreadLocal"); \ | 541 | + static const auto unInitMemAddr = GetOpApiFuncAddr("UnInitHugeMemThreadLocal"); \ |
| 542 | - static const auto releaseMemAddr = GetOpApiFuncAddr("ReleaseHugeMem"); \ | 542 | + static const auto releaseMemAddr = GetOpApiFuncAddr("ReleaseHugeMem"); \ |
| 543 | - TORCH_CHECK(getWorkspaceSizeFuncAddr != nullptr && opApiFuncAddr != nullptr, \ | 543 | + TORCH_CHECK(getWorkspaceSizeFuncAddr != nullptr && opApiFuncAddr != nullptr, \ |
| 544 | - #aclnn_api, \ | 544 | + #aclnn_api, \ |
| 545 | - " or ", \ | 545 | + " or ", \ |
| 546 | - #aclnn_api "GetWorkspaceSize", \ | 546 | + #aclnn_api "GetWorkspaceSize", \ |
| 547 | - " not in ", \ | 547 | + " not in ", \ |
| 548 | - GetOpApiLibName(), \ | 548 | + GetOpApiLibName(), \ |
| 549 | - ", or ", \ | 549 | + ", or ", \ |
| 550 | - GetOpApiLibName(), \ | 550 | + GetOpApiLibName(), \ |
| 551 | - "not found."); \ | 551 | + "not found."); \ |
| 552 | - auto acl_stream = c10_npu::getCurrentNPUStream().stream(false); \ | 552 | + auto acl_stream = c10_npu::getCurrentNPUStream().stream(false); \ |
| 553 | - uint64_t workspace_size = 0; \ | 553 | + uint64_t workspace_size = 0; \ |
| 554 | - uint64_t *workspace_size_addr = &workspace_size; \ | 554 | + uint64_t *workspace_size_addr = &workspace_size; \ |
| 555 | - aclOpExecutor *executor = nullptr; \ | 555 | + aclOpExecutor *executor = nullptr; \ |
| 556 | - aclOpExecutor **executor_addr = &executor; \ | 556 | + aclOpExecutor **executor_addr = &executor; \ |
| 557 | - InitHugeMemThreadLocal initMemFunc = reinterpret_cast<InitHugeMemThreadLocal>(initMemAddr); \ | 557 | + InitHugeMemThreadLocal initMemFunc = reinterpret_cast<InitHugeMemThreadLocal>(initMemAddr); \ |
| 558 | - UnInitHugeMemThreadLocal unInitMemFunc = reinterpret_cast<UnInitHugeMemThreadLocal>(unInitMemAddr); \ | 558 | + UnInitHugeMemThreadLocal unInitMemFunc = reinterpret_cast<UnInitHugeMemThreadLocal>(unInitMemAddr); \ |
| 559 | - if (initMemFunc) { \ | 559 | + if (initMemFunc) { \ |
| 560 | - initMemFunc(nullptr, false); \ | 560 | + initMemFunc(nullptr, false); \ |
| 561 | - } \ | 561 | + } \ |
| 562 | - auto converted_params = ConvertTypes(__VA_ARGS__, workspace_size_addr, executor_addr); \ | 562 | + auto converted_params = ConvertTypes(__VA_ARGS__, workspace_size_addr, executor_addr); \ |
| 563 | - static auto getWorkspaceSizeFunc = ConvertToOpApiFunc(converted_params, getWorkspaceSizeFuncAddr); \ | 563 | + static auto getWorkspaceSizeFunc = ConvertToOpApiFunc(converted_params, getWorkspaceSizeFuncAddr); \ |
| 564 | - auto workspace_status = call(getWorkspaceSizeFunc, converted_params); \ | 564 | + auto workspace_status = call(getWorkspaceSizeFunc, converted_params); \ |
| 565 | - TORCH_CHECK(workspace_status == 0, "call " #aclnn_api " failed, detail:", aclGetRecentErrMsg()); \ | 565 | + TORCH_CHECK(workspace_status == 0, "call " #aclnn_api " failed, detail:", aclGetRecentErrMsg()); \ |
| 566 | - void *workspace_addr = nullptr; \ | 566 | + void *workspace_addr = nullptr; \ |
| 567 | - if (workspace_size != 0) { \ | 567 | + if (workspace_size != 0) { \ |
| 568 | - at::TensorOptions options = at::TensorOptions(torch_npu::utils::get_npu_device_type()); \ | 568 | + at::TensorOptions options = at::TensorOptions(torch_npu::utils::get_npu_device_type()); \ |
| 569 | - auto workspace_tensor = at::empty({workspace_size}, options.dtype(at::kByte)); \ | 569 | + auto workspace_tensor = at::empty({workspace_size}, options.dtype(at::kByte)); \ |
| 570 | - workspace_addr = const_cast<void *>(workspace_tensor.storage().data()); \ | 570 | + workspace_addr = const_cast<void *>(workspace_tensor.storage().data()); \ |
| 571 | - } \ | 571 | + } \ |
| 572 | - auto acl_call = [converted_params, workspace_addr, workspace_size, acl_stream, executor]() -> int { \ | 572 | + auto acl_call = [converted_params, workspace_addr, workspace_size, acl_stream, executor]() -> int { \ |
| 573 | - typedef int (*OpApiFunc)(void *, uint64_t, aclOpExecutor *, const aclrtStream); \ | 573 | + typedef int (*OpApiFunc)(void *, uint64_t, aclOpExecutor *, const aclrtStream); \ |
| 574 | - OpApiFunc opApiFunc = reinterpret_cast<OpApiFunc>(opApiFuncAddr); \ | 574 | + OpApiFunc opApiFunc = reinterpret_cast<OpApiFunc>(opApiFuncAddr); \ |
| 575 | - auto api_ret = opApiFunc(workspace_addr, workspace_size, executor, acl_stream); \ | 575 | + auto api_ret = opApiFunc(workspace_addr, workspace_size, executor, acl_stream); \ |
| 576 | - TORCH_CHECK(api_ret == 0, "call " #aclnn_api " failed, detail:", aclGetRecentErrMsg()); \ | 576 | + TORCH_CHECK(api_ret == 0, "call " #aclnn_api " failed, detail:", aclGetRecentErrMsg()); \ |
| 577 | - ReleaseConvertTypes(converted_params); \ | 577 | + ReleaseConvertTypes(converted_params); \ |
| 578 | - ReleaseHugeMem releaseMemFunc = reinterpret_cast<ReleaseHugeMem>(releaseMemAddr); \ | 578 | + ReleaseHugeMem releaseMemFunc = reinterpret_cast<ReleaseHugeMem>(releaseMemAddr); \ |
| 579 | - if (releaseMemFunc) { \ | 579 | + if (releaseMemFunc) { \ |
| 580 | - releaseMemFunc(nullptr, false); \ | 580 | + releaseMemFunc(nullptr, false); \ |
| 581 | - } \ | 581 | + } \ |
| 582 | - return api_ret; \ | 582 | + return api_ret; \ |
| 583 | - }; \ | 583 | + }; \ |
| 584 | - at_npu::native::OpCommand cmd; \ | 584 | + at_npu::native::OpCommand cmd; \ |
| 585 | - cmd.Name(#aclnn_api); \ | 585 | + cmd.Name(#aclnn_api); \ |
| 586 | - cmd.SetCustomHandler(acl_call); \ | 586 | + cmd.SetCustomHandler(acl_call); \ |
| 587 | - cmd.Run(); \ | 587 | + cmd.Run(); \ |
| 588 | - if (unInitMemFunc) { \ | 588 | + if (unInitMemFunc) { \ |
| 589 | - unInitMemFunc(nullptr, false); \ | 589 | + unInitMemFunc(nullptr, false); \ |
| 590 | - } \ | 590 | + } \ |
| 591 | - } while (false) | 591 | + } while (false) |
| 592 | - | 592 | + |
| 593 | -#endif // ASCENDSPEED_OPS_CSRC_CANN_INC_ACL_COMMON_H | 593 | +#endif // MINDSPEED_OPS_CSRC_CANN_INC_ACL_COMMON_H |
Rascendspeed/ops/csrc/cann/npu_dropout_add_layer_norm.cpp→mindspeed/ops/csrc/cann/npu_dropout_add_layer_norm.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/cann/npu_mm_all_reduce_add_rms_norm.cpp→mindspeed/ops/csrc/cann/npu_mm_all_reduce_add_rms_norm.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/cann/npu_mm_all_reduce_add_rms_norm_.cpp→mindspeed/ops/csrc/cann/npu_mm_all_reduce_add_rms_norm_.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/adaptive_recomputing/NpuCachingCustomAllocator.cpp→mindspeed/ops/csrc/pluggable_allocator/adaptive_recomputing/NpuCachingCustomAllocator.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/adaptive_recomputing/NpuCachingCustomAllocator.h→mindspeed/ops/csrc/pluggable_allocator/adaptive_recomputing/NpuCachingCustomAllocator.h+2-2
| @@ -524,10 +524,10 @@ class DeviceCachingAllocator { | |||
| 524 | break; | 524 | break; |
| 525 | } | 525 | } |
| 526 | PyGILState_STATE state = PyGILState_Ensure(); | 526 | PyGILState_STATE state = PyGILState_Ensure(); |
| 527 | - PyObject *pModule = PyImport_ImportModule("ascendspeed.core.memory.adaptive_recomputing.swap_manager"); | 527 | + PyObject *pModule = PyImport_ImportModule("mindspeed.core.memory.adaptive_recomputing.swap_manager"); |
| 528 | if (!pModule) { | 528 | if (!pModule) { |
| 529 | PyGILState_Release(state); | 529 | PyGILState_Release(state); |
| 530 | - std::cout << "No Ascendspeed Module" << std::endl; | 530 | + std::cout << "No MindSpeed Module" << std::endl; |
| 531 | break; | 531 | break; |
| 532 | } | 532 | } |
| 533 | PyObject *pFunc1 = PyObject_GetAttrString(pModule, "SwapManager"); | 533 | PyObject *pFunc1 = PyObject_GetAttrString(pModule, "SwapManager"); |
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/CachingAllocatorConfig.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/CachingAllocatorConfig.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/CachingAllocatorConfig.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/CachingAllocatorConfig.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Decorator.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Decorator.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Decorator.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Decorator.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/DeviceCachingAllocator.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/DeviceCachingAllocator.cpp+2-2
| @@ -219,9 +219,9 @@ Block* DeviceCachingAllocator::malloc_internal(int device, size_t orig_size, acl | |||
| 219 | break; | 219 | break; |
| 220 | } | 220 | } |
| 221 | PyGILState_STATE state = PyGILState_Ensure(); | 221 | PyGILState_STATE state = PyGILState_Ensure(); |
| 222 | - PyObject *pModule = PyImport_ImportModule("ascendspeed.core.memory.adaptive_recomputing.swap_manager"); | 222 | + PyObject *pModule = PyImport_ImportModule("mindspeed.core.memory.adaptive_recomputing.swap_manager"); |
| 223 | if (!pModule) { | 223 | if (!pModule) { |
| 224 | - std::cout << "No Ascendspeed Module" << std::endl; | 224 | + std::cout << "No MindSpeed Module" << std::endl; |
| 225 | PyGILState_Release(state); | 225 | PyGILState_Release(state); |
| 226 | break; | 226 | break; |
| 227 | } | 227 | } |
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/DeviceCachingAllocator.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/DeviceCachingAllocator.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/EventPool.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/EventPool.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/EventPool.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/EventPool.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/PluggableAllocator.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/PluggableAllocator.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/PluggableAllocator.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/PluggableAllocator.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/PluggableAllocatorFunctions.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/PluggableAllocatorFunctions.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Recorder.cpp→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Recorder.cpp+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Recorder.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/Recorder.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/common.h→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/common.h+0-0
文件重命名但无更改。
Rascendspeed/ops/csrc/pluggable_allocator/memory_fragmentation/test.py→mindspeed/ops/csrc/pluggable_allocator/memory_fragmentation/test.py+1-1
| @@ -1,7 +1,7 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | import torch_npu | 2 | import torch_npu |
| 3 | import ctypes | 3 | import ctypes |
| 4 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 4 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 5 | 5 | ||
| 6 | os_path = load_memory_fragmentation_module().__file__ | 6 | os_path = load_memory_fragmentation_module().__file__ |
| 7 | new_alloc = torch_npu.npu.memory.NPUPluggableAllocator(os_path, 'memory_fragmentation_malloc', 'memory_fragmentation_free') | 7 | new_alloc = torch_npu.npu.memory.NPUPluggableAllocator(os_path, 'memory_fragmentation_malloc', 'memory_fragmentation_free') |
| @@ -1,47 +1,47 @@ | |||
| 1 | -import torch | 1 | +import torch |
| 2 | -import torch_npu | 2 | +import torch_npu |
| 3 | -from ascendspeed.op_builder import NpuDropoutAddLayerNormOpBuilder | 3 | +from mindspeed.op_builder import NpuDropoutAddLayerNormOpBuilder |
| 4 | - | 4 | + |
| 5 | - | 5 | + |
| 6 | -def npu_dropout_add_layer_norm(x0, | 6 | +def npu_dropout_add_layer_norm(x0, |
| 7 | - residual, | 7 | + residual, |
| 8 | - weight, | 8 | + weight, |
| 9 | - bias, | 9 | + bias, |
| 10 | - dropout_p, | 10 | + dropout_p, |
| 11 | - epsilon, | 11 | + epsilon, |
| 12 | - rowscale=None, | 12 | + rowscale=None, |
| 13 | - layerscale=None, | 13 | + layerscale=None, |
| 14 | - prenorm=False, | 14 | + prenorm=False, |
| 15 | - residual_in_fp32=False, | 15 | + residual_in_fp32=False, |
| 16 | - return_dropout_mask=False): | 16 | + return_dropout_mask=False): |
| 17 | - ascendspeed_ops = NpuDropoutAddLayerNormOpBuilder().load() | 17 | + mindspeed_ops = NpuDropoutAddLayerNormOpBuilder().load() |
| 18 | - is_rms_norm = False | 18 | + is_rms_norm = False |
| 19 | - out, pre_norm, dmask = ascendspeed_ops.npu_dropout_add_layer_norm( | 19 | + out, pre_norm, dmask = mindspeed_ops.npu_dropout_add_layer_norm( |
| 20 | - x0, | 20 | + x0, |
| 21 | - weight, | 21 | + weight, |
| 22 | - residual, | 22 | + residual, |
| 23 | - bias, | 23 | + bias, |
| 24 | - rowscale, | 24 | + rowscale, |
| 25 | - layerscale, | 25 | + layerscale, |
| 26 | - dropout_p, | 26 | + dropout_p, |
| 27 | - epsilon, | 27 | + epsilon, |
| 28 | - prenorm, | 28 | + prenorm, |
| 29 | - residual_in_fp32, | 29 | + residual_in_fp32, |
| 30 | - is_rms_norm, | 30 | + is_rms_norm, |
| 31 | - return_dropout_mask | 31 | + return_dropout_mask |
| 32 | - ) | 32 | + ) |
| 33 | - if not return_dropout_mask: | 33 | + if not return_dropout_mask: |
| 34 | - return ( | 34 | + return ( |
| 35 | - out.view(x0.shape) if not prenorm else (out.view(x0.shape), pre_norm.view(x0.shape)) | 35 | + out.view(x0.shape) if not prenorm else (out.view(x0.shape), pre_norm.view(x0.shape)) |
| 36 | - ) | 36 | + ) |
| 37 | - else: | 37 | + else: |
| 38 | - dmask = ( | 38 | + dmask = ( |
| 39 | - dmask.view(x0.shape) | 39 | + dmask.view(x0.shape) |
| 40 | - if dropout_p > 0.0 | 40 | + if dropout_p > 0.0 |
| 41 | - else torch.ones(x0.shape, dtype=torch.uint8, device=x0.device) | 41 | + else torch.ones(x0.shape, dtype=torch.uint8, device=x0.device) |
| 42 | - ) | 42 | + ) |
| 43 | - return ( | 43 | + return ( |
| 44 | - (out.view(x0.shape), dmask) | 44 | + (out.view(x0.shape), dmask) |
| 45 | - if not prenorm | 45 | + if not prenorm |
| 46 | - else (out.view(x0.shape), pre_norm.view(x0.shape), dmask) | 46 | + else (out.view(x0.shape), pre_norm.view(x0.shape), dmask) |
| 47 | ) | 47 | ) |
| @@ -1,47 +1,47 @@ | |||
| 1 | -import torch | 1 | +import torch |
| 2 | -import torch_npu | 2 | +import torch_npu |
| 3 | -from ascendspeed.op_builder import NpuDropoutAddLayerNormOpBuilder | 3 | +from mindspeed.op_builder import NpuDropoutAddLayerNormOpBuilder |
| 4 | - | 4 | + |
| 5 | - | 5 | + |
| 6 | -def npu_dropout_add_rms_norm(x0, | 6 | +def npu_dropout_add_rms_norm(x0, |
| 7 | - residual, | 7 | + residual, |
| 8 | - weight, | 8 | + weight, |
| 9 | - bias, | 9 | + bias, |
| 10 | - dropout_p, | 10 | + dropout_p, |
| 11 | - epsilon, | 11 | + epsilon, |
| 12 | - rowscale=None, | 12 | + rowscale=None, |
| 13 | - layerscale=None, | 13 | + layerscale=None, |
| 14 | - prenorm=False, | 14 | + prenorm=False, |
| 15 | - residual_in_fp32=False, | 15 | + residual_in_fp32=False, |
| 16 | - return_dropout_mask=False): | 16 | + return_dropout_mask=False): |
| 17 | - ascendspeed_ops = NpuDropoutAddLayerNormOpBuilder().load() | 17 | + mindspeed_ops = NpuDropoutAddLayerNormOpBuilder().load() |
| 18 | - is_rms_norm = True | 18 | + is_rms_norm = True |
| 19 | - out, pre_norm, dmask = ascendspeed_ops.npu_dropout_add_layer_norm( | 19 | + out, pre_norm, dmask = mindspeed_ops.npu_dropout_add_layer_norm( |
| 20 | - x0, | 20 | + x0, |
| 21 | - weight, | 21 | + weight, |
| 22 | - residual, | 22 | + residual, |
| 23 | - bias, | 23 | + bias, |
| 24 | - rowscale, | 24 | + rowscale, |
| 25 | - layerscale, | 25 | + layerscale, |
| 26 | - dropout_p, | 26 | + dropout_p, |
| 27 | - epsilon, | 27 | + epsilon, |
| 28 | - prenorm, | 28 | + prenorm, |
| 29 | - residual_in_fp32, | 29 | + residual_in_fp32, |
| 30 | - is_rms_norm, | 30 | + is_rms_norm, |
| 31 | - return_dropout_mask | 31 | + return_dropout_mask |
| 32 | - ) | 32 | + ) |
| 33 | - if not return_dropout_mask: | 33 | + if not return_dropout_mask: |
| 34 | - return ( | 34 | + return ( |
| 35 | - out.view(x0.shape) if not prenorm else (out.view(x0.shape), pre_norm.view(x0.shape)) | 35 | + out.view(x0.shape) if not prenorm else (out.view(x0.shape), pre_norm.view(x0.shape)) |
| 36 | - ) | 36 | + ) |
| 37 | - else: | 37 | + else: |
| 38 | - dmask = ( | 38 | + dmask = ( |
| 39 | - dmask.view(x0.shape) | 39 | + dmask.view(x0.shape) |
| 40 | - if dropout_p > 0.0 | 40 | + if dropout_p > 0.0 |
| 41 | - else torch.ones(x0.shape, dtype=torch.uint8, device=x0.device) | 41 | + else torch.ones(x0.shape, dtype=torch.uint8, device=x0.device) |
| 42 | - ) | 42 | + ) |
| 43 | - return ( | 43 | + return ( |
| 44 | - (out.view(x0.shape), dmask) | 44 | + (out.view(x0.shape), dmask) |
| 45 | - if not prenorm | 45 | + if not prenorm |
| 46 | - else (out.view(x0.shape), pre_norm.view(x0.shape), dmask) | 46 | + else (out.view(x0.shape), pre_norm.view(x0.shape), dmask) |
| 47 | ) | 47 | ) |
| @@ -1,77 +1,77 @@ | |||
| 1 | -import torch | 1 | +import torch |
| 2 | -from ascendspeed.op_builder import FusionAttentionV2OpBuilder | 2 | +from mindspeed.op_builder import FusionAttentionV2OpBuilder |
| 3 | - | 3 | + |
| 4 | - | 4 | + |
| 5 | -class FusionAttentionV2Function(torch.autograd.Function): | 5 | +class FusionAttentionV2Function(torch.autograd.Function): |
| 6 | - ascendspeed_ops = FusionAttentionV2OpBuilder().load() | 6 | + mindspeed_ops = FusionAttentionV2OpBuilder().load() |
| 7 | - | 7 | + |
| 8 | - @staticmethod | 8 | + @staticmethod |
| 9 | - def forward(ctx, query, key, value, head_num, input_layout, pse, padding_mask, atten_mask, scale, keep_prob, | 9 | + def forward(ctx, query, key, value, head_num, input_layout, pse, padding_mask, atten_mask, scale, keep_prob, |
| 10 | - pre_tokens, next_tokens, inner_precise, prefix, actual_seq_qlen, actual_seq_kvlen, sparse_mode, | 10 | + pre_tokens, next_tokens, inner_precise, prefix, actual_seq_qlen, actual_seq_kvlen, sparse_mode, |
| 11 | - gen_mask_parallel, sync, pse_type, q_start_idx, kv_start_idx): | 11 | + gen_mask_parallel, sync, pse_type, q_start_idx, kv_start_idx): |
| 12 | - outputs = FusionAttentionV2Function.ascendspeed_ops.npu_fusion_attention_v2(query, key, value, head_num, | 12 | + outputs = FusionAttentionV2Function.mindspeed_ops.npu_fusion_attention_v2(query, key, value, head_num, |
| 13 | - input_layout, pse, | 13 | + input_layout, pse, |
| 14 | - padding_mask, atten_mask, | 14 | + padding_mask, atten_mask, |
| 15 | - scale, keep_prob, pre_tokens, | 15 | + scale, keep_prob, pre_tokens, |
| 16 | - next_tokens, inner_precise, prefix, | 16 | + next_tokens, inner_precise, prefix, |
| 17 | - actual_seq_qlen, actual_seq_kvlen, | 17 | + actual_seq_qlen, actual_seq_kvlen, |
| 18 | - sparse_mode, gen_mask_parallel, | 18 | + sparse_mode, gen_mask_parallel, |
| 19 | - sync, pse_type, q_start_idx, | 19 | + sync, pse_type, q_start_idx, |
| 20 | - kv_start_idx) | 20 | + kv_start_idx) |
| 21 | - attention_in, softmax_max, softmax_sum, softmax_in, seed, offset, numels = outputs | 21 | + attention_in, softmax_max, softmax_sum, softmax_in, seed, offset, numels = outputs |
| 22 | - ctx.save_for_backward(query, key, value, pse, padding_mask, atten_mask, attention_in, | 22 | + ctx.save_for_backward(query, key, value, pse, padding_mask, atten_mask, attention_in, |
| 23 | - softmax_max, softmax_sum, softmax_in) | 23 | + softmax_max, softmax_sum, softmax_in) |
| 24 | - ctx.scale = scale | 24 | + ctx.scale = scale |
| 25 | - ctx.input_layout = input_layout | 25 | + ctx.input_layout = input_layout |
| 26 | - ctx.head_num = head_num | 26 | + ctx.head_num = head_num |
| 27 | - ctx.pre_tokens = pre_tokens | 27 | + ctx.pre_tokens = pre_tokens |
| 28 | - ctx.next_tokens = next_tokens | 28 | + ctx.next_tokens = next_tokens |
| 29 | - ctx.inner_precise = inner_precise | 29 | + ctx.inner_precise = inner_precise |
| 30 | - ctx.gen_mask_parallel = gen_mask_parallel | 30 | + ctx.gen_mask_parallel = gen_mask_parallel |
| 31 | - ctx.sync = sync | 31 | + ctx.sync = sync |
| 32 | - ctx.seed = seed | 32 | + ctx.seed = seed |
| 33 | - ctx.offset = offset | 33 | + ctx.offset = offset |
| 34 | - ctx.numels = numels | 34 | + ctx.numels = numels |
| 35 | - ctx.prefix = prefix | 35 | + ctx.prefix = prefix |
| 36 | - ctx.keep_prob = keep_prob | 36 | + ctx.keep_prob = keep_prob |
| 37 | - ctx.actual_seq_qlen = actual_seq_qlen | 37 | + ctx.actual_seq_qlen = actual_seq_qlen |
| 38 | - ctx.actual_seq_kvlen = actual_seq_kvlen | 38 | + ctx.actual_seq_kvlen = actual_seq_kvlen |
| 39 | - ctx.sparse_mode = sparse_mode | 39 | + ctx.sparse_mode = sparse_mode |
| 40 | - ctx.pse_type = pse_type | 40 | + ctx.pse_type = pse_type |
| 41 | - ctx.q_start_idx = q_start_idx | 41 | + ctx.q_start_idx = q_start_idx |
| 42 | - ctx.kv_start_idx = kv_start_idx | 42 | + ctx.kv_start_idx = kv_start_idx |
| 43 | - | 43 | + |
| 44 | - return outputs | 44 | + return outputs |
| 45 | - | 45 | + |
| 46 | - @staticmethod | 46 | + @staticmethod |
| 47 | - def backward(ctx, grad_outputs, dq=None, dk=None, dv=None, seed=0, offset=0, numels=0): | 47 | + def backward(ctx, grad_outputs, dq=None, dk=None, dv=None, seed=0, offset=0, numels=0): |
| 48 | - query, key, value, pse, padding_mask, atten_mask, attention_in, softmax_max, \ | 48 | + query, key, value, pse, padding_mask, atten_mask, attention_in, softmax_max, \ |
| 49 | - softmax_sum, softmax_in = ctx.saved_tensors | 49 | + softmax_sum, softmax_in = ctx.saved_tensors |
| 50 | - results = FusionAttentionV2Function.ascendspeed_ops.npu_fusion_attention_grad_v2( | 50 | + results = FusionAttentionV2Function.mindspeed_ops.npu_fusion_attention_grad_v2( |
| 51 | - query, key, value, grad_outputs, ctx.head_num, ctx.input_layout, pse, padding_mask, atten_mask, | 51 | + query, key, value, grad_outputs, ctx.head_num, ctx.input_layout, pse, padding_mask, atten_mask, |
| 52 | - softmax_max, softmax_sum, softmax_in, attention_in, ctx.scale, ctx.keep_prob, ctx.pre_tokens, | 52 | + softmax_max, softmax_sum, softmax_in, attention_in, ctx.scale, ctx.keep_prob, ctx.pre_tokens, |
| 53 | - ctx.next_tokens, ctx.inner_precise, ctx.seed, ctx.offset, ctx.numels, ctx.prefix, ctx.actual_seq_qlen, | 53 | + ctx.next_tokens, ctx.inner_precise, ctx.seed, ctx.offset, ctx.numels, ctx.prefix, ctx.actual_seq_qlen, |
| 54 | - ctx.actual_seq_kvlen, ctx.sparse_mode, ctx.gen_mask_parallel, ctx.sync, ctx.pse_type, ctx.q_start_idx, | 54 | + ctx.actual_seq_kvlen, ctx.sparse_mode, ctx.gen_mask_parallel, ctx.sync, ctx.pse_type, ctx.q_start_idx, |
| 55 | - ctx.kv_start_idx) | 55 | + ctx.kv_start_idx) |
| 56 | - | 56 | + |
| 57 | - return results[0], results[1], results[2], None, None, results[3], None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None | 57 | + return results[0], results[1], results[2], None, None, results[3], None, None, None, None, None, None, None, None, None, None, None, None, None, None, None, None |
| 58 | - | 58 | + |
| 59 | - | 59 | + |
| 60 | -def npu_fusion_attention(query, key, value, head_num, | 60 | +def npu_fusion_attention(query, key, value, head_num, |
| 61 | - input_layout, *, pse=None, | 61 | + input_layout, *, pse=None, |
| 62 | - padding_mask=None, atten_mask=None, | 62 | + padding_mask=None, atten_mask=None, |
| 63 | - scale=1., keep_prob=1., pre_tokens=2147483647, | 63 | + scale=1., keep_prob=1., pre_tokens=2147483647, |
| 64 | - next_tokens=2147483647, inner_precise=0, prefix=None, | 64 | + next_tokens=2147483647, inner_precise=0, prefix=None, |
| 65 | - actual_seq_qlen=None, actual_seq_kvlen=None, | 65 | + actual_seq_qlen=None, actual_seq_kvlen=None, |
| 66 | - sparse_mode=0, gen_mask_parallel=True, | 66 | + sparse_mode=0, gen_mask_parallel=True, |
| 67 | - sync=False, pse_type=1, q_start_idx=None, | 67 | + sync=False, pse_type=1, q_start_idx=None, |
| 68 | - kv_start_idx=None): | 68 | + kv_start_idx=None): |
| 69 | - return FusionAttentionV2Function.apply(query, key, value, head_num, | 69 | + return FusionAttentionV2Function.apply(query, key, value, head_num, |
| 70 | - input_layout, pse, | 70 | + input_layout, pse, |
| 71 | - padding_mask, atten_mask, | 71 | + padding_mask, atten_mask, |
| 72 | - scale, keep_prob, pre_tokens, | 72 | + scale, keep_prob, pre_tokens, |
| 73 | - next_tokens, inner_precise, prefix, | 73 | + next_tokens, inner_precise, prefix, |
| 74 | - actual_seq_qlen, actual_seq_kvlen, | 74 | + actual_seq_qlen, actual_seq_kvlen, |
| 75 | - sparse_mode, gen_mask_parallel, | 75 | + sparse_mode, gen_mask_parallel, |
| 76 | - sync, pse_type, q_start_idx, | 76 | + sync, pse_type, q_start_idx, |
| 77 | - kv_start_idx) | 77 | + kv_start_idx) |
| @@ -1,44 +1,44 @@ | |||
| 1 | -from typing import List | 1 | +from typing import List |
| 2 | -import torch | 2 | +import torch |
| 3 | -from ascendspeed.op_builder import GMMOpBuilder | 3 | +from mindspeed.op_builder import GMMOpBuilder |
| 4 | - | 4 | + |
| 5 | - | 5 | + |
| 6 | -class GMMFunction(torch.autograd.Function): | 6 | +class GMMFunction(torch.autograd.Function): |
| 7 | - ascendspeed_ops = GMMOpBuilder().load() | 7 | + mindspeed_ops = GMMOpBuilder().load() |
| 8 | - | 8 | + |
| 9 | - @staticmethod | 9 | + @staticmethod |
| 10 | - def forward(ctx, x, weight, bias, group_list, group_type): | 10 | + def forward(ctx, x, weight, bias, group_list, group_type): |
| 11 | - if bias is not None and bias.requires_grad: | 11 | + if bias is not None and bias.requires_grad: |
| 12 | - raise ValueError("Bias is not supported to compute gradient!") | 12 | + raise ValueError("Bias is not supported to compute gradient!") |
| 13 | - if (x.requires_grad or weight.requires_grad) and group_type != 0: | 13 | + if (x.requires_grad or weight.requires_grad) and group_type != 0: |
| 14 | - raise ValueError("group_type must be zero to compute gradients of x and weight!") | 14 | + raise ValueError("group_type must be zero to compute gradients of x and weight!") |
| 15 | - bias = [] if bias is None else [bias] | 15 | + bias = [] if bias is None else [bias] |
| 16 | - outputs = GMMFunction.ascendspeed_ops.npu_gmm([x], [weight], bias, group_list, group_type) | 16 | + outputs = GMMFunction.mindspeed_ops.npu_gmm([x], [weight], bias, group_list, group_type) |
| 17 | - ctx.save_for_backward(x, weight) | 17 | + ctx.save_for_backward(x, weight) |
| 18 | - ctx.group_list = group_list | 18 | + ctx.group_list = group_list |
| 19 | - | 19 | + |
| 20 | - return outputs[0] | 20 | + return outputs[0] |
| 21 | - | 21 | + |
| 22 | - @staticmethod | 22 | + @staticmethod |
| 23 | - def backward(ctx, grad_outputs): | 23 | + def backward(ctx, grad_outputs): |
| 24 | - x, weight = ctx.saved_tensors | 24 | + x, weight = ctx.saved_tensors |
| 25 | - dx, dw, dbias = GMMFunction.ascendspeed_ops.npu_gmm_backward( | 25 | + dx, dw, dbias = GMMFunction.mindspeed_ops.npu_gmm_backward( |
| 26 | - [grad_outputs], [x], [weight], ctx.group_list) | 26 | + [grad_outputs], [x], [weight], ctx.group_list) |
| 27 | - dbias = None if len(dbias) == 0 else dbias[0] | 27 | + dbias = None if len(dbias) == 0 else dbias[0] |
| 28 | - | 28 | + |
| 29 | - return dx[0], dw[0], dbias, None, None | 29 | + return dx[0], dw[0], dbias, None, None |
| 30 | - | 30 | + |
| 31 | - | 31 | + |
| 32 | -def npu_gmm(x, weight, *, bias=None, group_list=None, group_type=0): | 32 | +def npu_gmm(x, weight, *, bias=None, group_list=None, group_type=0): |
| 33 | - if not isinstance(x, torch.Tensor): | 33 | + if not isinstance(x, torch.Tensor): |
| 34 | - raise TypeError("arg0 must be a torch.Tensor, got {}".format(type(x))) | 34 | + raise TypeError("arg0 must be a torch.Tensor, got {}".format(type(x))) |
| 35 | - if not isinstance(weight, torch.Tensor): | 35 | + if not isinstance(weight, torch.Tensor): |
| 36 | - raise TypeError("arg1 must be a torch.Tensor, got {}".format(type(weight))) | 36 | + raise TypeError("arg1 must be a torch.Tensor, got {}".format(type(weight))) |
| 37 | - if not isinstance(bias, (torch.Tensor, type(None))): | 37 | + if not isinstance(bias, (torch.Tensor, type(None))): |
| 38 | - raise TypeError("bias must be a torch.Tensor or None, got {}".format(type(bias))) | 38 | + raise TypeError("bias must be a torch.Tensor or None, got {}".format(type(bias))) |
| 39 | - if not (isinstance(group_list, type(None)) \ | 39 | + if not (isinstance(group_list, type(None)) \ |
| 40 | - or (isinstance(group_list, list) and all(isinstance(x, int) for x in group_list))): | 40 | + or (isinstance(group_list, list) and all(isinstance(x, int) for x in group_list))): |
| 41 | - raise TypeError("group_list must be a List of int or None, got {}".format(type(group_list))) | 41 | + raise TypeError("group_list must be a List of int or None, got {}".format(type(group_list))) |
| 42 | - if not isinstance(group_type, (int, type(None))): | 42 | + if not isinstance(group_type, (int, type(None))): |
| 43 | - raise TypeError("group_type must be an int or None, got {}".format(type(group_type))) | 43 | + raise TypeError("group_type must be an int or None, got {}".format(type(group_type))) |
| 44 | - return GMMFunction.apply(x, weight, bias, group_list, group_type) | 44 | + return GMMFunction.apply(x, weight, bias, group_list, group_type) |
| @@ -1,8 +1,8 @@ | |||
| 1 | from typing import Optional, List, Dict | 1 | from typing import Optional, List, Dict |
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | -from ascendspeed.op_builder import GroupedMatMulAllReduceOpBuilder | 4 | +from mindspeed.op_builder import GroupedMatMulAllReduceOpBuilder |
| 5 | -ascendspeed_ops = GroupedMatMulAllReduceOpBuilder().load() | 5 | +mindspeed_ops = GroupedMatMulAllReduceOpBuilder().load() |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | def ascend_grouped_mat_mul_all_reduce(x: List[torch.Tensor], | 8 | def ascend_grouped_mat_mul_all_reduce(x: List[torch.Tensor], |
| @@ -17,7 +17,7 @@ def ascend_grouped_mat_mul_all_reduce(x: List[torch.Tensor], | |||
| 17 | if torch.__version__ < '2.1.0': | 17 | if torch.__version__ < '2.1.0': |
| 18 | if bias is None: | 18 | if bias is None: |
| 19 | bias = [] | 19 | bias = [] |
| 20 | - outputs = ascendspeed_ops.npu_grouped_mat_mul_all_reduce( | 20 | + outputs = mindspeed_ops.npu_grouped_mat_mul_all_reduce( |
| 21 | x, weight, bias, group_list, split_item, | 21 | x, weight, bias, group_list, split_item, |
| 22 | hcomm, reduce_op, comm_turn) | 22 | hcomm, reduce_op, comm_turn) |
| 23 | return outputs | 23 | return outputs |
| @@ -1,32 +1,32 @@ | |||
| 1 | -from ascendspeed.op_builder import LcalOpBuilder | 1 | +from mindspeed.op_builder import LcalOpBuilder |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class CoCOperations: | 4 | class CoCOperations: |
| 5 | - ascendspeed_ops = LcalOpBuilder().load() | 5 | + mindspeed_ops = LcalOpBuilder().load() |
| 6 | 6 | ||
| 7 | def matmul_all_reduce(self, input1, input2, output, bias=None): | 7 | def matmul_all_reduce(self, input1, input2, output, bias=None): |
| 8 | device = input1.device.index | 8 | device = input1.device.index |
| 9 | - CoCOperations.ascendspeed_ops.matmul_all_reduce(input1, input2, bias, output, device) | 9 | + CoCOperations.mindspeed_ops.matmul_all_reduce(input1, input2, bias, output, device) |
| 10 | return output | 10 | return output |
| 11 | 11 | ||
| 12 | def all_gather_matmul(self, input1, input2, output, bias=None): | 12 | def all_gather_matmul(self, input1, input2, output, bias=None): |
| 13 | device = input1.device.index | 13 | device = input1.device.index |
| 14 | - CoCOperations.ascendspeed_ops.all_gather_matmul(input1, input2, bias, output, device) | 14 | + CoCOperations.mindspeed_ops.all_gather_matmul(input1, input2, bias, output, device) |
| 15 | return output | 15 | return output |
| 16 | 16 | ||
| 17 | def all_gather_matmul_v2(self, input1, input2, output, comm_output, bias=None): | 17 | def all_gather_matmul_v2(self, input1, input2, output, comm_output, bias=None): |
| 18 | device = input1.device.index | 18 | device = input1.device.index |
| 19 | - CoCOperations.ascendspeed_ops.all_gather_matmul_v2(input1, input2, bias, output, comm_output, device) | 19 | + CoCOperations.mindspeed_ops.all_gather_matmul_v2(input1, input2, bias, output, comm_output, device) |
| 20 | return output, comm_output | 20 | return output, comm_output |
| 21 | 21 | ||
| 22 | def matmul_reduce_scatter(self, input1, input2, output, bias=None): | 22 | def matmul_reduce_scatter(self, input1, input2, output, bias=None): |
| 23 | device = input1.device.index | 23 | device = input1.device.index |
| 24 | - CoCOperations.ascendspeed_ops.matmul_reduce_scatter(input1, input2, bias, output, device) | 24 | + CoCOperations.mindspeed_ops.matmul_reduce_scatter(input1, input2, bias, output, device) |
| 25 | return output | 25 | return output |
| 26 | 26 | ||
| 27 | def pure_matmul(self, input1, input2, output, bias=None): | 27 | def pure_matmul(self, input1, input2, output, bias=None): |
| 28 | device = input1.device.index | 28 | device = input1.device.index |
| 29 | - CoCOperations.ascendspeed_ops.pure_matmul(input1, input2, bias, output, device) | 29 | + CoCOperations.mindspeed_ops.pure_matmul(input1, input2, bias, output, device) |
| 30 | return output | 30 | return output |
| 31 | 31 | ||
| 32 | coc_ops = CoCOperations() | 32 | coc_ops = CoCOperations() |
Rascendspeed/ops/npu_mm_all_reduce_add_rms_norm.py→mindspeed/ops/npu_mm_all_reduce_add_rms_norm.py+17-17
| @@ -16,10 +16,10 @@ | |||
| 16 | import torch | 16 | import torch |
| 17 | import torch_npu | 17 | import torch_npu |
| 18 | from torch.library import impl | 18 | from torch.library import impl |
| 19 | -from ascendspeed.op_builder.npu_mm_all_reduce_add_rms_norm_builder import MatmulAllReduceAddRmsNormOpBuilder | 19 | +from mindspeed.op_builder.npu_mm_all_reduce_add_rms_norm_builder import MatmulAllReduceAddRmsNormOpBuilder |
| 20 | -from ascendspeed.op_builder.builder import AS_LIBRARY | 20 | +from mindspeed.op_builder.builder import AS_LIBRARY |
| 21 | 21 | ||
| 22 | -ascendspeed_ops = MatmulAllReduceAddRmsNormOpBuilder().load() | 22 | +mindspeed_ops = MatmulAllReduceAddRmsNormOpBuilder().load() |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| @@ -44,21 +44,21 @@ def npu_mm_all_reduce_add_rms_norm_single(x1, | |||
| 44 | raise AssertionError('residual must not be None.') | 44 | raise AssertionError('residual must not be None.') |
| 45 | if gamma is None: | 45 | if gamma is None: |
| 46 | raise AssertionError('gamma must not be None.') | 46 | raise AssertionError('gamma must not be None.') |
| 47 | - y, normOut = ascendspeed_ops.npu_mm_all_reduce_add_rms_norm(x1, | 47 | + y, normOut = mindspeed_ops.npu_mm_all_reduce_add_rms_norm(x1, |
| 48 | - x2, | 48 | + x2, |
| 49 | - residual, | 49 | + residual, |
| 50 | - gamma, | 50 | + gamma, |
| 51 | - hcom, | 51 | + hcom, |
| 52 | - reduce_op, | 52 | + reduce_op, |
| 53 | - epsilon, | 53 | + epsilon, |
| 54 | - bias, | 54 | + bias, |
| 55 | - antiquant_scale, | 55 | + antiquant_scale, |
| 56 | - antiquant_offset, | 56 | + antiquant_offset, |
| 57 | - dequant_scale, | 57 | + dequant_scale, |
| 58 | - antiquant_group_size, | 58 | + antiquant_group_size, |
| 59 | - comm_turn) | 59 | + comm_turn) |
| 60 | return (y.view(residual.shape), normOut.view(residual.shape)) | 60 | return (y.view(residual.shape), normOut.view(residual.shape)) |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | def npu_mm_all_reduce_add_rms_norm(*args, **kwargs): | 63 | def npu_mm_all_reduce_add_rms_norm(*args, **kwargs): |
| 64 | - return torch.ops.ascendspeed.npu_mm_all_reduce_add_rms_norm(*args, **kwargs) | 64 | + return torch.ops.mindspeed.npu_mm_all_reduce_add_rms_norm(*args, **kwargs) |
Rascendspeed/ops/npu_mm_all_reduce_add_rms_norm_.py→mindspeed/ops/npu_mm_all_reduce_add_rms_norm_.py+17-17
| @@ -16,10 +16,10 @@ | |||
| 16 | import torch | 16 | import torch |
| 17 | import torch_npu | 17 | import torch_npu |
| 18 | from torch.library import impl | 18 | from torch.library import impl |
| 19 | -from ascendspeed.op_builder.npu_inplace_mm_all_reduce_add_rms_norm_builder import InplaceMatmulAllReduceAddRmsNormOpBuilder | 19 | +from mindspeed.op_builder.npu_inplace_mm_all_reduce_add_rms_norm_builder import InplaceMatmulAllReduceAddRmsNormOpBuilder |
| 20 | -from ascendspeed.op_builder.builder import AS_LIBRARY | 20 | +from mindspeed.op_builder.builder import AS_LIBRARY |
| 21 | 21 | ||
| 22 | -ascendspeed_ops = InplaceMatmulAllReduceAddRmsNormOpBuilder().load() | 22 | +mindspeed_ops = InplaceMatmulAllReduceAddRmsNormOpBuilder().load() |
| 23 | 23 | ||
| 24 | 24 | ||
| 25 | 25 | ||
| @@ -44,21 +44,21 @@ def npu_mm_all_reduce_add_rms_norm_single_(x1, | |||
| 44 | raise AssertionError('residual must not be None.') | 44 | raise AssertionError('residual must not be None.') |
| 45 | if gamma is None: | 45 | if gamma is None: |
| 46 | raise AssertionError('gamma must not be None.') | 46 | raise AssertionError('gamma must not be None.') |
| 47 | - y, normOut = ascendspeed_ops.npu_mm_all_reduce_add_rms_norm_(x1, | 47 | + y, normOut = mindspeed_ops.npu_mm_all_reduce_add_rms_norm_(x1, |
| 48 | - x2, | 48 | + x2, |
| 49 | - residual, | 49 | + residual, |
| 50 | - gamma, | 50 | + gamma, |
| 51 | - hcom, | 51 | + hcom, |
| 52 | - reduce_op, | 52 | + reduce_op, |
| 53 | - epsilon, | 53 | + epsilon, |
| 54 | - bias, | 54 | + bias, |
| 55 | - antiquant_scale, | 55 | + antiquant_scale, |
| 56 | - antiquant_offset, | 56 | + antiquant_offset, |
| 57 | - dequant_scale, | 57 | + dequant_scale, |
| 58 | - antiquant_group_size, | 58 | + antiquant_group_size, |
| 59 | - comm_turn) | 59 | + comm_turn) |
| 60 | return (y.view(residual.shape), normOut.view(residual.shape)) | 60 | return (y.view(residual.shape), normOut.view(residual.shape)) |
| 61 | 61 | ||
| 62 | 62 | ||
| 63 | def npu_mm_all_reduce_add_rms_norm_(*args, **kwargs): | 63 | def npu_mm_all_reduce_add_rms_norm_(*args, **kwargs): |
| 64 | - return torch.ops.ascendspeed.npu_mm_all_reduce_add_rms_norm_(*args, **kwargs) | 64 | + return torch.ops.mindspeed.npu_mm_all_reduce_add_rms_norm_(*args, **kwargs) |
| @@ -1,183 +1,183 @@ | |||
| 1 | -import os | 1 | +import os |
| 2 | -from functools import wraps | 2 | +from functools import wraps |
| 3 | - | 3 | + |
| 4 | -import torch | 4 | +import torch |
| 5 | -from megatron.training import get_args | 5 | +from megatron.training import get_args |
| 6 | -from megatron.core import tensor_parallel | 6 | +from megatron.core import tensor_parallel |
| 7 | -from megatron.core.optimizer.optimizer import Float16OptimizerWithFloat16Params | 7 | +from megatron.core.optimizer.optimizer import Float16OptimizerWithFloat16Params |
| 8 | - | 8 | + |
| 9 | - | 9 | + |
| 10 | -@torch.no_grad() | 10 | +@torch.no_grad() |
| 11 | -def mixed_precision_optimizer_step(self): | 11 | +def mixed_precision_optimizer_step(self): |
| 12 | - # Copy gradients from model params to main params. | 12 | + # Copy gradients from model params to main params. |
| 13 | - timers = self.config.timers | 13 | + timers = self.config.timers |
| 14 | - timers('optimizer-copy-to-main-grad', log_level=1).start( | 14 | + timers('optimizer-copy-to-main-grad', log_level=1).start( |
| 15 | - barrier=self.config.barrier_with_L1_time) | 15 | + barrier=self.config.barrier_with_L1_time) |
| 16 | - self._copy_model_grads_to_main_grads() | 16 | + self._copy_model_grads_to_main_grads() |
| 17 | - timers('optimizer-copy-to-main-grad').stop() | 17 | + timers('optimizer-copy-to-main-grad').stop() |
| 18 | - if self.config.reuse_fp32_param: | 18 | + if self.config.reuse_fp32_param: |
| 19 | - # bf16 -> fp32 | 19 | + # bf16 -> fp32 |
| 20 | - for int32_float32_group, float16_param_group in zip( | 20 | + for int32_float32_group, float16_param_group in zip( |
| 21 | - self.int32_float32_groups, self.float16_float32_groups): | 21 | + self.int32_float32_groups, self.float16_float32_groups): |
| 22 | - bf16_tensors_to_fp32_tensors(int32_float32_group, float16_param_group) | 22 | + bf16_tensors_to_fp32_tensors(int32_float32_group, float16_param_group) |
| 23 | - | 23 | + |
| 24 | - # Do unscale, check for inf, and update grad scaler only for | 24 | + # Do unscale, check for inf, and update grad scaler only for |
| 25 | - # the case that grad scaler is provided. | 25 | + # the case that grad scaler is provided. |
| 26 | - if self.grad_scaler: | 26 | + if self.grad_scaler: |
| 27 | - | 27 | + |
| 28 | - # Unscale and check for inf/nan. | 28 | + # Unscale and check for inf/nan. |
| 29 | - timers('optimizer-unscale-and-check-inf', log_level=1).start( | 29 | + timers('optimizer-unscale-and-check-inf', log_level=1).start( |
| 30 | - barrier=self.config.barrier_with_L1_time) | 30 | + barrier=self.config.barrier_with_L1_time) |
| 31 | - found_inf_flag = self._unscale_main_grads_and_check_for_nan() | 31 | + found_inf_flag = self._unscale_main_grads_and_check_for_nan() |
| 32 | - timers('optimizer-unscale-and-check-inf').stop() | 32 | + timers('optimizer-unscale-and-check-inf').stop() |
| 33 | - | 33 | + |
| 34 | - # We are done with scaling gradients | 34 | + # We are done with scaling gradients |
| 35 | - # so we can update the loss scale. | 35 | + # so we can update the loss scale. |
| 36 | - self.grad_scaler.update(found_inf_flag) | 36 | + self.grad_scaler.update(found_inf_flag) |
| 37 | - | 37 | + |
| 38 | - # If we found inf/nan, skip the update. | 38 | + # If we found inf/nan, skip the update. |
| 39 | - if found_inf_flag: | 39 | + if found_inf_flag: |
| 40 | - return False, None, None | 40 | + return False, None, None |
| 41 | - | 41 | + |
| 42 | - # Clip the main gradients. | 42 | + # Clip the main gradients. |
| 43 | - timers('optimizer-clip-main-grad', log_level=1).start( | 43 | + timers('optimizer-clip-main-grad', log_level=1).start( |
| 44 | - barrier=self.config.barrier_with_L1_time) | 44 | + barrier=self.config.barrier_with_L1_time) |
| 45 | - grad_norm = None | 45 | + grad_norm = None |
| 46 | - if self.config.clip_grad > 0.0: | 46 | + if self.config.clip_grad > 0.0: |
| 47 | - grad_norm = self.clip_grad_norm(self.config.clip_grad) | 47 | + grad_norm = self.clip_grad_norm(self.config.clip_grad) |
| 48 | - timers('optimizer-clip-main-grad').stop() | 48 | + timers('optimizer-clip-main-grad').stop() |
| 49 | - | 49 | + |
| 50 | - | 50 | + |
| 51 | - # Count the zeros in the grads. | 51 | + # Count the zeros in the grads. |
| 52 | - timers('optimizer-count-zeros', log_level=1).start( | 52 | + timers('optimizer-count-zeros', log_level=1).start( |
| 53 | - barrier=self.config.barrier_with_L1_time) | 53 | + barrier=self.config.barrier_with_L1_time) |
| 54 | - num_zeros_in_grad = self.count_zeros() if \ | 54 | + num_zeros_in_grad = self.count_zeros() if \ |
| 55 | - self.config.log_num_zeros_in_grad else None | 55 | + self.config.log_num_zeros_in_grad else None |
| 56 | - timers('optimizer-count-zeros').stop() | 56 | + timers('optimizer-count-zeros').stop() |
| 57 | - | 57 | + |
| 58 | - # Step the optimizer. | 58 | + # Step the optimizer. |
| 59 | - timers('optimizer-inner-step', log_level=1).start( | 59 | + timers('optimizer-inner-step', log_level=1).start( |
| 60 | - barrier=self.config.barrier_with_L1_time) | 60 | + barrier=self.config.barrier_with_L1_time) |
| 61 | - self.optimizer.step() | 61 | + self.optimizer.step() |
| 62 | - timers('optimizer-inner-step').stop() | 62 | + timers('optimizer-inner-step').stop() |
| 63 | - | 63 | + |
| 64 | - # Update params from main params. | 64 | + # Update params from main params. |
| 65 | - timers('optimizer-copy-main-to-model-params', log_level=1).start( | 65 | + timers('optimizer-copy-main-to-model-params', log_level=1).start( |
| 66 | - barrier=self.config.barrier_with_L1_time) | 66 | + barrier=self.config.barrier_with_L1_time) |
| 67 | - if self.config.reuse_fp32_param: | 67 | + if self.config.reuse_fp32_param: |
| 68 | - # fp32 -> bf16 + res | 68 | + # fp32 -> bf16 + res |
| 69 | - for int32_float32_param_group, float16_param_group in zip( | 69 | + for int32_float32_param_group, float16_param_group in zip( |
| 70 | - self.int32_float32_groups, self.float16_float32_groups): | 70 | + self.int32_float32_groups, self.float16_float32_groups): |
| 71 | - fp32_tensors_to_bf16_tensors(int32_float32_param_group, float16_param_group) | 71 | + fp32_tensors_to_bf16_tensors(int32_float32_param_group, float16_param_group) |
| 72 | - else: | 72 | + else: |
| 73 | - self._copy_main_params_to_model_params() | 73 | + self._copy_main_params_to_model_params() |
| 74 | - timers('optimizer-copy-main-to-model-params').stop() | 74 | + timers('optimizer-copy-main-to-model-params').stop() |
| 75 | - | 75 | + |
| 76 | - # Successful update. | 76 | + # Successful update. |
| 77 | - return True, grad_norm, num_zeros_in_grad | 77 | + return True, grad_norm, num_zeros_in_grad |
| 78 | - | 78 | + |
| 79 | - | 79 | + |
| 80 | -def optimizer_config_init_wrapper(init_func): | 80 | +def optimizer_config_init_wrapper(init_func): |
| 81 | - @wraps(init_func) | 81 | + @wraps(init_func) |
| 82 | - def optimizer_config_init(*args, **kwargs): | 82 | + def optimizer_config_init(*args, **kwargs): |
| 83 | - init_func(*args, **kwargs) | 83 | + init_func(*args, **kwargs) |
| 84 | - self = args[0] | 84 | + self = args[0] |
| 85 | - args = get_args() | 85 | + args = get_args() |
| 86 | - self.reuse_fp32_param = args.reuse_fp32_param if hasattr(args, "reuse_fp32_param") else False | 86 | + self.reuse_fp32_param = args.reuse_fp32_param if hasattr(args, "reuse_fp32_param") else False |
| 87 | - | 87 | + |
| 88 | - return optimizer_config_init | 88 | + return optimizer_config_init |
| 89 | - | 89 | + |
| 90 | - | 90 | + |
| 91 | -def reuse_fp32_param_init_wrapper(init_func): | 91 | +def reuse_fp32_param_init_wrapper(init_func): |
| 92 | - @wraps(init_func) | 92 | + @wraps(init_func) |
| 93 | - def reuse_fp32_param_init(*args, **kwargs): | 93 | + def reuse_fp32_param_init(*args, **kwargs): |
| 94 | - init_func(*args, **kwargs) | 94 | + init_func(*args, **kwargs) |
| 95 | - self = args[0] | 95 | + self = args[0] |
| 96 | - args = get_args() | 96 | + args = get_args() |
| 97 | - self.reuse_fp32_param = args.reuse_fp32_param if hasattr(args, "reuse_fp32_param") else False | 97 | + self.reuse_fp32_param = args.reuse_fp32_param if hasattr(args, "reuse_fp32_param") else False |
| 98 | - if self.reuse_fp32_param: | 98 | + if self.reuse_fp32_param: |
| 99 | - self.res_float16_groups = [] | 99 | + self.res_float16_groups = [] |
| 100 | - self.float16_float32_groups = [] | 100 | + self.float16_float32_groups = [] |
| 101 | - self.int32_float32_groups = [] | 101 | + self.int32_float32_groups = [] |
| 102 | - for float16_params_this_group, fp32_from_float16_group in zip(self.float16_groups, self.fp32_from_float16_groups): | 102 | + for float16_params_this_group, fp32_from_float16_group in zip(self.float16_groups, self.fp32_from_float16_groups): |
| 103 | - res_float16_params_this_group = [] | 103 | + res_float16_params_this_group = [] |
| 104 | - float16_float32_params_this_group = [] | 104 | + float16_float32_params_this_group = [] |
| 105 | - int32_float32_params_this_group = [] | 105 | + int32_float32_params_this_group = [] |
| 106 | - for i, (_, fp32_from_fp16_param) in enumerate(zip(float16_params_this_group, fp32_from_float16_group)): | 106 | + for i, (_, fp32_from_fp16_param) in enumerate(zip(float16_params_this_group, fp32_from_float16_group)): |
| 107 | - res_float16_params_this_group.append( | 107 | + res_float16_params_this_group.append( |
| 108 | - torch.empty((fp32_from_fp16_param.numel() * 1), dtype=torch.bfloat16, device=fp32_from_fp16_param.device)) | 108 | + torch.empty((fp32_from_fp16_param.numel() * 1), dtype=torch.bfloat16, device=fp32_from_fp16_param.device)) |
| 109 | - float16_float32_params_this_group.append( | 109 | + float16_float32_params_this_group.append( |
| 110 | - torch.empty((fp32_from_fp16_param.numel() * 2), dtype=torch.bfloat16, device=fp32_from_fp16_param.device)) | 110 | + torch.empty((fp32_from_fp16_param.numel() * 2), dtype=torch.bfloat16, device=fp32_from_fp16_param.device)) |
| 111 | - int32_float32_params_this_group.append( | 111 | + int32_float32_params_this_group.append( |
| 112 | - torch.empty((fp32_from_fp16_param.numel() * 1), dtype=torch.int32, device=fp32_from_fp16_param.device)) | 112 | + torch.empty((fp32_from_fp16_param.numel() * 1), dtype=torch.int32, device=fp32_from_fp16_param.device)) |
| 113 | - init_and_reuse_storage_of_tensors(fp32_from_float16_group[i], | 113 | + init_and_reuse_storage_of_tensors(fp32_from_float16_group[i], |
| 114 | - float16_float32_params_this_group[-1], | 114 | + float16_float32_params_this_group[-1], |
| 115 | - res_float16_params_this_group[-1], | 115 | + res_float16_params_this_group[-1], |
| 116 | - float16_params_this_group[i], | 116 | + float16_params_this_group[i], |
| 117 | - int32_float32_params_this_group[-1] | 117 | + int32_float32_params_this_group[-1] |
| 118 | - ) | 118 | + ) |
| 119 | - self.res_float16_groups.append(res_float16_params_this_group) | 119 | + self.res_float16_groups.append(res_float16_params_this_group) |
| 120 | - self.float16_float32_groups.append(float16_float32_params_this_group) | 120 | + self.float16_float32_groups.append(float16_float32_params_this_group) |
| 121 | - self.int32_float32_groups.append(int32_float32_params_this_group) | 121 | + self.int32_float32_groups.append(int32_float32_params_this_group) |
| 122 | - return reuse_fp32_param_init | 122 | + return reuse_fp32_param_init |
| 123 | - | 123 | + |
| 124 | - | 124 | + |
| 125 | -def init_and_reuse_storage_of_tensors( | 125 | +def init_and_reuse_storage_of_tensors( |
| 126 | - fp32_tensor, | 126 | + fp32_tensor, |
| 127 | - bf16_fp32_tensor, | 127 | + bf16_fp32_tensor, |
| 128 | - res_tensor, | 128 | + res_tensor, |
| 129 | - bf16_tensor, | 129 | + bf16_tensor, |
| 130 | - int32_tensor | 130 | + int32_tensor |
| 131 | -): | 131 | +): |
| 132 | - """ | 132 | + """ |
| 133 | - init a list of tensor with length of 2*fp32_tensor.numel() in bf16 to share the same storage. | 133 | + init a list of tensor with length of 2*fp32_tensor.numel() in bf16 to share the same storage. |
| 134 | - Args: | 134 | + Args: |
| 135 | - fp32_tensor: original fp32 tensor. | 135 | + fp32_tensor: original fp32 tensor. |
| 136 | - bf16_fp32_tensor: a bf16 tensor share the same storage with original list of fp32 tensors. | 136 | + bf16_fp32_tensor: a bf16 tensor share the same storage with original list of fp32 tensors. |
| 137 | - res_tensor: a bf16 tensor that store the residual value of fp32 to bf16, shares a half of the | 137 | + res_tensor: a bf16 tensor that store the residual value of fp32 to bf16, shares a half of the |
| 138 | - storage with bf16_fp32_tensor. | 138 | + storage with bf16_fp32_tensor. |
| 139 | - bf16_tensor: a bf16 tensor that store the value from fp32, shares another half of the | 139 | + bf16_tensor: a bf16 tensor that store the value from fp32, shares another half of the |
| 140 | - storage with bf16_fp32_tensor. | 140 | + storage with bf16_fp32_tensor. |
| 141 | - int32_tensors: a list of int32 tensors share the same storages with original list of fp32 tensors. | 141 | + int32_tensors: a list of int32 tensors share the same storages with original list of fp32 tensors. |
| 142 | - """ | 142 | + """ |
| 143 | - from ascendspeed.op_builder import AlgorithmOpBuilder | 143 | + from mindspeed.op_builder import AlgorithmOpBuilder |
| 144 | - reuse_data_ptr = AlgorithmOpBuilder().load().reuse_data_ptr | 144 | + reuse_data_ptr = AlgorithmOpBuilder().load().reuse_data_ptr |
| 145 | - reuse_data_ptr(bf16_fp32_tensor, fp32_tensor, 0) | 145 | + reuse_data_ptr(bf16_fp32_tensor, fp32_tensor, 0) |
| 146 | - reuse_data_ptr(int32_tensor, fp32_tensor, 0) | 146 | + reuse_data_ptr(int32_tensor, fp32_tensor, 0) |
| 147 | - fp32_tensors_to_bf16_tensors([int32_tensor], [bf16_fp32_tensor]) | 147 | + fp32_tensors_to_bf16_tensors([int32_tensor], [bf16_fp32_tensor]) |
| 148 | - reuse_data_ptr(res_tensor, bf16_fp32_tensor, 0) | 148 | + reuse_data_ptr(res_tensor, bf16_fp32_tensor, 0) |
| 149 | - reuse_data_ptr(bf16_tensor, bf16_fp32_tensor, res_tensor.numel()) | 149 | + reuse_data_ptr(bf16_tensor, bf16_fp32_tensor, res_tensor.numel()) |
| 150 | - | 150 | + |
| 151 | - | 151 | + |
| 152 | -def fp32_tensors_to_bf16_tensors(int32_tensors, bf16_fp32_tensors): | 152 | +def fp32_tensors_to_bf16_tensors(int32_tensors, bf16_fp32_tensors): |
| 153 | - """ | 153 | + """ |
| 154 | - fp32(0p0p0p0p) -> bf16(pppp) + res(0000) | 154 | + fp32(0p0p0p0p) -> bf16(pppp) + res(0000) |
| 155 | - rearrange the storage of bf16_fp32_tensors so that recover the fp32_tensors. | 155 | + rearrange the storage of bf16_fp32_tensors so that recover the fp32_tensors. |
| 156 | - Args: | 156 | + Args: |
| 157 | - int32_tensors: a list of int32 tensors share the same storages with original list of fp32 tensors. | 157 | + int32_tensors: a list of int32 tensors share the same storages with original list of fp32 tensors. |
| 158 | - bf16_fp32_tensors: a list of bf16 tensors share the same storages with original list of fp32 tensors. | 158 | + bf16_fp32_tensors: a list of bf16 tensors share the same storages with original list of fp32 tensors. |
| 159 | - Returns: | 159 | + Returns: |
| 160 | - None | 160 | + None |
| 161 | - """ | 161 | + """ |
| 162 | - for int32_tensor, bf16_fp32_tensor in zip(int32_tensors, bf16_fp32_tensors): | 162 | + for int32_tensor, bf16_fp32_tensor in zip(int32_tensors, bf16_fp32_tensors): |
| 163 | - if bf16_fp32_tensor.numel() == 0: | 163 | + if bf16_fp32_tensor.numel() == 0: |
| 164 | - return | 164 | + return |
| 165 | - int32_tensor.add_(32768) | 165 | + int32_tensor.add_(32768) |
| 166 | - bf16_fp32_tensor.copy_(bf16_fp32_tensor.view(-1, 2).transpose(1, 0).reshape(-1).contiguous()) | 166 | + bf16_fp32_tensor.copy_(bf16_fp32_tensor.view(-1, 2).transpose(1, 0).reshape(-1).contiguous()) |
| 167 | - | 167 | + |
| 168 | - | 168 | + |
| 169 | -def bf16_tensors_to_fp32_tensors(int32_tensors, bf16_fp32_tensors): | 169 | +def bf16_tensors_to_fp32_tensors(int32_tensors, bf16_fp32_tensors): |
| 170 | - """ | 170 | + """ |
| 171 | - res(0000) + bf16(pppp) -> fp32(0p0p0p0p) | 171 | + res(0000) + bf16(pppp) -> fp32(0p0p0p0p) |
| 172 | - rearrange the storage of bf16_fp32_tensors so that recover the fp32_tensors. | 172 | + rearrange the storage of bf16_fp32_tensors so that recover the fp32_tensors. |
| 173 | - Args: | 173 | + Args: |
| 174 | - int32_tensors: a list of int32 tensors share the same storages with original list of fp32 tensors. | 174 | + int32_tensors: a list of int32 tensors share the same storages with original list of fp32 tensors. |
| 175 | - bf16_fp32_tensors: a list of bf16 tensors share the same storages with original list of fp32 tensors. | 175 | + bf16_fp32_tensors: a list of bf16 tensors share the same storages with original list of fp32 tensors. |
| 176 | - Returns: | 176 | + Returns: |
| 177 | - None | 177 | + None |
| 178 | - """ | 178 | + """ |
| 179 | - for int32_tensor, bf16_fp32_tensor in zip(int32_tensors, bf16_fp32_tensors): | 179 | + for int32_tensor, bf16_fp32_tensor in zip(int32_tensors, bf16_fp32_tensors): |
| 180 | - if bf16_fp32_tensor.numel() == 0: | 180 | + if bf16_fp32_tensor.numel() == 0: |
| 181 | - return | 181 | + return |
| 182 | - bf16_fp32_tensor.copy_(bf16_fp32_tensor.view(2, -1).transpose(1, 0).reshape(-1).contiguous()) | 182 | + bf16_fp32_tensor.copy_(bf16_fp32_tensor.view(2, -1).transpose(1, 0).reshape(-1).contiguous()) |
| 183 | - int32_tensor.sub_(32768) | 183 | + int32_tensor.sub_(32768) |
| @@ -83,7 +83,7 @@ class Patch: | |||
| 83 | if not create_dummy: | 83 | if not create_dummy: |
| 84 | raise ModuleNotFoundError(e) from e | 84 | raise ModuleNotFoundError(e) from e |
| 85 | sys.modules[path] = types.ModuleType(path) | 85 | sys.modules[path] = types.ModuleType(path) |
| 86 | - sys.modules[path].__file__ = 'ascendspeed.dummy_module.py' | 86 | + sys.modules[path].__file__ = 'mindspeed.dummy_module.py' |
| 87 | if parent: | 87 | if parent: |
| 88 | setattr(importlib.import_module(parent), modules[i - 1], sys.modules[path]) | 88 | setattr(importlib.import_module(parent), modules[i - 1], sys.modules[path]) |
| 89 | else: | 89 | else: |
| @@ -98,17 +98,17 @@ class Patch: | |||
| 98 | return sys.modules[module_path], getattr(sys.modules[module_path], function_name) if function_name is not None else None | 98 | return sys.modules[module_path], getattr(sys.modules[module_path], function_name) if function_name is not None else None |
| 99 | 99 | ||
| 100 | 100 | ||
| 101 | -class AscendSpeedPatchesManager: | 101 | +class MindSpeedPatchesManager: |
| 102 | patches_info = {} | 102 | patches_info = {} |
| 103 | 103 | ||
| 104 | 104 | ||
| 105 | def register_patch(orig_func_name, new_func=None, force_patch=False, create_dummy=False): | 105 | def register_patch(orig_func_name, new_func=None, force_patch=False, create_dummy=False): |
| 106 | - if orig_func_name not in AscendSpeedPatchesManager.patches_info: | 106 | + if orig_func_name not in MindSpeedPatchesManager.patches_info: |
| 107 | - AscendSpeedPatchesManager.patches_info[orig_func_name] = Patch(orig_func_name, new_func, create_dummy) | 107 | + MindSpeedPatchesManager.patches_info[orig_func_name] = Patch(orig_func_name, new_func, create_dummy) |
| 108 | else: | 108 | else: |
| 109 | - AscendSpeedPatchesManager.patches_info.get(orig_func_name).set_patch_func(new_func, force_patch) | 109 | + MindSpeedPatchesManager.patches_info.get(orig_func_name).set_patch_func(new_func, force_patch) |
| 110 | 110 | ||
| 111 | 111 | ||
| 112 | def apply_patches(): | 112 | def apply_patches(): |
| 113 | - for patch in AscendSpeedPatchesManager.patches_info.values(): | 113 | + for patch in MindSpeedPatchesManager.patches_info.values(): |
| 114 | patch.apply_patch() | 114 | patch.apply_patch() |
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. | 5 | # you may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. | 5 | # you may not use this file except in compliance with the License. |
| @@ -1,3 +1,5 @@ | |||
| 1 | +# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | ||
| 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. | ||
| 1 | import time | 3 | import time |
| 2 | import torch | 4 | import torch |
| 3 | 5 | ||
| @@ -1,3 +1,5 @@ | |||
| 1 | +# Copyright (c) 2023, NVIDIA CORPORATION. All rights reserved. | ||
| 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. | ||
| 1 | import torch | 3 | import torch |
| 2 | from megatron.training import get_args | 4 | from megatron.training import get_args |
| 3 | from megatron.core import mpu | 5 | from megatron.core import mpu |
| @@ -6,17 +6,17 @@ import subprocess | |||
| 6 | import setuptools | 6 | import setuptools |
| 7 | 7 | ||
| 8 | if sys.version_info < (3,): | 8 | if sys.version_info < (3,): |
| 9 | - raise Exception("Python 2 is not supported by AscendSpeed.") | 9 | + raise Exception("Python 2 is not supported by MindSpeed.") |
| 10 | 10 | ||
| 11 | -__description__ = 'AscendSpeed for LLMs of Ascend' | 11 | +__description__ = 'MindSpeed for LLMs of Ascend' |
| 12 | __version__ = '0.0.1' | 12 | __version__ = '0.0.1' |
| 13 | __author__ = 'Ascend' | 13 | __author__ = 'Ascend' |
| 14 | -__long_description__ = 'AscendSpeed for LLMs of Ascend' | 14 | +__long_description__ = 'MindSpeed for LLMs of Ascend' |
| 15 | -__url__ = 'https://gitee.com/ascend/AscendSpeed' | 15 | +__url__ = 'https://gitee.com/ascend/MindSpeed' |
| 16 | -__download_url__ = 'https://gitee.com/ascend/AscendSpeed/release' | 16 | +__download_url__ = 'https://gitee.com/ascend/MindSpeed/release' |
| 17 | __keywords__ = 'Ascend, langauge, deep learning, NLP' | 17 | __keywords__ = 'Ascend, langauge, deep learning, NLP' |
| 18 | -__license__ = 'See https://gitee.com/ascend/AscendSpeed' | 18 | +__license__ = 'See https://gitee.com/ascend/MindSpeed' |
| 19 | -__package_name__ = 'ascendspeed' | 19 | +__package_name__ = 'mindspeed' |
| 20 | __contact_names__ = 'Ascend' | 20 | __contact_names__ = 'Ascend' |
| 21 | 21 | ||
| 22 | try: | 22 | try: |
| @@ -104,7 +104,7 @@ def atb_package(): | |||
| 104 | raise Exception("Download Failed") | 104 | raise Exception("Download Failed") |
| 105 | 105 | ||
| 106 | print("Extracting ATB package...") | 106 | print("Extracting ATB package...") |
| 107 | - extract_path = os.path.join(os.getcwd(), "ascendspeed", "atb") | 107 | + extract_path = os.path.join(os.getcwd(), "mindspeed", "atb") |
| 108 | os.makedirs(extract_path, exist_ok=True) | 108 | os.makedirs(extract_path, exist_ok=True) |
| 109 | absolute_atb_path = os.path.join(os.getcwd(), atb_name) | 109 | absolute_atb_path = os.path.join(os.getcwd(), atb_name) |
| 110 | subprocess.run(['./' + atb_name, '--noexec', '--extract=' + extract_path]) | 110 | subprocess.run(['./' + atb_name, '--noexec', '--extract=' + extract_path]) |
| @@ -113,7 +113,7 @@ def atb_package(): | |||
| 113 | with os.fdopen(os.open(init_file_path, flags, modes), 'w') as f: | 113 | with os.fdopen(os.open(init_file_path, flags, modes), 'w') as f: |
| 114 | pass | 114 | pass |
| 115 | 115 | ||
| 116 | - manifest_content = "recursive-include ascendspeed/atb *" | 116 | + manifest_content = "recursive-include mindspeed/atb *" |
| 117 | with os.fdopen(os.open('MANIFEST.in', flags, modes), 'w') as f: | 117 | with os.fdopen(os.open('MANIFEST.in', flags, modes), 'w') as f: |
| 118 | f.write(manifest_content) | 118 | f.write(manifest_content) |
| 119 | 119 | ||
| @@ -160,7 +160,7 @@ setuptools.setup( | |||
| 160 | include_package_data=True, | 160 | include_package_data=True, |
| 161 | install_package_data=True, | 161 | install_package_data=True, |
| 162 | exclude_package_data={'': ['**/*.md']}, | 162 | exclude_package_data={'': ['**/*.md']}, |
| 163 | - package_data={'ascendspeed': ['**/*.h', '**/*.cpp']}, | 163 | + package_data={'mindspeed': ['**/*.h', '**/*.cpp']}, |
| 164 | zip_safe=False, | 164 | zip_safe=False, |
| 165 | # PyPI package information. | 165 | # PyPI package information. |
| 166 | keywords=__keywords__, | 166 | keywords=__keywords__, |
| @@ -1,6 +1,6 @@ | |||
| 1 | # Tests Usage | 1 | # Tests Usage |
| 2 | 2 | ||
| 3 | -1. Install `ascendspeed` | 3 | +1. Install `mindspeed` |
| 4 | ```shell | 4 | ```shell |
| 5 | pip install -e . | 5 | pip install -e . |
| 6 | ``` | 6 | ``` |
| @@ -1,16 +1,16 @@ | |||
| 1 | # Tests Usage | 1 | # Tests Usage |
| 2 | 2 | ||
| 3 | -1. Put `AscendSpeed` and `Megatron-LM` in the same folder. | 3 | +1. Put `MindSpeed` and `Megatron-LM` in the same folder. |
| 4 | 4 | ||
| 5 | -2. Install `AscendSpeed` and enable 'AscendSpeed Patch'. | 5 | +2. Install `MindSpeed` and enable 'MindSpeed Patch'. |
| 6 | 6 | ||
| 7 | 3. Run all system tests by one scripts. | 7 | 3. Run all system tests by one scripts. |
| 8 | ```shell | 8 | ```shell |
| 9 | - bash /Path/To/AscendSpeed/tests_extend/system_tests/scripts/system_tests.sh | 9 | + bash /Path/To/MindSpeed/tests_extend/system_tests/scripts/system_tests.sh |
| 10 | ``` | 10 | ``` |
| 11 | Tips: | 11 | Tips: |
| 12 | 1. `--cann_dir=` can be used to change the path of cann-toolkit. Default is `/usr/local/Ascend/`. | 12 | 1. `--cann_dir=` can be used to change the path of cann-toolkit. Default is `/usr/local/Ascend/`. |
| 13 | 2. `--docker=` can be used to run tests on docker env. Default is local env. | 13 | 2. `--docker=` can be used to run tests on docker env. Default is local env. |
| 14 | 14 | ||
| 15 | -4. All test results will be collected in `/Dirname/To/AscendSpeed/logs`. | 15 | +4. All test results will be collected in `/Dirname/To/MindSpeed/logs`. |
| 16 | 16 | ||
| @@ -10,22 +10,22 @@ LLAMA3-8B 训练的硬件配置: | |||
| 10 | 10 | ||
| 11 | ### 脚本 | 11 | ### 脚本 |
| 12 | 12 | ||
| 13 | -1. 按照readme安装AscendSpeed和Megatron-LM | 13 | +1. 按照readme安装MindSpeed和Megatron-LM |
| 14 | 14 | ||
| 15 | ```shell | 15 | ```shell |
| 16 | - git clone https://gitee.com/ascend/AscendSpeed.git | 16 | + git clone https://gitee.com/ascend/MindSpeed.git |
| 17 | - pip install -e AscendSpeed | 17 | + pip install -e MindSpeed |
| 18 | git clone https://github.com/NVIDIA/Megatron-LM.git | 18 | git clone https://github.com/NVIDIA/Megatron-LM.git |
| 19 | cd Megatron-LM | 19 | cd Megatron-LM |
| 20 | # git checkout 到使用的Megatron-LM分支 | 20 | # git checkout 到使用的Megatron-LM分支 |
| 21 | git checkout xxx | 21 | git checkout xxx |
| 22 | - ascendspeed -P | 22 | + mindspeed -P |
| 23 | mkdir model_from_hf | 23 | mkdir model_from_hf |
| 24 | mkdir dataset | 24 | mkdir dataset |
| 25 | mkdir ckpt | 25 | mkdir ckpt |
| 26 | - mv ../AscendSpeed/tests_extend/tools/preprocess_data.py . | 26 | + mv ../MindSpeed/tests_extend/tools/preprocess_data.py . |
| 27 | - mv ../AscendSpeed/tests_extend/tools/data_handler.py . | 27 | + mv ../MindSpeed/tests_extend/tools/data_handler.py . |
| 28 | - mv ../AscendSpeed/tests_extend/system_tests/llama3/pretrain_llama3_8b_ptd.sh ./examples/ | 28 | + mv ../MindSpeed/tests_extend/system_tests/llama3/pretrain_llama3_8b_ptd.sh ./examples/ |
| 29 | ``` | 29 | ``` |
| 30 | 2. 搭建环境 | 30 | 2. 搭建环境 |
| 31 | 31 | ||
| @@ -93,7 +93,7 @@ LLAMA3-8B 训练的硬件配置: | |||
| 93 | source /usr/local/Ascend/ascend-toolkit/set_env.sh | 93 | source /usr/local/Ascend/ascend-toolkit/set_env.sh |
| 94 | 94 | ||
| 95 | # 根据实际情况配置词表、数据集、环境变量保存路径 | 95 | # 根据实际情况配置词表、数据集、环境变量保存路径 |
| 96 | - source "../AscendSpeed/tests_extend/system_tests/env_npu.sh" | 96 | + source "../MindSpeed/tests_extend/system_tests/env_npu.sh" |
| 97 | CKPT_SAVE_DIR="./ckpt/" | 97 | CKPT_SAVE_DIR="./ckpt/" |
| 98 | DATA_PATH="./dataset/llama-3-8b-hf/alpaca_text_document" #数据集路径 | 98 | DATA_PATH="./dataset/llama-3-8b-hf/alpaca_text_document" #数据集路径 |
| 99 | TOKENIZER_MODEL="./model_from_hf/llama-3-8b-hf/" #词表路径 | 99 | TOKENIZER_MODEL="./model_from_hf/llama-3-8b-hf/" #词表路径 |
| @@ -12,7 +12,7 @@ | |||
| 12 | 12 | ||
| 13 | ### 准备工作 | 13 | ### 准备工作 |
| 14 | 14 | ||
| 15 | -1. 按照AscendSpeed根目录下README完成AscendSpeed、Megatron-LM源码准备和上手准备 | 15 | +1. 按照MindSpeed根目录下README完成MindSpeed、Megatron-LM源码准备和上手准备 |
| 16 | 16 | ||
| 17 | 2. 下载 Mixtral-8x7B 的 [词表和tokenizer](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1/tree/main) | 17 | 2. 下载 Mixtral-8x7B 的 [词表和tokenizer](https://huggingface.co/mistralai/Mixtral-8x7B-v0.1/tree/main) |
| 18 | 18 | ||
| @@ -57,7 +57,7 @@ python ./tests_extend/tools/preprocess_data.py \ | |||
| 57 | 57 | ||
| 58 | ``` | 58 | ``` |
| 59 | # 拷贝mixtral训练所用脚本到Megatron-LM目录下 | 59 | # 拷贝mixtral训练所用脚本到Megatron-LM目录下 |
| 60 | -cp ../AscendSpeed/tests_extend/system_tests/mixtral/pretrain_mixtral.sh . | 60 | +cp ../MindSpeed/tests_extend/system_tests/mixtral/pretrain_mixtral.sh . |
| 61 | 61 | ||
| 62 | ``` | 62 | ``` |
| 63 | 63 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2024, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2024, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. | 5 | # you may not use this file except in compliance with the License. |
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2023, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2023, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. | 5 | # you may not use this file except in compliance with the License. |
| @@ -25,7 +25,7 @@ import logging | |||
| 25 | from typing import List | 25 | from typing import List |
| 26 | 26 | ||
| 27 | import torch | 27 | import torch |
| 28 | -import ascendspeed.megatron_adaptor | 28 | +import mindspeed.megatron_adaptor |
| 29 | from megatron.training.tokenizer.tokenizer import build_tokenizer | 29 | from megatron.training.tokenizer.tokenizer import build_tokenizer |
| 30 | from data_handler import build_dataset, get_dataset_handler | 30 | from data_handler import build_dataset, get_dataset_handler |
| 31 | 31 | ||
Mtests_extend/unit_tests/features/adaptive_recomputing/test_adaptive_recompute_allocator_adpator.py+1-1
| @@ -2,7 +2,7 @@ import ctypes | |||
| 2 | import torch | 2 | import torch |
| 3 | 3 | ||
| 4 | import torch_npu | 4 | import torch_npu |
| 5 | -from ascendspeed.op_builder import AdaptiveRecomputingPluggableAllocatorBuilder | 5 | +from mindspeed.op_builder import AdaptiveRecomputingPluggableAllocatorBuilder |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | class TestPluggableAllocator: | 8 | class TestPluggableAllocator: |
| @@ -1,10 +1,10 @@ | |||
| 1 | -from ascendspeed import megatron_adaptor | 1 | +from mindspeed import megatron_adaptor |
| 2 | from unittest import mock | 2 | from unittest import mock |
| 3 | -import ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute | 3 | +import mindspeed.core.memory.adaptive_recomputing.adaptive_recompute |
| 4 | from megatron.core import parallel_state | 4 | from megatron.core import parallel_state |
| 5 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute import get_adaptive_recomputing | 5 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute import get_adaptive_recomputing |
| 6 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute import is_activate_adaptive_recompute | 6 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute import is_activate_adaptive_recompute |
| 7 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute import get_adaptive_recomputing_policy | 7 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute import get_adaptive_recomputing_policy |
| 8 | 8 | ||
| 9 | from unit_tests.common import DistributedTest | 9 | from unit_tests.common import DistributedTest |
| 10 | 10 | ||
| @@ -44,19 +44,19 @@ class TestRecomputing(DistributedTest): | |||
| 44 | recomputing = get_adaptive_recomputing() | 44 | recomputing = get_adaptive_recomputing() |
| 45 | 45 | ||
| 46 | set_mock_args(True, False, -1, 10) | 46 | set_mock_args(True, False, -1, 10) |
| 47 | - with mock.patch.object(ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute, 'get_args', | 47 | + with mock.patch.object(mindspeed.core.memory.adaptive_recomputing.adaptive_recompute, 'get_args', |
| 48 | return_value=MockArgs.mock_args): | 48 | return_value=MockArgs.mock_args): |
| 49 | result, profile_step = is_activate_adaptive_recompute() | 49 | result, profile_step = is_activate_adaptive_recompute() |
| 50 | assert result is False | 50 | assert result is False |
| 51 | set_mock_args(False, True, 10, 0) | 51 | set_mock_args(False, True, 10, 0) |
| 52 | - with mock.patch.object(ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute, 'get_args', | 52 | + with mock.patch.object(mindspeed.core.memory.adaptive_recomputing.adaptive_recompute, 'get_args', |
| 53 | return_value=MockArgs.mock_args): | 53 | return_value=MockArgs.mock_args): |
| 54 | result, profile_step = is_activate_adaptive_recompute() | 54 | result, profile_step = is_activate_adaptive_recompute() |
| 55 | assert result is True | 55 | assert result is True |
| 56 | set_mock_args() | 56 | set_mock_args() |
| 57 | 57 | ||
| 58 | def test_step_hook(self): | 58 | def test_step_hook(self): |
| 59 | - with mock.patch.object(ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute, 'get_args', | 59 | + with mock.patch.object(mindspeed.core.memory.adaptive_recomputing.adaptive_recompute, 'get_args', |
| 60 | return_value=MockArgs()): | 60 | return_value=MockArgs()): |
| 61 | with mock.patch.object(parallel_state, 'get_tensor_model_parallel_world_size', | 61 | with mock.patch.object(parallel_state, 'get_tensor_model_parallel_world_size', |
| 62 | return_value=0): | 62 | return_value=0): |
| @@ -85,12 +85,12 @@ class TestRecomputing(DistributedTest): | |||
| 85 | 85 | ||
| 86 | recomputing.profiling_step = 11 | 86 | recomputing.profiling_step = 11 |
| 87 | with mock.patch.object( | 87 | with mock.patch.object( |
| 88 | - ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute.AdaptiveRecomputePolicy, | 88 | + mindspeed.core.memory.adaptive_recomputing.adaptive_recompute.AdaptiveRecomputePolicy, |
| 89 | 'solve_recompute_policy', return_value=recomputing.context): | 89 | 'solve_recompute_policy', return_value=recomputing.context): |
| 90 | - with mock.patch.object(ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute, | 90 | + with mock.patch.object(mindspeed.core.memory.adaptive_recomputing.adaptive_recompute, |
| 91 | 'apply_adaptive_recompute', return_value=None): | 91 | 'apply_adaptive_recompute', return_value=None): |
| 92 | with mock.patch.object( | 92 | with mock.patch.object( |
| 93 | - ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_solver.GraphSolver, | 93 | + mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_solver.GraphSolver, |
| 94 | 'build_solver_info', return_value=None): | 94 | 'build_solver_info', return_value=None): |
| 95 | recomputing.step_hook(models) | 95 | recomputing.step_hook(models) |
| 96 | assert get_adaptive_recomputing_policy().context_copy is not None | 96 | assert get_adaptive_recomputing_policy().context_copy is not None |
| @@ -1,9 +1,9 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | -from ascendspeed import megatron_adaptor | 2 | +from mindspeed import megatron_adaptor |
| 3 | import torch.nn as nn | 3 | import torch.nn as nn |
| 4 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute import get_adaptive_recomputing | 4 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute import get_adaptive_recomputing |
| 5 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import get_recompute_hook | 5 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_apply import get_recompute_hook |
| 6 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute import allowed_recomputing_module_wrapper | 6 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute import allowed_recomputing_module_wrapper |
| 7 | 7 | ||
| 8 | from unit_tests.common import DistributedTest | 8 | from unit_tests.common import DistributedTest |
| 9 | 9 | ||
| @@ -1,5 +1,5 @@ | |||
| 1 | # coding=utf-8 | 1 | # coding=utf-8 |
| 2 | -# Copyright (c) 2023, HUAWEI CORPORATION. All rights reserved. | 2 | +# Copyright (c) 2023, Huawei Technologies Co., Ltd. All rights reserved. |
| 3 | # | 3 | # |
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | # you may not use this file except in compliance with the License. | 5 | # you may not use this file except in compliance with the License. |
| @@ -15,8 +15,8 @@ | |||
| 15 | 15 | ||
| 16 | import json | 16 | import json |
| 17 | import unittest | 17 | import unittest |
| 18 | -from ascendspeed import megatron_adaptor | 18 | +from mindspeed import megatron_adaptor |
| 19 | -from ascendspeed.core.memory.adaptive_recomputing.adaptive_recompute_solver import GraphSolver | 19 | +from mindspeed.core.memory.adaptive_recomputing.adaptive_recompute_solver import GraphSolver |
| 20 | 20 | ||
| 21 | from unit_tests.common import DistributedTest | 21 | from unit_tests.common import DistributedTest |
| 22 | 22 | ||
| @@ -1,8 +1,8 @@ | |||
| 1 | import time | 1 | import time |
| 2 | import torch | 2 | import torch |
| 3 | -from ascendspeed import megatron_adaptor | 3 | +from mindspeed import megatron_adaptor |
| 4 | -from ascendspeed.core.memory.adaptive_recomputing.swappable_tensor import SwappableTensor | 4 | +from mindspeed.core.memory.adaptive_recomputing.swappable_tensor import SwappableTensor |
| 5 | -from ascendspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager | 5 | +from mindspeed.core.memory.adaptive_recomputing.swap_manager import SwapManager |
| 6 | 6 | ||
| 7 | from unit_tests.common import DistributedTest | 7 | from unit_tests.common import DistributedTest |
| 8 | 8 | ||
| @@ -2,14 +2,14 @@ import pytest | |||
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | 4 | ||
| 5 | -from ascendspeed.op_builder import AlgorithmOpBuilder | 5 | +from mindspeed.op_builder import AlgorithmOpBuilder |
| 6 | 6 | ||
| 7 | 7 | ||
| 8 | class TestReuseDataPtr: | 8 | class TestReuseDataPtr: |
| 9 | 9 | ||
| 10 | def test_reuse_dptr(self): | 10 | def test_reuse_dptr(self): |
| 11 | - ascendspeed_ops = AlgorithmOpBuilder().load() | 11 | + mindspeed_ops = AlgorithmOpBuilder().load() |
| 12 | fp32_tensor = torch.randn(10, dtype=torch.float).npu() | 12 | fp32_tensor = torch.randn(10, dtype=torch.float).npu() |
| 13 | int8_tensor = torch.empty(fp32_tensor.numel() * 4, dtype=torch.int8).npu() | 13 | int8_tensor = torch.empty(fp32_tensor.numel() * 4, dtype=torch.int8).npu() |
| 14 | - ascendspeed_ops.reuse_data_ptr(int8_tensor, fp32_tensor, 0) | 14 | + mindspeed_ops.reuse_data_ptr(int8_tensor, fp32_tensor, 0) |
| 15 | assert fp32_tensor.data_ptr() == int8_tensor.data_ptr() | 15 | assert fp32_tensor.data_ptr() == int8_tensor.data_ptr() |
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 1 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class TestCachingAllocatorConfig(): | 4 | class TestCachingAllocatorConfig(): |
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 1 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | 4 | ||
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 1 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class TestMallocRecorder(): | 4 | class TestMallocRecorder(): |
| @@ -1,4 +1,4 @@ | |||
| 1 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module | 1 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import load_memory_fragmentation_module |
| 2 | 2 | ||
| 3 | 3 | ||
| 4 | class TestMemoryRecorder(): | 4 | class TestMemoryRecorder(): |
| @@ -2,8 +2,8 @@ import pytest | |||
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | import collections | 4 | import collections |
| 5 | -from ascendspeed import megatron_adaptor | 5 | +from mindspeed import megatron_adaptor |
| 6 | -from ascendspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import change_allocator | 6 | +from mindspeed.core.memory.memory_fragmentation.pluggable_allocator_adpator import change_allocator |
| 7 | 7 | ||
| 8 | 8 | ||
| 9 | 9 | ||
| @@ -4,11 +4,11 @@ import torch | |||
| 4 | from unit_tests.common import DistributedTest | 4 | from unit_tests.common import DistributedTest |
| 5 | from commons import set_random_seed | 5 | from commons import set_random_seed |
| 6 | 6 | ||
| 7 | -from ascendspeed import megatron_adaptor | 7 | +from mindspeed import megatron_adaptor |
| 8 | -from ascendspeed.moe.config import Config | 8 | +from mindspeed.moe.config import Config |
| 9 | -from ascendspeed.moe.gate import TopKGate | 9 | +from mindspeed.moe.gate import TopKGate |
| 10 | -from ascendspeed.moe.experts import Experts | 10 | +from mindspeed.moe.experts import Experts |
| 11 | -from ascendspeed.moe.moe_layer import MOELayer | 11 | +from mindspeed.moe.moe_layer import MOELayer |
| 12 | from megatron.legacy.model.transformer import ParallelMLP | 12 | from megatron.legacy.model.transformer import ParallelMLP |
| 13 | from megatron.core.transformer import TransformerConfig | 13 | from megatron.core.transformer import TransformerConfig |
| 14 | from megatron.training.global_vars import set_args | 14 | from megatron.training.global_vars import set_args |
| @@ -1,11 +1,11 @@ | |||
| 1 | import pytest | 1 | import pytest |
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | -from ascendspeed import megatron_adaptor | 4 | +from mindspeed import megatron_adaptor |
| 5 | from megatron.training.global_vars import set_args | 5 | from megatron.training.global_vars import set_args |
| 6 | from megatron.core.tensor_parallel import ColumnParallelLinear | 6 | from megatron.core.tensor_parallel import ColumnParallelLinear |
| 7 | from megatron.core.transformer.transformer_config import TransformerConfig | 7 | from megatron.core.transformer.transformer_config import TransformerConfig |
| 8 | -from ascendspeed.core.tensor_parallel.ascend_turbo.initialize import initialize_cfg_from_args | 8 | +from mindspeed.core.tensor_parallel.ascend_turbo.initialize import initialize_cfg_from_args |
| 9 | from unit_tests.common import DistributedTest | 9 | from unit_tests.common import DistributedTest |
| 10 | from commons import initialize_model_parallel | 10 | from commons import initialize_model_parallel |
| 11 | from commons import set_random_seed | 11 | from commons import set_random_seed |
| @@ -1,11 +1,11 @@ | |||
| 1 | import pytest | 1 | import pytest |
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | -from ascendspeed import megatron_adaptor | 4 | +from mindspeed import megatron_adaptor |
| 5 | from megatron.training.global_vars import set_args | 5 | from megatron.training.global_vars import set_args |
| 6 | from megatron.core.tensor_parallel import RowParallelLinear | 6 | from megatron.core.tensor_parallel import RowParallelLinear |
| 7 | from megatron.core.transformer.transformer_config import TransformerConfig | 7 | from megatron.core.transformer.transformer_config import TransformerConfig |
| 8 | -from ascendspeed.core.tensor_parallel.ascend_turbo.initialize import initialize_cfg_from_args | 8 | +from mindspeed.core.tensor_parallel.ascend_turbo.initialize import initialize_cfg_from_args |
| 9 | from unit_tests.common import DistributedTest | 9 | from unit_tests.common import DistributedTest |
| 10 | from commons import initialize_model_parallel | 10 | from commons import initialize_model_parallel |
| 11 | from commons import set_random_seed | 11 | from commons import set_random_seed |
| @@ -2,9 +2,9 @@ import pytest | |||
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | import torch.distributed as dist | 4 | import torch.distributed as dist |
| 5 | -import ascendspeed.megatron_adaptor | 5 | +import mindspeed.megatron_adaptor |
| 6 | -from ascendspeed.moe.moe import MoE | 6 | +from mindspeed.moe.moe import MoE |
| 7 | -from ascendspeed.moe.mixtral_parallel_mlpbm import MixtralParallelMLPBM | 7 | +from mindspeed.moe.mixtral_parallel_mlpbm import MixtralParallelMLPBM |
| 8 | from commons import set_random_seed | 8 | from commons import set_random_seed |
| 9 | from unit_tests.common import DistributedTest | 9 | from unit_tests.common import DistributedTest |
| 10 | import megatron.core.parallel_state as ps | 10 | import megatron.core.parallel_state as ps |
| @@ -2,7 +2,7 @@ import pytest | |||
| 2 | import torch | 2 | import torch |
| 3 | import torch.nn.functional as F | 3 | import torch.nn.functional as F |
| 4 | import torch_npu | 4 | import torch_npu |
| 5 | -from ascendspeed import megatron_adaptor | 5 | +from mindspeed import megatron_adaptor |
| 6 | from megatron.training.global_vars import set_args | 6 | from megatron.training.global_vars import set_args |
| 7 | from megatron.training.arguments import parse_args | 7 | from megatron.training.arguments import parse_args |
| 8 | 8 | ||
| @@ -2,7 +2,7 @@ import copy | |||
| 2 | import pytest | 2 | import pytest |
| 3 | import torch | 3 | import torch |
| 4 | import torch_npu # noqa | 4 | import torch_npu # noqa |
| 5 | -import ascendspeed.megatron_adaptor # noqa | 5 | +import mindspeed.megatron_adaptor # noqa |
| 6 | from apex.optimizers import FusedAdam as Adam | 6 | from apex.optimizers import FusedAdam as Adam |
| 7 | 7 | ||
| 8 | from megatron.core import DistributedDataParallel as DDP | 8 | from megatron.core import DistributedDataParallel as DDP |
| @@ -1,7 +1,7 @@ | |||
| 1 | import os | 1 | import os |
| 2 | import pytest | 2 | import pytest |
| 3 | import torch | 3 | import torch |
| 4 | -import ascendspeed.megatron_adaptor | 4 | +import mindspeed.megatron_adaptor |
| 5 | from megatron.core.distributed.param_and_grad_buffer import Bucket | 5 | from megatron.core.distributed.param_and_grad_buffer import Bucket |
| 6 | from megatron.core import parallel_state | 6 | from megatron.core import parallel_state |
| 7 | from megatron.training.global_vars import set_args | 7 | from megatron.training.global_vars import set_args |
| @@ -1,7 +1,7 @@ | |||
| 1 | import copy | 1 | import copy |
| 2 | import pytest | 2 | import pytest |
| 3 | import torch | 3 | import torch |
| 4 | -import ascendspeed.megatron_adaptor | 4 | +import mindspeed.megatron_adaptor |
| 5 | from apex.optimizers import FusedAdam as Adam | 5 | from apex.optimizers import FusedAdam as Adam |
| 6 | 6 | ||
| 7 | from types import SimpleNamespace | 7 | from types import SimpleNamespace |
| @@ -2,7 +2,7 @@ import os | |||
| 2 | import pytest | 2 | import pytest |
| 3 | import torch | 3 | import torch |
| 4 | import torch_npu | 4 | import torch_npu |
| 5 | -import ascendspeed.megatron_adaptor | 5 | +import mindspeed.megatron_adaptor |
| 6 | import megatron.core.parallel_state as ps | 6 | import megatron.core.parallel_state as ps |
| 7 | from unit_tests.common import DistributedTest | 7 | from unit_tests.common import DistributedTest |
| 8 | from megatron.training.global_vars import set_args | 8 | from megatron.training.global_vars import set_args |
| @@ -1,7 +1,7 @@ | |||
| 1 | import pytest | 1 | import pytest |
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | -from ascendspeed import megatron_adaptor | 4 | +from mindspeed import megatron_adaptor |
| 5 | 5 | ||
| 6 | from commons import set_random_seed, initialize_model_parallel | 6 | from commons import set_random_seed, initialize_model_parallel |
| 7 | from unit_tests.common import DistributedTest | 7 | from unit_tests.common import DistributedTest |
Rtests_extend/unit_tests/ascendspeed/core/context_parallel/test_ringattn_context_parallel.py→tests_extend/unit_tests/mindspeed/core/context_parallel/test_ringattn_context_parallel.py+2-2
| @@ -4,10 +4,10 @@ import pytest | |||
| 4 | import torch | 4 | import torch |
| 5 | import torch_npu | 5 | import torch_npu |
| 6 | import torch.distributed as dist | 6 | import torch.distributed as dist |
| 7 | -from ascendspeed import megatron_adaptor | 7 | +from mindspeed import megatron_adaptor |
| 8 | from megatron.training.global_vars import set_args | 8 | from megatron.training.global_vars import set_args |
| 9 | from megatron.training.arguments import parse_args | 9 | from megatron.training.arguments import parse_args |
| 10 | -from ascendspeed.core.context_parallel.ring_context_parallel import ringattn_context_parallel | 10 | +from mindspeed.core.context_parallel.ring_context_parallel import ringattn_context_parallel |
| 11 | 11 | ||
| 12 | from commons import set_random_seed, initialize_model_parallel | 12 | from commons import set_random_seed, initialize_model_parallel |
| 13 | from unit_tests.common import DistributedTest | 13 | from unit_tests.common import DistributedTest |
Rtests_extend/unit_tests/ascendspeed/core/context_parallel/test_ulysses_context_parallel.py→tests_extend/unit_tests/mindspeed/core/context_parallel/test_ulysses_context_parallel.py+2-2
| @@ -5,8 +5,8 @@ import torch | |||
| 5 | import torch_npu | 5 | import torch_npu |
| 6 | import torch.distributed as dist | 6 | import torch.distributed as dist |
| 7 | 7 | ||
| 8 | -from ascendspeed import megatron_adaptor | 8 | +from mindspeed import megatron_adaptor |
| 9 | -from ascendspeed.core.context_parallel.ulysses_context_parallel import UlyssesContextAttention | 9 | +from mindspeed.core.context_parallel.ulysses_context_parallel import UlyssesContextAttention |
| 10 | import megatron.core.parallel_state as ps | 10 | import megatron.core.parallel_state as ps |
| 11 | from megatron.training.global_vars import set_args | 11 | from megatron.training.global_vars import set_args |
| 12 | from megatron.training.arguments import parse_args | 12 | from megatron.training.arguments import parse_args |
Rtests_extend/unit_tests/ascendspeed/test_register_patches.py→tests_extend/unit_tests/mindspeed/test_register_patches.py+17-17
| @@ -1,6 +1,6 @@ | |||
| 1 | from functools import wraps | 1 | from functools import wraps |
| 2 | import pytest | 2 | import pytest |
| 3 | -from ascendspeed.patch_utils import AscendSpeedPatchesManager as aspm | 3 | +from mindspeed.patch_utils import MindSpeedPatchesManager as aspm |
| 4 | from unit_tests.common import DistributedTest | 4 | from unit_tests.common import DistributedTest |
| 5 | 5 | ||
| 6 | 6 | ||
| @@ -48,9 +48,9 @@ class TestRegisterPatches(DistributedTest): | |||
| 48 | world_size = 1 | 48 | world_size = 1 |
| 49 | 49 | ||
| 50 | def test_replace_class_variable(self): | 50 | def test_replace_class_variable(self): |
| 51 | - from unit_tests.ascendspeed.test_register_patches import TestClass | 51 | + from unit_tests.mindspeed.test_register_patches import TestClass |
| 52 | assert TestClass.test_variable == 1 | 52 | assert TestClass.test_variable == 1 |
| 53 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.TestClass.test_variable', 2) | 53 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.TestClass.test_variable', 2) |
| 54 | aspm.apply_patches() | 54 | aspm.apply_patches() |
| 55 | assert TestClass.test_variable == 2 | 55 | assert TestClass.test_variable == 2 |
| 56 | 56 | ||
| @@ -73,43 +73,43 @@ class TestRegisterPatchesResetEnv(DistributedTest): | |||
| 73 | reuse_dist_env = False | 73 | reuse_dist_env = False |
| 74 | 74 | ||
| 75 | def test_replace_function(self): | 75 | def test_replace_function(self): |
| 76 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function2) | 76 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function2) |
| 77 | aspm.apply_patches() | 77 | aspm.apply_patches() |
| 78 | 78 | ||
| 79 | - from unit_tests.ascendspeed.test_register_patches import function1 | 79 | + from unit_tests.mindspeed.test_register_patches import function1 |
| 80 | 80 | ||
| 81 | assert function1() == 'this is function2' | 81 | assert function1() == 'this is function2' |
| 82 | 82 | ||
| 83 | def test_wrapper_function(self): | 83 | def test_wrapper_function(self): |
| 84 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function_wrapper) | 84 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function_wrapper) |
| 85 | aspm.apply_patches() | 85 | aspm.apply_patches() |
| 86 | 86 | ||
| 87 | - from unit_tests.ascendspeed.test_register_patches import function1 | 87 | + from unit_tests.mindspeed.test_register_patches import function1 |
| 88 | 88 | ||
| 89 | assert function1() == 'this is function1 wrapper' | 89 | assert function1() == 'this is function1 wrapper' |
| 90 | 90 | ||
| 91 | def test_multi_patch(self): | 91 | def test_multi_patch(self): |
| 92 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function2) | 92 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function2) |
| 93 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function_wrapper) | 93 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function_wrapper) |
| 94 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function_second_wrapper) | 94 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function_second_wrapper) |
| 95 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function_third_wrapper) | 95 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function_third_wrapper) |
| 96 | aspm.apply_patches() | 96 | aspm.apply_patches() |
| 97 | 97 | ||
| 98 | - from unit_tests.ascendspeed.test_register_patches import function1 | 98 | + from unit_tests.mindspeed.test_register_patches import function1 |
| 99 | 99 | ||
| 100 | assert function1() == 'this is function2 wrapper wrapper2 wrapper3' | 100 | assert function1() == 'this is function2 wrapper wrapper2 wrapper3' |
| 101 | 101 | ||
| 102 | def test_double_patch(self): | 102 | def test_double_patch(self): |
| 103 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function2) | 103 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function2) |
| 104 | 104 | ||
| 105 | with pytest.raises(RuntimeError, match='the patch of function1 exist !'): | 105 | with pytest.raises(RuntimeError, match='the patch of function1 exist !'): |
| 106 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function3) | 106 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function3) |
| 107 | 107 | ||
| 108 | def test_force_double_patch(self): | 108 | def test_force_double_patch(self): |
| 109 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function2) | 109 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function2) |
| 110 | - aspm.register_patch('unit_tests.ascendspeed.test_register_patches.function1', function3, force_patch=True) | 110 | + aspm.register_patch('unit_tests.mindspeed.test_register_patches.function1', function3, force_patch=True) |
| 111 | aspm.apply_patches() | 111 | aspm.apply_patches() |
| 112 | 112 | ||
| 113 | - from unit_tests.ascendspeed.test_register_patches import function1 | 113 | + from unit_tests.mindspeed.test_register_patches import function1 |
| 114 | 114 | ||
| 115 | assert function1() == 'this is function3' | 115 | assert function1() == 'this is function3' |
| @@ -67,7 +67,7 @@ class TestCoC(DistributedTest): | |||
| 67 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') | 67 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') |
| 68 | 68 | ||
| 69 | def test_coc_matmul_all_reduce(self): | 69 | def test_coc_matmul_all_reduce(self): |
| 70 | - from ascendspeed.ops.lcal_functional import coc_ops | 70 | + from mindspeed.ops.lcal_functional import coc_ops |
| 71 | for shape_idx in range(total_shape_num): | 71 | for shape_idx in range(total_shape_num): |
| 72 | for dtype in dtype_list: | 72 | for dtype in dtype_list: |
| 73 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] | 73 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] |
| @@ -94,7 +94,7 @@ class TestCoC(DistributedTest): | |||
| 94 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') | 94 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') |
| 95 | 95 | ||
| 96 | def test_coc_all_gather_matmul(self): | 96 | def test_coc_all_gather_matmul(self): |
| 97 | - from ascendspeed.ops.lcal_functional import coc_ops | 97 | + from mindspeed.ops.lcal_functional import coc_ops |
| 98 | for shape_idx in range(total_shape_num): | 98 | for shape_idx in range(total_shape_num): |
| 99 | for dtype in dtype_list: | 99 | for dtype in dtype_list: |
| 100 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] | 100 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] |
| @@ -121,7 +121,7 @@ class TestCoC(DistributedTest): | |||
| 121 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') | 121 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') |
| 122 | 122 | ||
| 123 | def test_coc_all_gather_matmul_v2(self): | 123 | def test_coc_all_gather_matmul_v2(self): |
| 124 | - from ascendspeed.ops.lcal_functional import coc_ops | 124 | + from mindspeed.ops.lcal_functional import coc_ops |
| 125 | for shape_idx in range(total_shape_num): | 125 | for shape_idx in range(total_shape_num): |
| 126 | for dtype in dtype_list: | 126 | for dtype in dtype_list: |
| 127 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] | 127 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] |
| @@ -151,7 +151,7 @@ class TestCoC(DistributedTest): | |||
| 151 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') | 151 | # @pytest.mark.skipif(DEVICE_NAME != 'Ascend910B', reason='device type is not supported, skip this UT!') |
| 152 | 152 | ||
| 153 | def test_coc_matmul_reduce_scatter(self): | 153 | def test_coc_matmul_reduce_scatter(self): |
| 154 | - from ascendspeed.ops.lcal_functional import coc_ops | 154 | + from mindspeed.ops.lcal_functional import coc_ops |
| 155 | for shape_idx in range(total_shape_num): | 155 | for shape_idx in range(total_shape_num): |
| 156 | for dtype in dtype_list: | 156 | for dtype in dtype_list: |
| 157 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] | 157 | m, k, n = shape_list[shape_idx][0], shape_list[shape_idx][1], shape_list[shape_idx][2] |
| @@ -2,7 +2,7 @@ import pytest | |||
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | 4 | ||
| 5 | -from ascendspeed.ops import npu_dropout_add_layer_norm, npu_dropout_add_rms_norm | 5 | +from mindspeed.ops import npu_dropout_add_layer_norm, npu_dropout_add_rms_norm |
| 6 | 6 | ||
| 7 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] | 7 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] |
| 8 | 8 | ||
| @@ -2,7 +2,7 @@ import pytest | |||
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | 4 | ||
| 5 | -from ascendspeed.op_builder import GMMOpBuilder | 5 | +from mindspeed.op_builder import GMMOpBuilder |
| 6 | 6 | ||
| 7 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] | 7 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] |
| 8 | 8 | ||
| @@ -25,8 +25,8 @@ class TestNPUGMM: | |||
| 25 | return torch.cat([x for x in final_out], dim=0) | 25 | return torch.cat([x for x in final_out], dim=0) |
| 26 | 26 | ||
| 27 | def custom_op_exec(self, x, weight, bias, group_list, group_type): | 27 | def custom_op_exec(self, x, weight, bias, group_list, group_type): |
| 28 | - ascendspeed_ops = GMMOpBuilder().load() | 28 | + mindspeed_ops = GMMOpBuilder().load() |
| 29 | - return ascendspeed_ops.npu_gmm(x, weight, bias, group_list, group_type) | 29 | + return mindspeed_ops.npu_gmm(x, weight, bias, group_list, group_type) |
| 30 | 30 | ||
| 31 | 31 | ||
| 32 | def test_npu_gmm(self): | 32 | def test_npu_gmm(self): |
| @@ -5,7 +5,7 @@ import torch.distributed as dist | |||
| 5 | from torch.distributed.distributed_c10d import _get_default_group, ReduceOp | 5 | from torch.distributed.distributed_c10d import _get_default_group, ReduceOp |
| 6 | import torch_npu | 6 | import torch_npu |
| 7 | from unit_tests.common import DistributedTest | 7 | from unit_tests.common import DistributedTest |
| 8 | -from ascendspeed.op_builder import GroupedMatMulAllReduceOpBuilder | 8 | +from mindspeed.op_builder import GroupedMatMulAllReduceOpBuilder |
| 9 | 9 | ||
| 10 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] | 10 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] |
| 11 | 11 | ||
| @@ -36,8 +36,8 @@ class TestNPUGroupedMatMulAllReduce(DistributedTest): | |||
| 36 | return output_npu | 36 | return output_npu |
| 37 | 37 | ||
| 38 | def custom_op_exec(self, x, weight, bias, group_list, split_item, hccl_group, reduce_op, comm_turn): | 38 | def custom_op_exec(self, x, weight, bias, group_list, split_item, hccl_group, reduce_op, comm_turn): |
| 39 | - ascendspeed_ops = GroupedMatMulAllReduceOpBuilder().load() | 39 | + mindspeed_ops = GroupedMatMulAllReduceOpBuilder().load() |
| 40 | - return ascendspeed_ops.npu_grouped_mat_mul_all_reduce(x, weight, bias, group_list, split_item, | 40 | + return mindspeed_ops.npu_grouped_mat_mul_all_reduce(x, weight, bias, group_list, split_item, |
| 41 | hccl_group, reduce_op, comm_turn) | 41 | hccl_group, reduce_op, comm_turn) |
| 42 | 42 | ||
| 43 | def get_hcomm_info(self, n, i): | 43 | def get_hcomm_info(self, n, i): |
| @@ -5,7 +5,7 @@ import torch.distributed as dist | |||
| 5 | from torch.distributed.distributed_c10d import _get_default_group, ReduceOp | 5 | from torch.distributed.distributed_c10d import _get_default_group, ReduceOp |
| 6 | import torch_npu | 6 | import torch_npu |
| 7 | from unit_tests.common import DistributedTest | 7 | from unit_tests.common import DistributedTest |
| 8 | -from ascendspeed.ops.npu_mm_all_reduce_add_rms_norm import npu_mm_all_reduce_add_rms_norm | 8 | +from mindspeed.ops.npu_mm_all_reduce_add_rms_norm import npu_mm_all_reduce_add_rms_norm |
| 9 | 9 | ||
| 10 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] | 10 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] |
| 11 | 11 | ||
| @@ -5,7 +5,7 @@ import torch.distributed as dist | |||
| 5 | from torch.distributed.distributed_c10d import _get_default_group, ReduceOp | 5 | from torch.distributed.distributed_c10d import _get_default_group, ReduceOp |
| 6 | import torch_npu | 6 | import torch_npu |
| 7 | from unit_tests.common import DistributedTest | 7 | from unit_tests.common import DistributedTest |
| 8 | -from ascendspeed.ops.npu_mm_all_reduce_add_rms_norm_ import npu_mm_all_reduce_add_rms_norm_ | 8 | +from mindspeed.ops.npu_mm_all_reduce_add_rms_norm_ import npu_mm_all_reduce_add_rms_norm_ |
| 9 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] | 9 | DEVICE_NAME = torch_npu.npu.get_device_name(0)[:10] |
| 10 | 10 | ||
| 11 | 11 | ||
| @@ -3,7 +3,7 @@ import pytest | |||
| 3 | import torch | 3 | import torch |
| 4 | from torch import nn | 4 | from torch import nn |
| 5 | import torch_npu | 5 | import torch_npu |
| 6 | -from ascendspeed import megatron_adaptor | 6 | +from mindspeed import megatron_adaptor |
| 7 | from megatron.legacy.model.rms_norm import RMSNorm | 7 | from megatron.legacy.model.rms_norm import RMSNorm |
| 8 | from megatron.training.global_vars import set_args | 8 | from megatron.training.global_vars import set_args |
| 9 | 9 | ||
| @@ -1,7 +1,7 @@ | |||
| 1 | import pytest | 1 | import pytest |
| 2 | import torch | 2 | import torch |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | -from ascendspeed import megatron_adaptor | 4 | +from mindspeed import megatron_adaptor |
| 5 | from megatron.legacy.model.transformer import ParallelMLP | 5 | from megatron.legacy.model.transformer import ParallelMLP |
| 6 | from unit_tests.common import DistributedTest | 6 | from unit_tests.common import DistributedTest |
| 7 | from commons import initialize_model_parallel | 7 | from commons import initialize_model_parallel |