已合并
add error code #1333
misty-rain-typhoid创建于 2024年3月2日
add error code #1333
已合并
misty-rain-typhoid创建于 2024年3月2日
refs/pull/1333/head合入到master
9 个文件变更+29-29
Mop_plugin/utils/AdvancedIndex.cpp+5-5
@@ -146,10 +146,10 @@ at::Tensor AdvanceIndex::restride_src(const at::Tensor &src, int64_t before_dims
146 auto shape = at::DimVector(src.sizes());146 auto shape = at::DimVector(src.sizes());
147 auto strides = at::DimVector(src.strides());147 auto strides = at::DimVector(src.strides());
148 int64_t end = before_dims + dims_indexed;148 int64_t end = before_dims + dims_indexed;
149 TORCH_CHECK(shape.size() >= end, "end", end, "is overrange shape.size() ", shape.size(), OPS_ERROR(ErrCode::PARAM));149 TORCH_CHECK(shape.size() >= end, "end", end, "is overrange shape.size() ", shape.size(), OPS_ERROR(ErrCode::VALUE));
150 shape.erase(shape.begin() + before_dims, shape.begin() + end);150 shape.erase(shape.begin() + before_dims, shape.begin() + end);
151 TORCH_CHECK(strides.size() >= end, "end", end, "is overrange strides.size() ", strides.size(),151 TORCH_CHECK(strides.size() >= end, "end", end, "is overrange strides.size() ", strides.size(),
152 OPS_ERROR(ErrCode::PARAM));152 OPS_ERROR(ErrCode::VALUE));
153 strides.erase(strides.begin() + before_dims, strides.begin() + end);153 strides.erase(strides.begin() + before_dims, strides.begin() + end);
154 shape.insert(shape.begin() + before_dims, replacement_shape.begin(), replacement_shape.end());154 shape.insert(shape.begin() + before_dims, replacement_shape.begin(), replacement_shape.end());
155 strides.insert(strides.begin() + before_dims, replacement_shape.size(), 0);155 strides.insert(strides.begin() + before_dims, replacement_shape.size(), 0);
@@ -182,7 +182,7 @@ bool AdvanceIndex::checkIndexTensorTypes(const torch::List<c10::optional<at::Ten
182 if (scalarType != at::kLong && scalarType != at::kByte &&182 if (scalarType != at::kLong && scalarType != at::kByte &&
183 scalarType != at::kBool && scalarType != at::kInt) {183 scalarType != at::kBool && scalarType != at::kInt) {
184 TORCH_CHECK_INDEX(false, "tensors used as indices must be long, int, byte, or bool tensors",184 TORCH_CHECK_INDEX(false, "tensors used as indices must be long, int, byte, or bool tensors",
185 OPS_ERROR(ErrCode::PARAM));185 OPS_ERROR(ErrCode::TYPE));
186 }186 }
187 if (!indicesDtype.has_value()) {187 if (!indicesDtype.has_value()) {
188 indicesDtype = scalarType;188 indicesDtype = scalarType;
@@ -207,7 +207,7 @@ AdvancedIndex AdvanceIndex::make_info(at::Tensor self, const torch::List<c10::op
207 "shape mismatch: indexing tensors could not be broadcast"207 "shape mismatch: indexing tensors could not be broadcast"
208 " together with shapes ",208 " together with shapes ",
209 shapes_as_str(indices),209 shapes_as_str(indices),
210 OPS_ERROR(ErrCode::PARAM));210 OPS_ERROR(ErrCode::VALUE));
211 }211 }
212 // add missing null Tensors so that it matches self.dim().212 // add missing null Tensors so that it matches self.dim().
213 while (indices.size() < (size_t)self.dim()) {213 while (indices.size() < (size_t)self.dim()) {
@@ -253,7 +253,7 @@ std::vector<at::Tensor> AdvanceIndex::npu_expand_tensors(const at::Tensor &self,
253 uint64_t srcIdx = result.size() + j;253 uint64_t srcIdx = result.size() + j;
254 TORCH_CHECK_INDEX(index.size(j) == self.size(srcIdx), "The shape of the mask ", index.sizes(),254 TORCH_CHECK_INDEX(index.size(j) == self.size(srcIdx), "The shape of the mask ", index.sizes(),
255 " at index ", j, " does not match the shape of the indexed tensor ", self.sizes(),255 " at index ", j, " does not match the shape of the indexed tensor ", self.sizes(),
256 " at index ", srcIdx, OPS_ERROR(ErrCode::PARAM));256 " at index ", srcIdx, OPS_ERROR(ErrCode::VALUE));
257 }257 }
258 at::Tensor nonzero;258 at::Tensor nonzero;
259 // Replace with nonzeros259 // Replace with nonzeros
Mop_plugin/utils/OpUtils.cpp+2-2
@@ -142,7 +142,7 @@ int64_t complete_pad(int64_t s_size, int64_t p_size, int64_t k_size, int64_t str
142 int64_t needpads = 0;142 int64_t needpads = 0;
143 int64_t sizeP = s_size + p_size * 2;143 int64_t sizeP = s_size + p_size * 2;
144 int64_t leftLen = sizeP - k_size;144 int64_t leftLen = sizeP - k_size;
145 TORCH_CHECK(stride != 0, "CompletePad stride is zero!", OPS_ERROR(ErrCode::PARAM));145 TORCH_CHECK(stride != 0, "CompletePad stride is zero!", OPS_ERROR(ErrCode::VALUE));
146 auto reminder = leftLen % stride;146 auto reminder = leftLen % stride;
147 if (reminder != 0) {147 if (reminder != 0) {
148 needpads = stride - reminder;148 needpads = stride - reminder;
@@ -156,7 +156,7 @@ c10::optional<double> get_scale_value(c10::optional<c10::ArrayRef<double>> scale
156 return c10::nullopt;156 return c10::nullopt;
157 }157 }
158 TORCH_CHECK(scales->size() > idx, "idx", idx, "is overrange scales->at(idx) ", scales->size(),158 TORCH_CHECK(scales->size() > idx, "idx", idx, "is overrange scales->at(idx) ", scales->size(),
159 OPS_ERROR(ErrCode::PARAM));159 OPS_ERROR(ErrCode::VALUE));
160 return scales->at(idx);160 return scales->at(idx);
161}161}
162 162 
Mop_plugin/utils/custom_functions/aclops/IndexCopyKernelNpu.cpp+7-7
@@ -25,19 +25,19 @@ void index_copy_npu_par_check(const int64_t dim, const at::Tensor& index,
25{25{
26 int64_t new_dim = at::maybe_wrap_dim(dim, result.dim());26 int64_t new_dim = at::maybe_wrap_dim(dim, result.dim());
27 TORCH_CHECK_INDEX(index.dim() < 2, "index_copy_()", ": Index should have dimension 1 or 0 (got ", index.dim(), ")",27 TORCH_CHECK_INDEX(index.dim() < 2, "index_copy_()", ": Index should have dimension 1 or 0 (got ", index.dim(), ")",
28 OPS_ERROR(ErrCode::PARAM));28 OPS_ERROR(ErrCode::VALUE));
29 29 
30 int64_t num_indices = index.numel();30 int64_t num_indices = index.numel();
31 TORCH_CHECK_INDEX(!(source.dim() == 0 && num_indices != 1),31 TORCH_CHECK_INDEX(!(source.dim() == 0 && num_indices != 1),
32 "index_copy_()", ": When source is scalar, index should have one element (got ", num_indices, ")",32 "index_copy_()", ": When source is scalar, index should have one element (got ", num_indices, ")",
33 OPS_ERROR(ErrCode::PARAM));33 OPS_ERROR(ErrCode::VALUE));
34 TORCH_CHECK_INDEX(!((source.dim() != result.dim()) && (source.dim() != 0 && result.dim() != 0)),34 TORCH_CHECK_INDEX(!((source.dim() != result.dim()) && (source.dim() != 0 && result.dim() != 0)),
35 "index_copy_()", ": When source and destination are not scalars, "35 "index_copy_()", ": When source and destination are not scalars, "
36 "their dimensionality must match. Source dimensionality (",36 "their dimensionality must match. Source dimensionality (",
37 source.dim(), "), destination dimensionality (", result.dim(), ")", OPS_ERROR(ErrCode::PARAM));37 source.dim(), "), destination dimensionality (", result.dim(), ")", OPS_ERROR(ErrCode::VALUE));
38 38 
39 TORCH_CHECK_INDEX(index.scalar_type() == at::ScalarType::Long, "index_copy_()", ": Expected LongTensor for index",39 TORCH_CHECK_INDEX(index.scalar_type() == at::ScalarType::Long, "index_copy_()", ": Expected LongTensor for index",
40 OPS_ERROR(ErrCode::PARAM));40 OPS_ERROR(ErrCode::TYPE));
41 41 
42 // Check that source and destination slices have the same size42 // Check that source and destination slices have the same size
43 auto self_sliced_sizes = result.sizes().vec();43 auto self_sliced_sizes = result.sizes().vec();
@@ -55,16 +55,16 @@ void index_copy_npu_par_check(const int64_t dim, const at::Tensor& index,
55 !std::equal(self_sliced_sizes.begin(), self_sliced_sizes.end(), source_sliced_sizes.begin())),55 !std::equal(self_sliced_sizes.begin(), self_sliced_sizes.end(), source_sliced_sizes.begin())),
56 "index_copy_()", ": Source/destination tensor must have same slice shapes.\n",56 "index_copy_()", ": Source/destination tensor must have same slice shapes.\n",
57 "Destination slice shape: ", self_sliced_sizes, " at dimension ", new_dim,57 "Destination slice shape: ", self_sliced_sizes, " at dimension ", new_dim,
58 " and source slice shape: ", source_sliced_sizes, " at dimension 0.", OPS_ERROR(ErrCode::PARAM));58 " and source slice shape: ", source_sliced_sizes, " at dimension 0.", OPS_ERROR(ErrCode::VALUE));
59 TORCH_CHECK_INDEX(source.dim() == 0 || num_indices == source.size(new_dim),59 TORCH_CHECK_INDEX(source.dim() == 0 || num_indices == source.size(new_dim),
60 "index_copy_()", ": Number of indices (", num_indices,60 "index_copy_()", ": Number of indices (", num_indices,
61 ") should be equal to source.size(newDim) (", source.size(new_dim), ")", OPS_ERROR(ErrCode::PARAM));61 ") should be equal to source.size(newDim) (", source.size(new_dim), ")", OPS_ERROR(ErrCode::VALUE));
62 62
63 for (int64_t i = 0; i < num_indices; i++) {63 for (int64_t i = 0; i < num_indices; i++) {
64 int64_t specifical_index = index.dim() == 0 ? index.item<int64_t>() : index[i].item<int64_t>();64 int64_t specifical_index = index.dim() == 0 ? index.item<int64_t>() : index[i].item<int64_t>();
65 TORCH_CHECK_INDEX(specifical_index <= boundary_index, "index_copy_()", ": index ", specifical_index,65 TORCH_CHECK_INDEX(specifical_index <= boundary_index, "index_copy_()", ": index ", specifical_index,
66 " is out of bounds for dimension ", boundary_index, " with size ", boundary_index + 1,66 " is out of bounds for dimension ", boundary_index, " with size ", boundary_index + 1,
67 OPS_ERROR(ErrCode::PARAM));67 OPS_ERROR(ErrCode::VALUE));
68 }68 }
69}69}
70} // namespace acl_op70} // namespace acl_op
Mop_plugin/utils/custom_functions/aclops/LinalgSvdKernelNpu.cpp+7-7
@@ -90,8 +90,8 @@ inline c10::MaybeOwned<at::Tensor> borrow_else_clone(const bool cond, const at::
90std::tuple<at::Tensor, at::Tensor, at::Tensor> _svd_helper(const at::Tensor &self, bool some, bool compute_uv)90std::tuple<at::Tensor, at::Tensor, at::Tensor> _svd_helper(const at::Tensor &self, bool some, bool compute_uv)
91{91{
92 TORCH_CHECK(self.dtype() == at::kFloat, "svd_npu only supported Float, but get", self.dtype(),92 TORCH_CHECK(self.dtype() == at::kFloat, "svd_npu only supported Float, but get", self.dtype(),
93 OPS_ERROR(ErrCode::PARAM));93 OPS_ERROR(ErrCode::TYPE));
94 TORCH_CHECK(self.dim() >= 2, "The dim of input tensor must larger than two.", OPS_ERROR(ErrCode::PARAM));94 TORCH_CHECK(self.dim() >= 2, "The dim of input tensor must larger than two.", OPS_ERROR(ErrCode::VALUE));
95 std::vector<int64_t> infos(batch_count(self), 0);95 std::vector<int64_t> infos(batch_count(self), 0);
96 int64_t m = self.size(-2);96 int64_t m = self.size(-2);
97 int64_t n = self.size(-1);97 int64_t n = self.size(-1);
@@ -149,8 +149,8 @@ std::tuple<at::Tensor, at::Tensor, at::Tensor> _svd_helper(const at::Tensor &sel
149 149 
150static void linalg_check_errors(const at::Tensor &infos, const c10::string_view api_name, bool is_matrix)150static void linalg_check_errors(const at::Tensor &infos, const c10::string_view api_name, bool is_matrix)
151{151{
152 TORCH_CHECK(infos.scalar_type() == at::kInt, OPS_ERROR(ErrCode::PARAM));152 TORCH_CHECK(infos.scalar_type() == at::kInt, OPS_ERROR(ErrCode::TYPE));
153 TORCH_CHECK(infos.is_contiguous(), OPS_ERROR(ErrCode::PARAM));153 TORCH_CHECK(infos.is_contiguous(), OPS_ERROR(ErrCode::VALUE));
154 if (infos.is_meta()) {154 if (infos.is_meta()) {
155 return;155 return;
156 }156 }
@@ -187,12 +187,12 @@ static void linalg_check_errors(const at::Tensor &infos, const c10::string_view
187 if (api_name.find("svd") != api_name.npos) {187 if (api_name.find("svd") != api_name.npos) {
188 TORCH_CHECK(info != -4, api_name, batch_str,188 TORCH_CHECK(info != -4, api_name, batch_str,
189 ": The algorithm failed to converge because the input matrix contained non-finite values.",189 ": The algorithm failed to converge because the input matrix contained non-finite values.",
190 OPS_ERROR(ErrCode::PARAM));190 OPS_ERROR(ErrCode::VALUE));
191 }191 }
192 TORCH_CHECK(192 TORCH_CHECK(
193 false, api_name, batch_str, ": Argument ", -info,193 false, api_name, batch_str, ": Argument ", -info,
194 " has illegal value. Most certainly there is a bug in the implementation calling the backend library.",194 " has illegal value. Most certainly there is a bug in the implementation calling the backend library.",
195 OPS_ERROR(ErrCode::PARAM));195 OPS_ERROR(ErrCode::VALUE));
M
Mmisty-rain-typhoid2024年3月4日

这个是info<0会执行到的代码,可以理解为value错误

已修改

likedislike
196 } else if (info > 0) {196 } else if (info > 0) {
197 if (api_name.find("svd") != api_name.npos) {197 if (api_name.find("svd") != api_name.npos) {
198 TORCH_CHECK(false, api_name, batch_str,198 TORCH_CHECK(false, api_name, batch_str,
@@ -200,7 +200,7 @@ static void linalg_check_errors(const at::Tensor &infos, const c10::string_view
200 "many repeated singular values (error code: ",200 "many repeated singular values (error code: ",
201 info, ").", OPS_ERROR(ErrCode::PARAM));201 info, ").", OPS_ERROR(ErrCode::PARAM));
202 } else {202 } else {
203 TORCH_CHECK(false, api_name, ": Unknown error code: ", info, ".", OPS_ERROR(ErrCode::PARAM));203 TORCH_CHECK(false, api_name, ": Unknown error code: ", info, ".", OPS_ERROR(ErrCode::INTERNAL));
204 }204 }
205 }205 }
206 // We should never reach this point as info was non-zero206 // We should never reach this point as info was non-zero
Mop_plugin/utils/custom_functions/aclops/RepeatInterLeaveKernelNpu.cpp+2-2
@@ -51,7 +51,7 @@ void check_dim_valid(int64_t real_dim, int64_t self_dim) {
51 TORCH_CHECK(51 TORCH_CHECK(
52 (real_dim >= dim_min) && (real_dim <= dim_max),52 (real_dim >= dim_min) && (real_dim <= dim_max),
53 "dim value should be in the range of [-x, x-1], x is the dimension number of input tensor.",53 "dim value should be in the range of [-x, x-1], x is the dimension number of input tensor.",
54 OPS_ERROR(ErrCode::PARAM));54 OPS_ERROR(ErrCode::VALUE));
55}55}
56} // namespace56} // namespace
57 57 
@@ -109,7 +109,7 @@ at::Tensor repeat_interleave_common_nocheck(
109 109 
110 TORCH_CHECK(110 TORCH_CHECK(
111 (repeats.size(0) == self_tensor.size(real_dim)) || (repeats.size(0) == 1),111 (repeats.size(0) == self_tensor.size(real_dim)) || (repeats.size(0) == 1),
112 "repeats must have the same size as input along dim.", OPS_ERROR(ErrCode::PARAM));112 "repeats must have the same size as input along dim.", OPS_ERROR(ErrCode::VALUE));
113 113 
114 if (self_dim > 1 && real_dim != 0) {114 if (self_dim > 1 && real_dim != 0) {
115 self_tensor = self_tensor.transpose(0, real_dim);115 self_tensor = self_tensor.transpose(0, real_dim);
Mop_plugin/utils/custom_functions/aclops/TriangularSolveKernelNpu.cpp+2-2
@@ -29,11 +29,11 @@ std::tuple<at::Tensor, at::Tensor> triangular_solve_out_common_nocheck(const at:
29 std::tie(self_broadcasted, a_broadcasted) = at::native::_linalg_broadcast_batch_dims(self, A, "triangular_solve");29 std::tie(self_broadcasted, a_broadcasted) = at::native::_linalg_broadcast_batch_dims(self, A, "triangular_solve");
30 TORCH_CHECK(self_broadcasted.dtype() == at::kFloat && a_broadcasted.dtype() == at::kFloat,30 TORCH_CHECK(self_broadcasted.dtype() == at::kFloat && a_broadcasted.dtype() == at::kFloat,
31 "_triangular_solve_helper_npu only supported Float, but get ", self_broadcasted.dtype(), ' ',31 "_triangular_solve_helper_npu only supported Float, but get ", self_broadcasted.dtype(), ' ',
32 a_broadcasted.dtype(), OPS_ERROR(ErrCode::PARAM));32 a_broadcasted.dtype(), OPS_ERROR(ErrCode::TYPE));
33 auto self_working_copy = npu_preparation::apply_tensor(self_broadcasted);33 auto self_working_copy = npu_preparation::apply_tensor(self_broadcasted);
34 auto a_working_copy = a_broadcasted.clone();34 auto a_working_copy = a_broadcasted.clone();
35 at::Tensor a_tensor = a_broadcasted;35 at::Tensor a_tensor = a_broadcasted;
36 TORCH_CHECK(a_tensor.dim() >= 2, "The dim of input tensor must larger than two.", OPS_ERROR(ErrCode::PARAM));36 TORCH_CHECK(a_tensor.dim() >= 2, "The dim of input tensor must larger than two.", OPS_ERROR(ErrCode::VALUE));
37 if (unitriangular) {37 if (unitriangular) {
38 auto diagonal_tensor = at::eye(a_tensor.size(-2), a_tensor.size(-1), a_tensor.options());38 auto diagonal_tensor = at::eye(a_tensor.size(-2), a_tensor.size(-1), a_tensor.options());
39 a_tensor = a_tensor * (1 - diagonal_tensor) + diagonal_tensor;39 a_tensor = a_tensor * (1 - diagonal_tensor) + diagonal_tensor;
Mop_plugin/utils/custom_functions/aclops/VarKernelNpu.cpp+2-2
@@ -106,9 +106,9 @@ std::tuple<at::Tensor &, at::Tensor &> var_mean_out_nocheck(at::Tensor &variance
106 dim.empty() ? op_plugin::utils::get_dimlist_for_tensor(self) : c10::SmallVector<int64_t, N>(dim);106 dim.empty() ? op_plugin::utils::get_dimlist_for_tensor(self) : c10::SmallVector<int64_t, N>(dim);
107 auto ori_type = self.scalar_type();107 auto ori_type = self.scalar_type();
108 TORCH_CHECK((ori_type == c10::ScalarType::Half || ori_type == c10::ScalarType::Float),108 TORCH_CHECK((ori_type == c10::ScalarType::Half || ori_type == c10::ScalarType::Float),
109 "Var Mean only support float16 or float32 type.", OPS_ERROR(ErrCode::PARAM));109 "Var Mean only support float16 or float32 type.", OPS_ERROR(ErrCode::TYPE));
110 TORCH_CHECK((variance.scalar_type() == mean.scalar_type() && variance.scalar_type() == ori_type),110 TORCH_CHECK((variance.scalar_type() == mean.scalar_type() && variance.scalar_type() == ori_type),
111 "mean's type and variance' type must be equal to input's type.", OPS_ERROR(ErrCode::PARAM));111 "mean's type and variance' type must be equal to input's type.", OPS_ERROR(ErrCode::TYPE));
112 var_mean_compute(variance, mean, self, dim_now, unbiased, keepdim, correction);112 var_mean_compute(variance, mean, self, dim_now, unbiased, keepdim, correction);
113 113 
114 return std::tuple<at::Tensor &, at::Tensor &>(variance, mean);114 return std::tuple<at::Tensor &, at::Tensor &>(variance, mean);
Mop_plugin/utils/custom_functions/aclops/WhereKernelNpu.cpp+1-1
@@ -34,7 +34,7 @@ at::Tensor &where_out_nocheck(at::Tensor &out, const at::Tensor &condition, cons
34 34 
35 TORCH_CHECK(!(condition.scalar_type() != at::ScalarType::Byte && condition.scalar_type() != at::ScalarType::Bool),35 TORCH_CHECK(!(condition.scalar_type() != at::ScalarType::Byte && condition.scalar_type() != at::ScalarType::Bool),
36 "Expected condition to have ScalarType Byte, but got ScalarType ", toString(condition.scalar_type()),36 "Expected condition to have ScalarType Byte, but got ScalarType ", toString(condition.scalar_type()),
37 OPS_ERROR(ErrCode::PARAM));37 OPS_ERROR(ErrCode::TYPE));
38 38 
39 at_npu::native::OpCommand cmd;39 at_npu::native::OpCommand cmd;
40 cmd.Name("Select").Input(condition).Input(self_cp).Input(other_cp).Output(out).Run();40 cmd.Name("Select").Input(condition).Input(self_cp).Input(other_cp).Output(out).Run();
Mop_plugin/utils/op_api_common.h+1-1
@@ -152,7 +152,7 @@ inline aclTensor *ConvertType(const at::Tensor &at_tensor)
152 // if acl_data_type is ACL_STRING, storageDims is empty.152 // if acl_data_type is ACL_STRING, storageDims is empty.
153 if (acl_data_type != ACL_STRING) {153 if (acl_data_type != ACL_STRING) {
154 TORCH_CHECK(at_tensor.itemsize() > 0, "the itemsize of tensor must be greater than 0.",154 TORCH_CHECK(at_tensor.itemsize() > 0, "the itemsize of tensor must be greater than 0.",
155 OPS_ERROR(ErrCode::PARAM));155 OPS_ERROR(ErrCode::VALUE));
156 storageDims.push_back(at_tensor.storage().nbytes() / at_tensor.itemsize());156 storageDims.push_back(at_tensor.storage().nbytes() / at_tensor.itemsize());
157 }157 }
158 158