From 0b294906f910d5bec4edb4e21a8d31c097ed786d Mon Sep 17 00:00:00 2001 From: yinhaofeng <66763551+yinhaofeng@users.noreply.github.com> Date: Tue, 20 Oct 2020 14:27:14 +0800 Subject: [PATCH] lookup_table_v2_op_xpu report errors;test=kunlun (#28064) (#28100) * lookup_table_v2_op_xpu report errors;test=kunlun * lookup_table_v2_op_xpu report errors;test=kunlun --- .../fluid/operators/lookup_table_v2_op_xpu.cc | 52 ++++++++++++------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/paddle/fluid/operators/lookup_table_v2_op_xpu.cc b/paddle/fluid/operators/lookup_table_v2_op_xpu.cc index bca30862a80..2284401ba1b 100644 --- a/paddle/fluid/operators/lookup_table_v2_op_xpu.cc +++ b/paddle/fluid/operators/lookup_table_v2_op_xpu.cc @@ -31,11 +31,14 @@ class LookupTableV2XPUKernel : public framework::OpKernel { auto *table_var = context.InputVar("W"); PADDLE_ENFORCE_EQ( (std::is_same::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(), true, - platform::errors::InvalidArgument( - "idx in LookupTableV2XPUKernel should be LoDTensor")); + platform::errors::PermissionDenied( + "Unsupported Variable Type , idx in " + "LookupTableV2XPUKernel should be LoDTensor.")); int64_t padding_idx = context.Attr("padding_idx"); int64_t ids_numel = ids_t->numel(); @@ -49,15 +52,19 @@ class LookupTableV2XPUKernel : public framework::OpKernel { auto *output = output_t->mutable_data(context.GetPlace()); const int64_t *ids = ids_t->data(); - PADDLE_ENFORCE_EQ(ids_numel <= std::numeric_limits::max(), true, - platform::errors::InvalidArgument( - "idx_numel in LookupTableV2XPUKernel should not " - "greater than int32_t::max.")); + PADDLE_ENFORCE_EQ( + ids_numel <= std::numeric_limits::max(), true, + platform::errors::OutOfRange( + "Number of ids greater than int32_t::max , please check " + "number of ids in LookupTableV2XPUKernel.")); int ids_numel_int32 = static_cast(ids_numel); int r = xpu::embedding(dev_ctx.x_context(), ids_numel_int32, ids, D, table, output, padding_idx); 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 { void Compute(const framework::ExecutionContext &context) const override { auto *table_var = context.InputVar("W"); DDim table_dim; - PADDLE_ENFORCE_EQ( - table_var->IsType(), true, - platform::errors::InvalidArgument( - "idx in LookupTableV2GradXPUKernel should be LoDTensor")); + PADDLE_ENFORCE_EQ(table_var->IsType(), true, + platform::errors::PermissionDenied( + "Unsupported Variable Type , idx in " + "LookupTableV2GradXPUKernel should be LoDTensor.")); table_dim = context.Input("W")->dims(); bool is_sparse = context.Attr("is_sparse"); PADDLE_ENFORCE_EQ( is_sparse, false, platform::errors::InvalidArgument( - "LookupTableV2GradXPUKernel dose NOT support is_sparse = True")); + "LookupTableV2GradXPUKernel dose NOT support is_sparse = True.")); auto ids_t = context.Input("Ids"); auto d_output_t = context.Input(framework::GradVarName("Out")); auto d_table_t = context.Output(framework::GradVarName("W")); int64_t ids_numel = ids_t->numel(); - PADDLE_ENFORCE_EQ(ids_numel <= std::numeric_limits::max(), true, - platform::errors::InvalidArgument( - "idx_numel in LookupTableV2GradXPUKernel should not " - "greater than int32_t::max.")); + PADDLE_ENFORCE_EQ( + ids_numel <= std::numeric_limits::max(), true, + platform::errors::OutOfRange( + "Number of ids greater than int32_t::max , please check " + "number of ids in LookupTableV2GradXPUKernel.")); int ids_numel_int32 = static_cast(ids_numel); const int64_t *ids_data = ids_t->data(); @@ -100,13 +108,19 @@ class LookupTableV2GradXPUKernel : public framework::OpKernel { int r = xpu::memset(dev_ctx.x_context(), d_table_data, zero, d_table_t->numel() * sizeof(T)); 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(dev_ctx.x_context(), ids_numel_int32, ids_data, D, d_output_data, d_table_data); 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 -- GitLab