MindSpore报错:无法在AI CORE或AI CPU内核信息候选列表中为[Default/Pow-op0]选择有效的内核信息:

1 报错描述

1.1 系统环境

Hardware Environment(Ascend/GPU/CPU): Ascend
Software Environment:
-- MindSpore version (source or binary): 1.6.0
-- Python version (e.g., Python 3.7.5): 3.7.6
-- OS platform and distribution (e.g., Linux Ubuntu 16.04): Ubuntu 4.15.0-74-generic
-- GCC/Compiler version (if compiled from source):

1.2 基本信息

1.2.1 脚本

01 class Net(nn.Cell):
02   def __init__(self):
03     super(Net, self).__init__()
04     self.pow = ops.Pow()
05   def construct(self, x,y):
06     output = self.pow(x, y)
07     return output
08 net = Net()
09 x = Tensor(np.array([1.0, 2.0, 4.0]), mindspore.float64) .astype(mindspore.float32)
10 y = 3.0
11 output = net(x, y)
12 print('output', output)

训练脚本是通过构建Pow的单算子网络,对第一个输入的每个值进行幂运算。脚本如下:

1.2.2

这里报错信息如下:

Traceback (most recent call last):
 File 'demo.py', line 11, in <module>
​    output = net(x, y)
…
TypeError: mindspore/ccsrc/runtime/device/ascend/kernel_select_ascend.cc:788 PrintNotMatchMessage] Can not select a valid kernel info for [Default/Pow-op0] in AI CORE or AI CPU kernel info candidates list:
AI CORE:
(<Int8xDefaultFormat>, <Int8xDefaultFormat>) -> (<Int8xDefaultFormat>)
(<UInt8xDefaultFormat>, <UInt8xDefaultFormat>) -> (<UInt8xDefaultFormat>)
(<Int32xDefaultFormat>, <Int32xDefaultFormat>) -> (<Int32xDefaultFormat>)
(<Float16xDefaultFormat>, <Float16xDefaultFormat>) -> (<Float16xDefaultFormat>)
(<Float32xDefaultFormat>, <Float32xDefaultFormat>) -> (<Float32xDefaultFormat>)
AI CPU:
{}
Please check the given data type or shape:
AI CORE:    : (<Tensor[Float64], (3)>, <Tensor[Float64], (), value=...>) -> (<Tensor[Float64], (3)>)
AI CPU:    : (<Tensor[Float64], (3)>, <Tensor[Float64], (), value=...>) -> (<Tensor[Float64], (3)>)
For more details, please refer to 'Kernel Select Failed' at https://www.mindspore.cn
The function call stack:
In file demo.py(06)/    output = self.pow(x, y)/

2 原因分析

我们看报错信息,在TypeError中,写到 Can not select a valid kernel info for [Default/Pow-op0] in AI CORE or AI CPU kernel info candidates list ,结合后边列出的数据类型格式,不难猜出这是在提示传入的数据类型不在支持的类型范围内,支持的数据类型为:int8、uint8、int32、float16、float32,再结合*Please check the given data type or shape:AI CORE : (<Tensor[Float64], (3)>*可知,传入的数据类型为float64, 检查代码发现,09行代码传入的数据类型确实为float64,此时需要将该类型转化为其他支持类型。

2 解决方法

基于上面已知的原因,很容易做出如下修改:


此时执行成功,输出如下:
output [ 1. 8. 64.]

3 总结

定位报错问题的步骤:
1、 找到报错的用户代码行: output = self.pow(x, y) ; 2、 根据日志报错信息中的关键字,缩小分析问题的范围; 3、需要重点关注变量定义、初始化的正确性。

4 参考文档

Pow算子API接口