未验证 提交 2cb1ecb9 编写于 作者: Y yinhaofeng 提交者: GitHub

lookup_table_v2_op_xpu report errors;test=kunlun (#28064)

* lookup_table_v2_op_xpu report errors;test=kunlun

* lookup_table_v2_op_xpu report errors;test=kunlun
上级 6f0c3d1f
...@@ -31,11 +31,14 @@ class LookupTableV2XPUKernel : public framework::OpKernel<T> { ...@@ -31,11 +31,14 @@ class LookupTableV2XPUKernel : public framework::OpKernel<T> {
auto *table_var = context.InputVar("W"); auto *table_var = context.InputVar("W");
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
(std::is_same<DeviceContext, platform::XPUDeviceContext>::value), true, (std::is_same<DeviceContext, platform::XPUDeviceContext>::value), true,
platform::errors::InvalidArgument("Unsupported place!")); platform::errors::PreconditionNotMet("Unsupported place! only support "
"xpu place , please check your "
"place."));
PADDLE_ENFORCE_EQ(table_var->IsType<LoDTensor>(), true, PADDLE_ENFORCE_EQ(table_var->IsType<LoDTensor>(), true,
platform::errors::InvalidArgument( platform::errors::PermissionDenied(
"idx in LookupTableV2XPUKernel should be LoDTensor")); "Unsupported Variable Type , idx in "
"LookupTableV2XPUKernel should be LoDTensor."));
int64_t padding_idx = context.Attr<int64_t>("padding_idx"); int64_t padding_idx = context.Attr<int64_t>("padding_idx");
int64_t ids_numel = ids_t->numel(); int64_t ids_numel = ids_t->numel();
...@@ -49,15 +52,19 @@ class LookupTableV2XPUKernel : public framework::OpKernel<T> { ...@@ -49,15 +52,19 @@ class LookupTableV2XPUKernel : public framework::OpKernel<T> {
auto *output = output_t->mutable_data<T>(context.GetPlace()); auto *output = output_t->mutable_data<T>(context.GetPlace());
const int64_t *ids = ids_t->data<int64_t>(); const int64_t *ids = ids_t->data<int64_t>();
PADDLE_ENFORCE_EQ(ids_numel <= std::numeric_limits<int32_t>::max(), true, PADDLE_ENFORCE_EQ(
platform::errors::InvalidArgument( ids_numel <= std::numeric_limits<int32_t>::max(), true,
"idx_numel in LookupTableV2XPUKernel should not " platform::errors::OutOfRange(
"greater than int32_t::max.")); "Number of ids greater than int32_t::max , please check "
"number of ids in LookupTableV2XPUKernel."));
int ids_numel_int32 = static_cast<int>(ids_numel); int ids_numel_int32 = static_cast<int>(ids_numel);
int r = xpu::embedding<T>(dev_ctx.x_context(), ids_numel_int32, ids, D, int r = xpu::embedding<T>(dev_ctx.x_context(), ids_numel_int32, ids, D,
table, output, padding_idx); table, output, padding_idx);
PADDLE_ENFORCE_EQ(r == xpu::Error_t::SUCCESS, true, PADDLE_ENFORCE_EQ(r == xpu::Error_t::SUCCESS, true,
platform::errors::InvalidArgument("XPU kernel error!")); platform::errors::External(
"XPU API return wrong value[%d] , please check where "
"Baidu Kunlun Card is properly installed.",
r));
} }
}; };
...@@ -67,27 +74,28 @@ class LookupTableV2GradXPUKernel : public framework::OpKernel<T> { ...@@ -67,27 +74,28 @@ class LookupTableV2GradXPUKernel : public framework::OpKernel<T> {
void Compute(const framework::ExecutionContext &context) const override { void Compute(const framework::ExecutionContext &context) const override {
auto *table_var = context.InputVar("W"); auto *table_var = context.InputVar("W");
DDim table_dim; DDim table_dim;
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(table_var->IsType<LoDTensor>(), true,
table_var->IsType<LoDTensor>(), true, platform::errors::PermissionDenied(
platform::errors::InvalidArgument( "Unsupported Variable Type , idx in "
"idx in LookupTableV2GradXPUKernel should be LoDTensor")); "LookupTableV2GradXPUKernel should be LoDTensor."));
table_dim = context.Input<LoDTensor>("W")->dims(); table_dim = context.Input<LoDTensor>("W")->dims();
bool is_sparse = context.Attr<bool>("is_sparse"); bool is_sparse = context.Attr<bool>("is_sparse");
PADDLE_ENFORCE_EQ( PADDLE_ENFORCE_EQ(
is_sparse, false, is_sparse, false,
platform::errors::InvalidArgument( platform::errors::InvalidArgument(
"LookupTableV2GradXPUKernel dose NOT support is_sparse = True")); "LookupTableV2GradXPUKernel dose NOT support is_sparse = True."));
auto ids_t = context.Input<LoDTensor>("Ids"); auto ids_t = context.Input<LoDTensor>("Ids");
auto d_output_t = context.Input<LoDTensor>(framework::GradVarName("Out")); auto d_output_t = context.Input<LoDTensor>(framework::GradVarName("Out"));
auto d_table_t = context.Output<LoDTensor>(framework::GradVarName("W")); auto d_table_t = context.Output<LoDTensor>(framework::GradVarName("W"));
int64_t ids_numel = ids_t->numel(); int64_t ids_numel = ids_t->numel();
PADDLE_ENFORCE_EQ(ids_numel <= std::numeric_limits<int32_t>::max(), true, PADDLE_ENFORCE_EQ(
platform::errors::InvalidArgument( ids_numel <= std::numeric_limits<int32_t>::max(), true,
"idx_numel in LookupTableV2GradXPUKernel should not " platform::errors::OutOfRange(
"greater than int32_t::max.")); "Number of ids greater than int32_t::max , please check "
"number of ids in LookupTableV2GradXPUKernel."));
int ids_numel_int32 = static_cast<int>(ids_numel); int ids_numel_int32 = static_cast<int>(ids_numel);
const int64_t *ids_data = ids_t->data<int64_t>(); const int64_t *ids_data = ids_t->data<int64_t>();
...@@ -100,13 +108,19 @@ class LookupTableV2GradXPUKernel : public framework::OpKernel<T> { ...@@ -100,13 +108,19 @@ class LookupTableV2GradXPUKernel : public framework::OpKernel<T> {
int r = xpu::memset(dev_ctx.x_context(), d_table_data, zero, int r = xpu::memset(dev_ctx.x_context(), d_table_data, zero,
d_table_t->numel() * sizeof(T)); d_table_t->numel() * sizeof(T));
PADDLE_ENFORCE_EQ(r == xpu::Error_t::SUCCESS, true, PADDLE_ENFORCE_EQ(r == xpu::Error_t::SUCCESS, true,
platform::errors::InvalidArgument("XPU kernel error!")); platform::errors::External(
"XPU API return wrong value[%d], please check where "
"Baidu Kunlun Card is properly installed.",
r));
r = xpu::embedding_backward<T, int64_t>(dev_ctx.x_context(), r = xpu::embedding_backward<T, int64_t>(dev_ctx.x_context(),
ids_numel_int32, ids_data, D, ids_numel_int32, ids_data, D,
d_output_data, d_table_data); d_output_data, d_table_data);
PADDLE_ENFORCE_EQ(r == xpu::Error_t::SUCCESS, true, PADDLE_ENFORCE_EQ(r == xpu::Error_t::SUCCESS, true,
platform::errors::InvalidArgument("XPU kernel error!")); platform::errors::External(
"XPU API return wrong value[%d] , please check where "
"Baidu Kunlun Card is properly installed.",
r));
} }
}; };
#endif #endif
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册