当前位置: 首页 > news >正文

Atlas 200I DK A2安装MindSpore Ascend版本

一、参考资料

mindspore快速安装

二、重要说明

经过博主多次尝试多个版本,Atlas 200I DK A2无法安装MindSpore Ascend版本

也有其他博主测试,也未尝成功,例如:【MindSpore易点通·漫游世界】在Atlas 200I DK A2 (CANN6.2.RC2)上安装MindSpore Ascend版的踩坑记录

mindspore 1.5.2 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 1.6.2 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 1.7.1 报错无法运行 (./tensor_add_sample: error while loading shared libraries: libhccl.so: cannot open shared object file: No such file or directory)

mindspore 1.8.1 报错无法运行(./tensor_add_sample: error while loading shared libraries: libhccl.so: cannot open shared object file: No such file or directory)

mindspore 1.9.0 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 1.10.1 报错无法运行(./tensor_add_sample: symbol lookup error: /home/HwHiAiUser/.local/lib/python3.9/site-packages/mindspore/lib/libmindspore.so: undefined symbol: _ZN2ge5Model8SetGraphERKNS_5GraphE)

mindspore 2.0.0 报错无法运行(Unsupported device target Ascend)

mindspore 2.1.0 报错无法运行(Unsupported device target Ascend)

三、准备工作

1. 测试环境

设备型号:Atlas 200I DK A2
Operating System + Version: Ubuntu 22.04 LTS
CPU Type: 4核TAISHANV200M处理器
AI CPU number: 0
control CPU number: 4
RAM: 4GB 
miscroSD: 128GB
CANN Vertion: 7.0.RC1
HwHiAiUser@davinci-mini:~$ npu-smi info -t aicpu-config -i 0 -c 0Current AI CPU number          : 0Current control CPU number     : 4Number of AI CPUs set          : 0Number of control CPUs set     : 4

2. MindSpore与CANN版本对齐

通过 链接 查询MindSpore与Ascend配套软件包的版本配套关系。

在这里插入图片描述

3. 安装mindspore_ascend

详细过程,请参考:pip方式安装MindSpore Ascend 310版本

4. 验证是否安装成功

4.1 方法一

import mindspore as ms# ms.set_context(device_target='CPU')
# ms.set_context(device_target='GPU')
ms.set_context(device_target="Ascend")
ms.set_context(device_id=0)
mindspore.run_check()

如果输出以下结果,则说明mindspore_ascend安装成功。

MindSpore version: 版本号
The result of multiplication calculation is correct, MindSpore has been installed on platform [Ascend] successfully!

4.2 方法二

import numpy as np
import mindspore as ms
import mindspore.ops as opsms.set_context(device_target="Ascend")
x = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
y = ms.Tensor(np.ones([1,3,3,4]).astype(np.float32))
print(ops.add(x, y))

如果输出以下结果,则说明mindspore_ascend安装成功。

[[[[2. 2. 2. 2.][2. 2. 2. 2.][2. 2. 2. 2.]][[2. 2. 2. 2.][2. 2. 2. 2.][2. 2. 2. 2.]][[2. 2. 2. 2.][2. 2. 2. 2.][2. 2. 2. 2.]]]]

4.3 方法三

ascend310_single_op_sample

这是一个[1, 2, 3, 4][2, 3, 4, 5]相加的简单样例,代码工程目录结构如下:

└─ascend310_single_op_sample├── CMakeLists.txt                    // 编译脚本├── README.md                         // 使用说明├── main.cc                           // 主函数└── tensor_add.mindir                 // MindIR模型文件
unzip ascend310_single_op_sample.zip
cd ascend310_single_op_sample# 编译
cmake . -DMINDSPORE_PATH=`pip show mindspore-ascend | grep Location | awk '{print $2"/mindspore"}' | xargs realpath`
make# 执行
./tensor_add_sample

如果输出以下结果,则说明mindspore_ascend安装成功。

3
5
7
9

四、测试代码

1. 示例一

用MindSpore搭建模型,并进行测试。

"""
MindSpore implementation of `MobileNetV1`.
Refer to MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications.
"""
import timefrom mindspore import nn, Tensor, ops
import mindspore.common.initializer as init
import mindspore as ms
from PIL import Image
from mindcv.data import create_transforms
import numpy as npdef depthwise_separable_conv(inp: int, oup: int, stride: int) -> nn.SequentialCell:return nn.SequentialCell(# dwnn.Conv2d(inp, inp, 3, stride, pad_mode="pad", padding=1, group=inp, has_bias=False),nn.BatchNorm2d(inp),nn.ReLU(),# pwnn.Conv2d(inp, oup, 1, 1, pad_mode="pad", padding=0, has_bias=False),nn.BatchNorm2d(oup),nn.ReLU(),)class MobileNetV1(nn.Cell):r"""MobileNetV1 model class, based on`"MobileNets: Efficient Convolutional Neural Networks for Mobile Vision Applications" <https://arxiv.org/abs/1704.04861>`_Args:alpha: scale factor of model width. Default: 1.in_channels: number the channels of the input. Default: 3.num_classes: number of classification classes. Default: 1000."""def __init__(self,alpha: float = 1.,in_channels: int = 3,num_classes: int = 1000) -> None:super().__init__()input_channels = int(32 * alpha)# Setting of depth-wise separable conv# c: number of output channel# s: stride of depth-wise convblock_setting = [# c, s[64, 1],[128, 2],[128, 1],[256, 2],[256, 1],[512, 2],[512, 1],[512, 1],[512, 1],[512, 1],[512, 1],[1024, 2],[1024, 1],]features = [nn.Conv2d(in_channels, input_channels, 3, 2, pad_mode="pad", padding=1, has_bias=False),nn.BatchNorm2d(input_channels),nn.ReLU()]for c, s in block_setting:output_channel = int(c * alpha)features.append(depthwise_separable_conv(input_channels, output_channel, s))input_channels = output_channelself.features = nn.SequentialCell(features)# self.pool = GlobalAvgPooling()self.pool = nn.AdaptiveAvgPool2d(output_size=(1, 1))self.classifier = nn.Dense(input_channels, num_classes)self._initialize_weights()def _initialize_weights(self) -> None:"""Initialize weights for cells."""for _, cell in self.cells_and_names():if isinstance(cell, nn.Conv2d):cell.weight.set_data(init.initializer(init.XavierUniform(),cell.weight.shape,cell.weight.dtype))if isinstance(cell, nn.Dense):cell.weight.set_data(init.initializer(init.TruncatedNormal(),cell.weight.shape,cell.weight.dtype))def forward_features(self, x: Tensor) -> Tensor:x = self.features(x)return xdef forward_head(self, x: Tensor) -> Tensor:squeeze = ops.Squeeze(0)x = squeeze(x)x = self.pool(x)squeeze = ops.Squeeze(2)x = squeeze(x)x = x.transpose()x = self.classifier(x)return xdef construct(self, x: Tensor) -> Tensor:x = self.forward_features(x)x = self.forward_head(x)return xdef mobilenet_v1_100_224(pretrained: bool = False, num_classes: int = 1000, in_channels=3, **kwargs) -> MobileNetV1:"""Get MobileNetV1 model without width scaling.Refer to the base class `models.MobileNetV1` for more details."""model = MobileNetV1(alpha=1.0, in_channels=in_channels, num_classes=num_classes, **kwargs)return modelif __name__ == '__main__':# ms.set_context(device_target='GPU')# ms.set_context(device_target='CPU')ms.set_context(device_target="Ascend")ms.set_context(device_id=0)ms.set_seed(1)ms.set_context(mode=ms.PYNATIVE_MODE)img = Image.open("image.jpg").convert("RGB")# create transformtransform_list = create_transforms(dataset_name="imagenet",is_training=False,)transform_list.pop(0)for transform in transform_list:img = transform(img)img = np.expand_dims(img, axis=0)# create modelnetwork = mobilenet_v1_100_224()for i in range(100):# warmupnetwork(ms.Tensor(img))time_begin = time.time()for i in range(1000):# predictnetwork(ms.Tensor(img))time_total = (time.time() - time_begin) * 1000 / 1000print(f"total time is: {time_total}")# print(network)

2. 示例二

调用 mindcv库中的预训练模型进行测试。

"""MindSpore Inference Script
"""import numpy as np
from PIL import Imageimport mindspore as msfrom mindcv.data import create_transforms
from mindcv.models import create_model
import time# ms.set_context(device_target='CPU')
# ms.set_context(device_target='GPU')ms.set_context(device_target='Ascend')
ms.set_context(device_id=0)
ms.set_context(max_device_memory="3.5GB")def main():ms.set_seed(1)ms.set_context(mode=ms.PYNATIVE_MODE)img = Image.open("image.jpg").convert("RGB")# create transformtransform_list = create_transforms(dataset_name="imagenet",is_training=False,)transform_list.pop(0)for transform in transform_list:img = transform(img)img = np.expand_dims(img, axis=0)# create modelnetwork = create_model(model_name="mobilenet_v1_100",  # mobilenet_v1_100_224pretrained=False,)network.set_train(False)for i in range(100):# warmupnetwork(ms.Tensor(img))time_begin = time.time()for i in range(1000):# predictnetwork(ms.Tensor(img))time_total = (time.time() - time_begin) * 1000 / 1000print(f"total time is: {time_total}")if __name__ == "__main__":main()

五、FAQ

Q:RuntimeError: Load op info form json config failed, version: Ascend310B4

[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:28.302.942 [mindspore/run_check/_check_version.py:375] MindSpore version 2.1.1 and "te" wheel package version 7.0 does not match. For details, refer to the installation guidelines: https://www.mindspore.cn/install
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:28.305.619 [mindspore/run_check/_check_version.py:382] MindSpore version 2.1.1 and "hccl" wheel package version 7.0 does not match. For details, refer to the installation guidelines: https://www.mindspore.cn/install
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:28.305.849 [mindspore/run_check/_check_version.py:396] Please pay attention to the above warning, countdown: 3
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:29.307.139 [mindspore/run_check/_check_version.py:396] Please pay attention to the above warning, countdown: 2
[WARNING] ME(230369:255086392991776,MainProcess):2024-05-25-17:29:30.308.249 [mindspore/run_check/_check_version.py:396] Please pay attention to the above warning, countdown: 1
[ERROR] KERNEL(230369,e7ffaf56f120,python):2024-05-25-17:29:35.761.869 [mindspore/ccsrc/kernel/oplib/op_info_utils.cc:172] LoadOpInfoJson] Get op info json suffix path failed, soc_version: Ascend310B4
[ERROR] KERNEL(230369,e7ffaf56f120,python):2024-05-25-17:29:35.762.199 [mindspore/ccsrc/kernel/oplib/op_info_utils.cc:111] GenerateOpInfos] Load op info json failed, version: Ascend310B4
Traceback (most recent call last):File "/root/Downloads/mindspore_ascend_demo.py", line 8, in <module>print(ops.add(x, y))File "/usr/local/miniconda3/envs/mindspore22/lib/python3.9/site-packages/mindspore/common/_stub_tensor.py", line 49, in funreturn method(*arg, **kwargs)File "/usr/local/miniconda3/envs/mindspore22/lib/python3.9/site-packages/mindspore/common/tensor.py", line 486, in __str__return str(self.asnumpy())File "/usr/local/miniconda3/envs/mindspore22/lib/python3.9/site-packages/mindspore/common/tensor.py", line 924, in asnumpyreturn Tensor_.asnumpy(self)
RuntimeError: Load op info form json config failed, version: Ascend310B4----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc:431 Init[ERROR] PIPELINE(230369,e7ffedd76020,python):2024-05-25-17:29:35.824.442 [mindspore/ccsrc/pipeline/jit/pipeline.cc:2311] ClearResAtexit] Check exception before process exit: Load op info form json config failed, version: Ascend310B4----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/ascend/hal/device/ascend_kernel_runtime.cc:431 Init

mindspore_ascend 2.1.1 测试失败。

Q:RuntimeError: The device address type is wrong: type name in address:CPU, type name in context:Ascend

RuntimeError: The device address type is wrong: type name in address:CPU, type name in context:Ascend----------------------------------------------------
- C++ Call Stack: (For framework developers)
----------------------------------------------------
mindspore/ccsrc/plugin/device/ascend/hal/hardware/ge_device_res_manager.cc:72 AllocateMemory

mindspore_ascend 2.2.0 测试失败。

相关文章:

  • Yolov9调用COCOAPI生成APs,APm,APl
  • 每日OJ题_剑指offer斐波那契数列篇
  • 奇舞周刊第529期:万字长文入门前端全球化
  • STM32F1之OV7725摄像头
  • Golang | Leetcode Golang题解之第112题路径总和
  • 医院门诊互联电子病历|基于SSM+vue的医院门诊互联电子病历管理信息系统的设计与实现(源码+数据库+文档)
  • 存在重复元素 II[简单]
  • 文件编码格式查看和转换
  • Websocket助手
  • pyhton调用STK常用代码
  • 【vue3】嵌套的 effect 与 effect 栈
  • 【spring】@ControllerAdvice注解学习
  • 【设计模式】桥接模式
  • 小皮面板中访问不了本地的sqli网站---解决方法
  • 【Andoird开发】android获取蓝牙权限,搜索蓝牙设备MAC
  • 2018一半小结一波
  • AHK 中 = 和 == 等比较运算符的用法
  • isset在php5.6-和php7.0+的一些差异
  • Java 网络编程(2):UDP 的使用
  • Linux编程学习笔记 | Linux多线程学习[2] - 线程的同步
  • mysql常用命令汇总
  • 京东美团研发面经
  • 聚簇索引和非聚簇索引
  • 前端性能优化--懒加载和预加载
  • 一个JAVA程序员成长之路分享
  • 3月27日云栖精选夜读 | 从 “城市大脑”实践,瞭望未来城市源起 ...
  • 回归生活:清理微信公众号
  • ###STL(标准模板库)
  • #HarmonyOS:软件安装window和mac预览Hello World
  • #Linux(权限管理)
  • $.ajax中的eval及dataType
  • (2015)JS ES6 必知的十个 特性
  • (3)选择元素——(14)接触DOM元素(Accessing DOM elements)
  • (4) PIVOT 和 UPIVOT 的使用
  • (solr系列:一)使用tomcat部署solr服务
  • (附源码)ssm本科教学合格评估管理系统 毕业设计 180916
  • (附源码)ssm高校志愿者服务系统 毕业设计 011648
  • (附源码)基于SpringBoot和Vue的厨到家服务平台的设计与实现 毕业设计 063133
  • (蓝桥杯每日一题)平方末尾及补充(常用的字符串函数功能)
  • (每日持续更新)信息系统项目管理(第四版)(高级项目管理)考试重点整理第3章 信息系统治理(一)
  • (四)Controller接口控制器详解(三)
  • (杂交版)植物大战僵尸
  • (转载)虚幻引擎3--【UnrealScript教程】章节一:20.location和rotation
  • *Django中的Ajax 纯js的书写样式1
  • ..thread“main“ com.fasterxml.jackson.databind.JsonMappingException: Jackson version is too old 2.3.1
  • .gitattributes 文件
  • .NET CF命令行调试器MDbg入门(三) 进程控制
  • .Net CoreRabbitMQ消息存储可靠机制
  • .project文件
  • /dev/sda2 is mounted; will not make a filesystem here!
  • @RequestMapping用法详解
  • @selector(..)警告提示
  • [ 云计算 | Azure 实践 ] 在 Azure 门户中创建 VM 虚拟机并进行验证
  • [.net] 如何在mail的加入正文显示图片
  • [AIR] NativeExtension在IOS下的开发实例 --- IOS项目的创建 (一)