1 报错形容
1.1 零碎环境
Hardware Environment(Ascend/GPU/CPU): GPU
Software Environment:
– MindSpore version (source or binary): 1.5.2
– 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 脚本
训练脚本是通过构建 Minimum 的单算子网络,计算输出 Tensor 对应元素的最小值。脚本如下:
01 class Net(nn.Cell):
02 def __init__(self):
03 super(Net, self).__init__()
04 self.minimum = ops.minumum()
05 def construct(self, x,y):
06 output = self.minimum(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 = Tensor(np.array([3.0, 5.0, 6.0]), mindspore.float64) .astype(mindspore.float32)
11 output = net(x, y)
12 print(‘output’, output)
1.2.2 报错
这里报错信息如下:
[EXCEPTION] PYNATIVE(95109,7fe22ea22740,python):2022-06-14-21:59:02.837.339 [mindspore/ccsrc/pipeline/pynative/pynative_execute.cc:1331] SetImplicitCast] Minimum inputs size 0 does not match the requires signature size 2
Traceback (most recent call last):
File “182168.py”, line 36, in <module>
net = Net()
File “182168.py”, line 24, in init
self.minimum = ops.minimum()
File “/data2/llj/mindspores/r1.5/build/package/mindspore/ops/primitive.py”, line 247, in call
return _run_op(self, self.name, args)
File “/data2/llj/mindspores/r1.5/build/package/mindspore/common/api.py”, line 78, in wrapper
results = fn(*arg, **kwargs)
File “/data2/llj/mindspores/r1.5/build/package/mindspore/ops/primitive.py”, line 682, in _run_op
output = real_run_op(obj, op_name, args)
ValueError: mindspore/ccsrc/pipeline/pynative/pynative_execute.cc:1331 SetImplicitCast] Minimum inputs size 0 does not match the requires signature size 2
起因剖析
咱们看报错信息,在 ValueError 中,写到 Minimum inputs size 0 does not match the requires signature size 2,大略意思是须要两个输出,但理论没有输出。联合第 11 行发现其实是传入了两个输出的。所以问题可能就不是出在这一行,咱们能够在 3,5,11 行前面别离加上一个打印标记,看程序执行到了哪个地位。执行后发现只打印了 1,阐明问题就出在第四行,仔细检查发现第四行初始化 Minimum 算子的时候 minimum 用的小写,相当于间接调用了函数式接口 minimum 算子,所以报错没有传入参数。
2 解决办法
基于下面已知的起因,很容易做出如下批改:
01 class Net(nn.Cell):
02 def __init__(self):
03 super(Net, self).__init__()
04 self.minimum = ops.Minimum()
05 def construct(self, x,y):
06 output = self.minimum(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 = Tensor(np.array([3.0, 5.0, 6.0]), mindspore.float64) .astype(mindspore.float32)
11 output = net(x, y)
12 print(‘output’, output)
此时执行胜利,输入如下:
output [1. 2. 3.]
3 总结
定位报错问题的步骤:
1、找到报错的用户代码行:self.minimum = ops.minimum();
2、依据日志报错信息中的关键字,放大剖析问题的范畴 Minimum inputs size 0 does not match the requires signature size 2 ;
3、须要重点关注变量定义、初始化的正确性。
4 参考文档
4.1 Minimum 算子 API 接口