Are you sure you want to delete this task? Once this task is deleted, it cannot be recovered.
pengtao 54efd35409 | 1 year ago | |
---|---|---|
ms_adapter | 1 year ago | |
testing/ut | 1 year ago | |
third_party/einops | 1 year ago | |
.drone.yml | 1 year ago | |
.gitignore | 1 year ago | |
CONTRIBUTING_CN.md | 1 year ago | |
LICENSE | 1 year ago | |
README.md | 1 year ago | |
SupportedList.md | 1 year ago | |
pylint_check.sh | 1 year ago | |
pylintrc | 1 year ago | |
requirements.txt | 1 year ago | |
run.sh | 1 year ago | |
setup.py | 1 year ago |
简体中文 | English
MindSpore适配PyTorch接口工具。
MSAdapter可以使PyTorch的模型在昇腾(Ascend)上运行。
import torch
替换为import ms_adapter.pytorch
即可实现模型能支持昇腾上训练。请根据MindSpore官网安装指南,安装2.0.0及以上版本的MindSpore。
pip install ms_adapter
git clone https://git.openi.org.cn/OpenI/MSAdapter.git
cd MSAdapter
python setup.py install
如果出现权限不足的提示,请按照如下方式安装:
python setup.py install --user || exit 1
在构建模型上,MSAdapter可以和PyTorch一样使用,示例如下:
from ms_adapter.pytorch.nn import Module, Linear, Flatten
class MLP(Module):
def __init__(self):
super(MLP, self).__init__()
self.flatten = Flatten()
self.line1 = Linear(in_features=1024, out_features=64)
self.line2 = Linear(in_features=64, out_features=128, bias=False)
self.line3 = Linear(in_features=128, out_features=10)
def forward(self, inputs):
x = self.flatten(inputs)
x = self.line1(x)
x = self.line2(x)
x = self.line3(x)
return x
net = MLP()
对于网络迁移工作,从PyTorch代码迁移到MindSpore只需修改导入包。
Q:设置context.set_context(mode=context.GRAPH_MODE)后运行出现类似问题:Tensor.add_
is an in-place operation and "x.add_()" is not encouraged to use in MindSpore static graph mode. Please use "x = x.add()" or other API instead。
A:目前在设置GRAPH模式下不支持原地操作相关的接口,需要按照提示信息进行修改。需要注意的是,即使在PYNATIVE模式下,原地操作相关接口也是不鼓励使用的,因为目前在MSAdapter不会带来内存收益,而且会给反向梯度计算带来不确定性。
Q:运行代码出现类似报错信息:AttributeError: module 'ms_adapter.pytorch' has no attribute 'xxx'。
A:首先确定'xxx'是否为torch 1.12版本支持的接口,PyTorch官网明确已废弃或者即将废弃的接口和参数,MSAdapter不会兼容支持,请使用其他同等功能的接口代替。如果是PyTorch对应版本支持,而MSAdapter中暂时没有,欢迎参与MSAdapter项目贡献你的代码,也可以通过创建任务(New issue)反馈需求。
MindSpore对PyTorch接口的支持工具
Python Markdown
Dear OpenI User
Thank you for your continuous support to the Openl Qizhi Community AI Collaboration Platform. In order to protect your usage rights and ensure network security, we updated the Openl Qizhi Community AI Collaboration Platform Usage Agreement in January 2024. The updated agreement specifies that users are prohibited from using intranet penetration tools. After you click "Agree and continue", you can continue to use our services. Thank you for your cooperation and understanding.
For more agreement content, please refer to the《Openl Qizhi Community AI Collaboration Platform Usage Agreement》