1 Error description
1.1 System Environment
Hardware Environment(Ascend/GPU/CPU): Ascend
Software Environment:
– MindSpore version (source or binary): 1.8.0
– 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 is to construct a simple operator network, perform the Add operation on the input two tensors, and then call the Tensor
Summary. The script is as follows:
01 class SummaryNet(nn.Cell):
02 def __init__(self,):
03 super(SummaryNet, self).__init__()
04 self.summary = ops.TensorSummary()
05 self.add = ops.Add()
06
07 def construct(self, x, y):
08 x = self.add(x, y)
09 name = "x"
10 self.summary(name, x.sum())
11 return x
12
13 x = Tensor(np.array([1, 2, 3]).astype(np.float32))
14 y = Tensor(np.array([4, 5, 6]).astype(np.float32))
15 summary_net = SummaryNet()(x, y)
16 print("out: ", summary_net)
1.2.2 Error reporting
The error message here is as follows:
Traceback (most recent call last):
File "C:/Users/l30026544/PycharmProjects/q2_map/new/173735.py", line 22, in <module>
summary_net = SummaryNet()(x, y)
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\nn\cell.py", line 586, in __call__
out = self.compile_and_run(*args)
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\nn\cell.py", line 964, in compile_and_run
self.compile(*inputs)
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\nn\cell.py", line 937, in compile
_cell_graph_executor.compile(self, *inputs, phase=self.phase, auto_parallel_mode=self._auto_parallel_mode)
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\common\api.py", line 1006, in compile
result = self._graph_executor.compile(obj, args_list, phase, self._use_vm_mode())
ValueError: mindspore\core\utils\check_convert_utils.cc:397 CheckInteger] For primitive[TensorSummary], the v rank must be greater than or equal to 1, but got 0.
WARNING: Logging before InitGoogleLogging() is written to STDERR
[CRITICAL] CORE(6472,1,?):2022-6-17 15:47:53 [mindspore\core\utils\check_convert_utils.cc:397] CheckInteger] For primitive[TensorSummary], the v rank must be greater than or equal to 1, but got 0.
Cause Analysis
Let’s look at the error message. In ValueError, write ValueError: For primitive[TensorSummary], the v rank must be greater than or equal to 1, but got 0.
, which means that for TensorSummary, the rank of parameter v must be greater than or equal to 1, But it got 0. Therefore, it is necessary to check whether the rank of v passed into TensorSummary meets the requirements. Checking line 8 of the script finds that x and y are summed and the result is a scalar (constant), hence the error. Regarding TensorSummary, there are input restrictions on the official website, and the rank of the input Tensor must be greater than or equal to 1. If you need to collect scalar data, you can use the ScalarSummary operator.
2 Solutions
For the reasons known above, it is easy to make the following modifications:
01 class SummaryNet(nn.Cell):
02 def __init__(self,):
03 super(SummaryNet, self).__init__()
04 self.summary = ops.ScalarSummary()
05 self.add = ops.Add()
06
07 def construct(self, x, y):
08 x = self.add(x, y)
09 name = "x"
10 self.summary(name, x.sum())
11 return x
12
13 x = Tensor(np.array([1, 2, 3]).astype(np.float32))
14 y = Tensor(np.array([4, 5, 6]).astype(np.float32))
15 summary_net = SummaryNet()(x, y)
16 print("out: ", summary_net)
At this point, the execution is successful, and the output is as follows:
out: [5. 7. 9.]
3 Summary
Steps to locate the error report:
1. Find the line of user code that reported the error: * summary_net = SummaryNet()(x, y)*;
2. According to the keywords in the log error message, narrow the scope of the analysis problem* For primitive[TensorSummary], the v rank must be greater than or equal to 1, but got 0.* ;
3. It is necessary to focus on the correctness of variable definition and initialization.
Read More:
- [Solved] MindSpore Error: ValueError: For ‘AvgPool’ every dimension of the output shape must be greater than zero
- [Solved] MindSpore Error: TypeError: For ‘TopK’, the type of ‘x’ should be…
- [Solved] MindSpore Error: For ‘MirrorPad‘, paddings must be a Tensor with *
- [Solved] MindSpore Error: For ‘CellList’, each cell should be subclass of Cell
- [Solved] MindSpore Error: ReduceMean in the Ascend environment does not support inputs of 8 or more dimensions
- [Solved] MindSpore Error: task_fail_info or current_graph_ is nullptr
- [Solved] MindSpore Error: Data type conversion of ‘Parameter’ is not supporte
- [Solved] MindSpore Error: ValueError: Minimum inputs size 0 does not match…
- [Solved] MindSpore Error: Select GPU kernel op * fail! Incompatible data type
- [Solved] MindSpore Error: `half_pixel_centers`=True only support in Ascend
- [Solved] MindSpore Error: ValueError: `padding_idx` in `Embedding` out of range
- [Solved] RuntimeError: each element in list of batch should be of equal size
- [Solved] MindSpore Error: StridedSlice operator does not support input of uint8 data type on Ascend hardware
- [Solved] MindSpore Network custom reverse error: TypeError: The params of function ‘bprop’ of
- [Solved] MindSpore infer error when passing in sens values for derivation: For ‘MatMul’, the input dimensions
- [Solved] MindSpore Error: Should not use Python in runtime
- [Solved] MindSpore Error: “ValueError:invalid literal for int()with base10’the’
- [Solved] MindSpore Error: “TypeError: parse() missing 1 required positional.”
- [Solved] MindSpore Error: “GeneratorDataset’s num_workers=8, this value is …”