[Solved] MindSpore Error: ValueError: Minimum inputs size 0 does not match…

1 Error description

1.1 System Environment

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

1.2 Basic information

1.2.1 Script

The training script calculates the minimum value of the corresponding elements of the input Tensor by constructing a single-operator network of Minimum. The script is as follows:

 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 Error reporting

The error message here is as follows:

[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

Cause Analysis

Let’s look at the error message. In ValueError, it is written that Minimum inputs size 0 does not match the requires signature size 2, which probably means that two inputs are required, but there are actually no inputs. Combined with line 11, it is found that two inputs are actually passed in. So the problem may not lie in this line. We can add a print mark after lines 3, 5, and 11 to see where the program is executed. After execution, it is found that only 1 is printed, indicating that the problem lies in the fourth line. After careful inspection, it is found that the minimum is in lowercase when the minimum operator is initialized in the fourth line, which is equivalent to directly calling the functional interface minimum operator, so the error is not passed. input parameters.

2 Solutions

For the reasons known above, it is easy to make the following modifications:

 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)

At this point, the execution is successful, and the output is as follows:

output [1. 2. 3.]

3 Summary

Steps to locate the error report:

1. Find the line of user code that reports the error: self.minimum = ops.minimum() ;

2. According to the keywords in the log error message, narrow down the scope of the analysis problem. Minimum inputs size 0 does not match the requires signature size 2  ;

3. It is necessary to focus on the correctness of variable definition and initialization.

Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *