未验证 提交 effd51b6 编写于 作者: L liym27 提交者: GitHub

Fix error message in operator/utils.h (#27532)

上级 6bb02e8e
...@@ -41,7 +41,9 @@ inline std::vector<T> GetDataFromTensor(const framework::Tensor* x) { ...@@ -41,7 +41,9 @@ inline std::vector<T> GetDataFromTensor(const framework::Tensor* x) {
// NOTE: Converting int64 to int32 may cause data overflow. // NOTE: Converting int64 to int32 may cause data overflow.
vec_new_data = std::vector<T>(data, data + x->numel()); vec_new_data = std::vector<T>(data, data + x->numel());
} else { } else {
PADDLE_THROW("The dtype of Tensor must be int32 or int64."); PADDLE_THROW(platform::errors::InvalidArgument(
"The dtype of Tensor must be int32 or int64, but received: %s",
x->type()));
} }
return vec_new_data; return vec_new_data;
} }
...@@ -53,10 +55,11 @@ inline std::vector<T> GetDataFromTensorList( ...@@ -53,10 +55,11 @@ inline std::vector<T> GetDataFromTensorList(
for (size_t i = 0; i < list_tensor.size(); ++i) { for (size_t i = 0; i < list_tensor.size(); ++i) {
auto tensor = list_tensor[i]; auto tensor = list_tensor[i];
PADDLE_ENFORCE_EQ(tensor->dims(), framework::make_ddim({1}), PADDLE_ENFORCE_EQ(tensor->dims(), framework::make_ddim({1}),
"ShapeError: The shape of Tensor in list must be [1]. " platform::errors::InvalidArgument(
"But received the shape " "The shape of Tensor in list must be [1]. "
"is [%s]", "But received its shape "
tensor->dims()); "is [%s]",
tensor->dims()));
if (tensor->type() == framework::proto::VarType::INT32) { if (tensor->type() == framework::proto::VarType::INT32) {
if (platform::is_gpu_place(tensor->place())) { if (platform::is_gpu_place(tensor->place())) {
...@@ -76,7 +79,10 @@ inline std::vector<T> GetDataFromTensorList( ...@@ -76,7 +79,10 @@ inline std::vector<T> GetDataFromTensorList(
vec_new_data.push_back(static_cast<T>(*tensor->data<int64_t>())); vec_new_data.push_back(static_cast<T>(*tensor->data<int64_t>()));
} }
} else { } else {
PADDLE_THROW("The dtype of Tensor in list must be int32 or int64."); PADDLE_THROW(platform::errors::InvalidArgument(
"The dtype of Tensor in list must be int32 or int64, but received: "
"%s",
tensor->type()));
} }
} }
return vec_new_data; return vec_new_data;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册