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 completes the embedding layer operation by constructing a single-operator network of Embedding. The script is as follows:
01 class Net(nn.Cell):
02 def __init__(self, vocab_size, embedding_size, use_one_hot, padding_idx=None):
03 super(Net, self).__init__()
04 self.op = nn.Embedding(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=padding_idx)
05
06 def construct(self, x):
07 output = self.op(x)
08 return output
09
10 input = Tensor(np.ones([8, 128]), mindspore.int32)
11 vocab_size = 2000
12 embedding_size = 768
13 use_one_hot = True
14 example = Net(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=10000)
15 output = example(input)
16 print("Output:", output.shape)
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/I3MRK3.py", line 26, in <module>
example = Net(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=10000)
File "C:/Users/l30026544/PycharmProjects/q2_map/new/I3MRK3.py", line 12, in __init__
self.op = nn.Embedding(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=padding_idx)
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\nn\layer\embedding.py", line 111, in __init__
self.padding_idx = validator.check_int_range(padding_idx, 0, vocab_size, Rel.INC_BOTH,
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\_checkparam.py", line 413, in check_int_range
return check_number_range(arg_value, lower_limit, upper_limit, rel, int, arg_name, prim_name)
File "C:\Users\l30026544\PycharmProjects\q2_map\lib\site-packages\mindspore\_checkparam.py", line 209, in check_number_range
raise ValueError("{} {} should be in range of {}, but got {} with type `{}`.".format(
ValueError: `padding_idx` in `Embedding` should be in range of [0, 2000], but got 10000 with type `int`.
Cause Analysis
Let’s look at the error message. In ValueError, it is written that padding_idx
in Embedding
should be in range of [0, 2000], but got 10000 with type int
., which means that the value of padding_idx’ in the Embedding operator needs to be between 0 and 2000, but Got 10000. Combined with the official website’s description of the usage of the Ebedding operator, it is found that padding_idx has been clearly specified, and its value needs to be between 0 and vocab_size:
2 Solutions
For the reasons known above, it is easy to make the following modifications:
01 class Net(nn.Cell):
02 def __init__(self, vocab_size, embedding_size, use_one_hot, padding_idx=None):
03 super(Net, self).__init__()
04 self.op = nn.Embedding(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=padding_idx)
05
06 def construct(self, x):
07 output = self.op(x)
08 return output
09
10 input = Tensor(np.ones([8, 128]), mindspore.int32)
11 vocab_size = 2000
12 embedding_size = 768
13 use_one_hot = True
14 example = Net(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=1000)
15 output = example(input)
16 print("Output:", output.shape)
At this point, the execution is successful, and the output is as follows:
Output: (8, 128, 768)
3 Summary
Steps to locate the error report:
1. Find the user code line that reported the error: example = Net(vocab_size=vocab_size, embedding_size=embedding_size, use_one_hot=use_one_hot, padding_idx=10000) ;
2. According to the keywords in the log error message, narrow the scope of the analysis problem V padding_idx
in Embedding
should be in range of [0, 2000], but got 10000 with type int
. ;
Read More:
- [Solved] MindSpore Error: ValueError: For ‘AvgPool’ every dimension of the output shape must be greater than zero
- [Solved] MindSpore Error: ValueError: Minimum inputs size 0 does not match…
- [Solved] MindSpore Error: “ValueError:invalid literal for int()with base10’the’
- ValueError: Floating point image RGB values must be in the 0..1 range.
- [Solved] MindSpore Error: `half_pixel_centers`=True only support in Ascend
- [Solved] MindSpore Error: ReduceMean in the Ascend environment does not support inputs of 8 or more dimensions
- runtime error ‘9’: subscript out of range error in VBA programming
- Tensorflow error: InvalidArgumentError: indices[data_index] = data_value is not in [0, max_embedding_size)
- [Solved] MindSpore infer error when passing in sens values for derivation: For ‘MatMul’, the input dimensions
- How to Solve “RIP Address Out Of Range” Error
- Android Studio Error: String index out of range 0 [How to Solve]
- [Solved] MindSpore Error: For ‘MirrorPad‘, paddings must be a Tensor with *
- [Solved] MindSpore Error: TypeError: For ‘TopK’, the type of ‘x’ should be…
- [Solved] TensorFlow severing Container Creat Error: failed: Out of range: Read less bytes than requested
- [Solved] MindSpore Error: For ‘CellList’, each cell should be subclass of Cell
- C++ Error: terminating with uncaught exception of type std::out_of_range: vector Abort trap: 6
- [Solved] MindSpore Error: For primitive[TensorSummary], the v rank Must be greater than or equal to 0
- [Solved] MindSpore Error: Should not use Python in runtime
- [Solved] MindSpore Error: StridedSlice operator does not support input of uint8 data type on Ascend hardware