From e74d7807c3f3911580480681925aace0f7f3cfb4 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 15:04:01 +0800 Subject: [PATCH 01/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../grad_node_info_test.cc | 46 +++++++++++++++---- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/test/cpp/eager/data_structure_tests/grad_node_info_test.cc b/test/cpp/eager/data_structure_tests/grad_node_info_test.cc index 3235d9cf6164e..4c8128a0cec2d 100644 --- a/test/cpp/eager/data_structure_tests/grad_node_info_test.cc +++ b/test/cpp/eager/data_structure_tests/grad_node_info_test.cc @@ -26,7 +26,10 @@ TEST(GradNodeInfo, GradSlotMeta) { auto grad_slot = egr::GradSlotMeta(); VLOG(6) << "Set SetStopGradient"; grad_slot.SetStopGradient(); - CHECK(grad_slot.IsStopGradient() == true); + PADDLE_ENFORCE_EQ(grad_slot.IsStopGradient(), + true, + phi::errors::Fatal("`grad_slot.IsStopGradient()` should be " + "true, please check related function")); } void TestGradNodeBase(bool is_remove_gradient_hook) { @@ -67,8 +70,16 @@ void TestGradNodeBase(bool is_remove_gradient_hook) { meta.dtype); CHECK_EQ(grad_test_node0->InputMeta()[1][0].GetTensorMeta().dtype, meta.dtype); - CHECK(grad_test_node0->OutputMeta()[0][0].IsStopGradient()); - CHECK(grad_test_node0->OutputMeta()[1][0].IsStopGradient()); + PADDLE_ENFORCE_EQ( + grad_test_node0->OutputMeta()[0][0].IsStopGradient(), + true, + phi::errors::Fatal("`grad_test_node0->OutputMeta()[0][0].IsStopGradient()" + "` should be true, please related function")); + PADDLE_ENFORCE_EQ( + grad_test_node0->OutputMeta()[1][0].IsStopGradient(), + true, + phi::errors::Fatal("`grad_test_node0->OutputMeta()[1][0].IsStopGradient()" + "` should be true, please related function")); CHECK_EQ(grad_test_node0->OutputMeta()[0][0].GetTensorMeta().dtype, meta.dtype); CHECK_EQ(grad_test_node0->OutputMeta()[1][0].GetTensorMeta().dtype, @@ -79,8 +90,17 @@ void TestGradNodeBase(bool is_remove_gradient_hook) { /* val */ 5.0, /* in_num */ 1, /* out_num */ 1); grad_test_node2->SetDefaultGradInOutMeta(); CHECK_GT(grad_test_node2->OutputMeta()[0].size(), size_t(0)); - CHECK(grad_test_node2->OutputMeta()[0][0].IsStopGradient() == false); - CHECK_EQ(grad_test_node2->OutputMeta()[0].size(), size_t(1)); + PADDLE_ENFORCE_EQ( + grad_test_node2->OutputMeta()[0][0].IsStopGradient(), + false, + phi::errors::Fatal("`grad_test_node2->OutputMeta()[0][0].IsStopGradient()" + "` should be false, please check related function")); + PADDLE_ENFORCE_EQ( + grad_test_node2->OutputMeta()[0].size(), + size_t(1), + phi::errors::Fatal( + "`grad_test_node2->OutputMeta()[0].size()` is %d, but should be 1", + grad_test_node2->OutputMeta()[0].size())); VLOG(6) << "Test Gradient Hook"; auto gradient_hook = [](const paddle::Tensor& et) -> paddle::Tensor { @@ -135,9 +155,15 @@ TEST(GradNodeInfo, Edge) { auto auto_grad1 = std::make_shared(); VLOG(6) << "Test Construct Edge"; egr::Edge edge0 = egr::Edge(); - CHECK(edge0.IsInitialized() == false); + PADDLE_ENFORCE_EQ(edge0.IsInitialized(), + false, + phi::errors::Fatal("`edge0.IsInitialized()` should be " + "false, please check related function")); egr::Edge edge1 = egr::Edge(grad_test_node0, size_t(0), size_t(0)); - CHECK(edge1.IsInitialized() == true); + PADDLE_ENFORCE_EQ(edge1.IsInitialized(), + true, + phi::errors::Fatal("`edge1.IsInitialized()` should be " + "true, please check related function")); egr::Edge edge2 = egr::Edge(grad_test_node0, std::make_pair(size_t(1), size_t(0))); VLOG(6) << "Test Set Edge's Grad Node"; @@ -147,7 +173,11 @@ TEST(GradNodeInfo, Edge) { CHECK_EQ(grad_node->InputMeta().size(), size_t(2)); std::vector metas = {auto_grad1.get()}; - CHECK(grad_node->InputMeta()[0][0].IsStopGradient() == true); + PADDLE_ENFORCE_EQ( + grad_node->InputMeta()[0][0].IsStopGradient(), + true, + phi::errors::Fatal("`grad_node->InputMeta()[0][0].IsStopGradient()` " + "should be true, please check related function")); VLOG(6) << "Test Get/Set Edge Rank Info"; CHECK_EQ(edge2.GetEdgeRankInfo().first, size_t(1)); CHECK_EQ(edge2.GetEdgeRankInfo().second, size_t(0)); From 4bfe38b63092a3b66b4e3dbb5816db0663f083a2 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 15:07:57 +0800 Subject: [PATCH 02/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../xpu/weight_only_linear_kernel_xpu.cc | 30 +++++++++++++++---- 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc b/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc index cc0e3c47860c1..db4d10a710d88 100644 --- a/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc +++ b/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc @@ -26,8 +26,11 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, const int32_t arch, const int32_t group_size, DenseTensor* out) { - PD_CHECK(weight_dtype == "int8", - "WeightOnlyLinearKernel xpu just support int8 weight only"); + PADDLE_ENFORCE_EQ( + weight_dtype, + "int8", + phi::errors::Fatal( + "WeightOnlyLinearKernel xpu just support int8 weight only")); phi::XPUPlace place(phi::backends::xpu::GetXPUCurrentDeviceId()); auto xpu_ctx = static_cast(&dev_ctx); dev_ctx.template Alloc(out); @@ -55,14 +58,21 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, false, weight_dtype == "int8" ? 127.f : 7.f, 0.f); - PD_CHECK(r == 0, "scale failed"); + PADDLE_ENFORCE_EQ(r, + 0, + phi::errors::Fatal + "scale failed, scale related variable `r` is %d", + r); r = baidu::xpu::api::cast_v2( xpu_ctx->x_context(), reinterpret_cast( max_value_fp16.data()), max_value.data(), max_value.numel()); - PD_CHECK(r == 0, "cast_v2 failed"); + PADDLE_ENFORCE_EQ(r, + 0, + phi::errors::Fatal( + "cast_v2 failed, related variable `r` is %d", r)); } else if (weight_scale.dtype() == phi::DataType::FLOAT32) { r = baidu::xpu::api::scale(xpu_ctx->x_context(), weight_scale.data(), @@ -71,7 +81,10 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, false, weight_dtype == "int8" ? 127.f : 7.f, 0.f); - PD_CHECK(r == 0, "scale failed"); + PADDLE_ENFORCE_EQ( + r, + 0, + phi::errors::Fatal("scale failed, related variable `r` is %d", r)); } else { PADDLE_THROW(phi::errors::Unimplemented( "Only support that weight scale as type float32 ot float16.")); @@ -115,7 +128,12 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, : nullptr, baidu::xpu::api::Activation_t::LINEAR, max_value.data()); - PD_CHECK(r == 0, "baidu::xpu::api::gpt_fc_fusion failed."); + PADDLE_ENFORCE_EQ( + r, + 0, + phi::errors::Fatal("baidu::xpu::api::gpt_fc_fusion failed, related " + "variable `r` is %d", + r)); } else if (weight_dtype == "int4") { PD_THROW("only support int8 weight only now"); } From 67397ab08e2098bfd1fce106a910edf7b8225c57 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 15:32:13 +0800 Subject: [PATCH 03/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/auto_parallel/custom_op/custom_relu_op.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/auto_parallel/custom_op/custom_relu_op.cc b/test/auto_parallel/custom_op/custom_relu_op.cc index 7f76ab92cb2d1..6a3a052eff8cf 100644 --- a/test/auto_parallel/custom_op/custom_relu_op.cc +++ b/test/auto_parallel/custom_op/custom_relu_op.cc @@ -19,14 +19,17 @@ #include "paddle/phi/api/ext/spmd_infer.h" #include "paddle/phi/infermeta/spmd_rules/rules.h" -#define CHECK_CPU_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") +#define CHECK_CPU_INPUT(x) \ + PADDLE_ENFORCE_EQ( \ + x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) template void relu_cpu_forward_kernel(const data_t* x_data, data_t* out_data, int64_t x_numel) { - PD_CHECK(x_data != nullptr, "x_data is nullptr."); - PD_CHECK(out_data != nullptr, "out_data is nullptr."); + PADDLE_ENFORCE_NE(x_data, nullptr, phi::errors::Fatal("x_data is nullptr.")); + PADDLE_ENFORCE_NE( + out_data, nullptr, phi::errors::Fatal("out_data is nullptr.")); for (int64_t i = 0; i < x_numel; ++i) { out_data[i] = std::max(static_cast(0.), x_data[i]); } From bf8f7ee1483a47a4f279af038759bf966bb923d8 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 15:43:57 +0800 Subject: [PATCH 04/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/cpp_extension/mix_relu_and_extension.cc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/test/cpp_extension/mix_relu_and_extension.cc b/test/cpp_extension/mix_relu_and_extension.cc index afaa8d45eb206..80fd6ee6ff30a 100644 --- a/test/cpp_extension/mix_relu_and_extension.cc +++ b/test/cpp_extension/mix_relu_and_extension.cc @@ -18,14 +18,17 @@ #include "custom_power.h" // NOLINT #include "paddle/extension.h" -#define CHECK_CPU_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") +#define CHECK_CPU_INPUT(x) \ + PADDLE_ENFORCE_EQ( \ + x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) template void relu_cpu_forward_kernel(const data_t* x_data, data_t* out_data, int64_t x_numel) { - PD_CHECK(x_data != nullptr, "x_data is nullptr."); - PD_CHECK(out_data != nullptr, "out_data is nullptr."); + PADDLE_ENFORCE_NE(x_data, nullptr, phi::errors::Fatal("x_data is nullptr.")); + PADDLE_ENFORCE_NE( + out_data, nullptr, phi::errors::Fatal("out_data is nullptr.")); for (int64_t i = 0; i < x_numel; ++i) { out_data[i] = std::max(static_cast(0.), x_data[i]); } From 0b8e9f3acd242525cc59d32eee23af4816fb5dce Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 15:48:15 +0800 Subject: [PATCH 05/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/custom_op/custom_relu_op.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/custom_op/custom_relu_op.cc b/test/custom_op/custom_relu_op.cc index 5627bb28b921f..863d5262be2f9 100644 --- a/test/custom_op/custom_relu_op.cc +++ b/test/custom_op/custom_relu_op.cc @@ -17,14 +17,18 @@ #include "paddle/extension.h" -#define CHECK_CPU_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") +#define CHECK_CPU_INPUT(x) \ + PADDLE_ENFORCE_EQ( \ + x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) template void relu_cpu_forward_kernel(const data_t* x_data, data_t* out_data, int64_t x_numel) { - PD_CHECK(x_data != nullptr, "x_data is nullptr."); - PD_CHECK(out_data != nullptr, "out_data is nullptr."); + PADDLE_ENFORCE_NE( + x_data, nullptr, phi::errors::InvalidArgument("x_data is nullptr.")); + PADDLE_ENFORCE_NE( + out_data, nullptr, phi::errors::InvalidArgument "out_data is nullptr."); for (int64_t i = 0; i < x_numel; ++i) { out_data[i] = std::max(static_cast(0.), x_data[i]); } From 21b671553666c389f873d24f05840e643cff2606 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 15:57:11 +0800 Subject: [PATCH 06/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paddle/cinn/ir/buffer.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/paddle/cinn/ir/buffer.h b/paddle/cinn/ir/buffer.h index 5b173b6792c19..c93308f18d490 100755 --- a/paddle/cinn/ir/buffer.h +++ b/paddle/cinn/ir/buffer.h @@ -110,8 +110,14 @@ class _Buffer_ : public ExprNode<_Buffer_> { const std::vector& shape = {}); static Buffer Make(const std::string& name, Type type) { - CHECK(!type.is_void()); - CHECK(!type.is_unk()); + PADDLE_ENFORCE_EQ(!type.is_void(), + true, + phi::errors::InvalidArgument( + "Input argument `type` should not be void")); + PADDLE_ENFORCE_EQ( + !type.is_unk(), + true, + phi::errors::InvalidArgument("Invalid input argument `type` type")); auto n = make_shared<_Buffer_>(); n->name = name; n->dtype = type; From 6bd639d2871212fb728a55c4419d3887c82ca064 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 16:12:39 +0800 Subject: [PATCH 07/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../infer_symbolic_shape/infer_sym_slice_utils.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h index dcd1911767e78..63468a9110cfc 100644 --- a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h +++ b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h @@ -24,14 +24,20 @@ inline ExprVec GetExprVecFromData(const ShapeOrData &shapeordata) { TensorListExprs list = shapeordata.dyn_cast(); for (size_t i = 0; i < list.size(); i++) { - CHECK(list.at(i).data().has_value()); + PADDLE_ENFORCE_EQ(list.at(i).data().has_value(), + true, + phi::errors::Fatal( + "i-th element of list has no value, please check")); for (auto expr : list.at(i).data().value()) { result.emplace_back(expr); } } return result; } else { - CHECK(shapeordata.data().has_value()); + PADDLE_ENFORCE_EQ( + shapeordata.data().has_value(), + true, + phi::errors::Fatal("`shapeordata.data` is empty, please check")); return shapeordata.data().value(); } } From 845603435a345022975182edddd25742bc25a449 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 16:14:18 +0800 Subject: [PATCH 08/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/custom_op/custom_inplace.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/test/custom_op/custom_inplace.cc b/test/custom_op/custom_inplace.cc index f7db7922bf3f7..1e91551095ad0 100644 --- a/test/custom_op/custom_inplace.cc +++ b/test/custom_op/custom_inplace.cc @@ -18,7 +18,9 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") +#define CHECK_INPUT(x) \ + PADDLE_ENFORCE_EQ( \ + x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) template void add_data_pointer(const data_t* x_data, data_t* out_data, int64_t numel) { @@ -113,8 +115,10 @@ std::vector AddVectorBackward( std::vector& out_grad) { // NOLINT CHECK_INPUT(x[0]); CHECK_INPUT(y); - PD_CHECK(x.size() == out_grad.size(), - "x must have the same size as out_grad."); + PADDLE_ENFORCE_EQ( + x.size(), + out_grad.size(), + phi::errors::InvalidArgument("x must have the same size as out_grad.")); paddle::Tensor y_grad = paddle::zeros(y.shape(), y.dtype(), y.place()); From cae4390d7c22e5f49c8a49ca7c020e87b84572b9 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 16:27:38 +0800 Subject: [PATCH 09/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/custom_op/custom_linear_op.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/custom_op/custom_linear_op.cc b/test/custom_op/custom_linear_op.cc index 268f86fd24574..6b53f130f6e1d 100644 --- a/test/custom_op/custom_linear_op.cc +++ b/test/custom_op/custom_linear_op.cc @@ -42,9 +42,11 @@ std::vector> LinearInferShape( auto dims_y = weight_shape; auto ndims_x = x_shape.size(); auto ndims_y = weight_shape.size(); - PD_CHECK(ndims_x > 0, - "The Input(x) dims size must be greater than 0," - " but received dims size is 0. "); + PADDLE_ENFORCE_GT( + ndims_x, + 0, + phi::errors::InvalidArgument("The Input(x) dims size must be greater " + "than 0, but received dims size is 0. ")); PD_CHECK(ndims_y > 0, "The Input(y) dims size must be greater than 0," " but received dims size is 0. "); From 3bac19e3f94344f85f168abc05bda047f48c0fca Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 16:33:18 +0800 Subject: [PATCH 10/25] =?UTF-8?q?=E5=AE=8C=E6=88=90=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/custom_op/custom_linear_op.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/custom_op/custom_linear_op.cc b/test/custom_op/custom_linear_op.cc index 6b53f130f6e1d..44f16f475c95f 100644 --- a/test/custom_op/custom_linear_op.cc +++ b/test/custom_op/custom_linear_op.cc @@ -47,9 +47,11 @@ std::vector> LinearInferShape( 0, phi::errors::InvalidArgument("The Input(x) dims size must be greater " "than 0, but received dims size is 0. ")); - PD_CHECK(ndims_y > 0, - "The Input(y) dims size must be greater than 0," - " but received dims size is 0. "); + PADDLE_ENFORCE_GT( + ndims_y, + 0, + phi::errors::InvalidArgument("The Input(y) dims size must be greater " + "than 0, but received dims size is 0. ")); bool x_broadcasted = false, y_broadcasted = false; if (ndims_x == 1) { From 3777caa26dd3613c2ab392e7a646c63027fdac51 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 16:45:17 +0800 Subject: [PATCH 11/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../cpp/inference/api/analyzer_dam_tester.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc b/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc index 584033ae673a1..35d0e1268947a 100644 --- a/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc +++ b/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc @@ -70,8 +70,15 @@ struct DataRecord { response.begin() + batch_end); data.response_mask.assign(response_mask.begin() + batch_iter, response_mask.begin() + batch_end); - CHECK(!data.response.empty()); - CHECK(!data.response_mask.empty()); + PADDLE_ENFORCE_EQ(!data.response.empty(), + true, + phi::errors::Fatal( + "Variable `data` response is empty, please check")); + PADDLE_ENFORCE_EQ( + !data.response_mask.empty(), + true, + phi::errors::Fatal( + "Variable `data` response mask is empty, please check")); CHECK_EQ(data.response.size(), data.response_mask.size()); } batch_iter += batch_size; From 98e44b57005432deee01dbbeeb69d9a9927f0e1f Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 16:53:33 +0800 Subject: [PATCH 12/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inference/api/analyzer_text_classification_tester.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc b/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc index fb5284239f99f..ef6d737e940ea 100644 --- a/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc +++ b/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc @@ -39,8 +39,13 @@ struct DataReader { tensor.lod.front().push_back(data.size()); tensor.data.Resize(data.size() * sizeof(int64_t)); - CHECK(tensor.data.data() != nullptr); - CHECK(data.data() != nullptr); + PADDLE_ENFORCE_NE( + tensor.data.data(), + nullptr, + phi::errors::Fatal("Variable `tensor.data.data()` is nullptr")); + PADDLE_ENFORCE_EQ(data.data(), + nullptr, + phi::errors::Fatal("Variable `data.data()` is nullptr")); memcpy(tensor.data.data(), data.data(), data.size() * sizeof(int64_t)); tensor.shape.push_back(data.size()); tensor.shape.push_back(1); From 5f519ed10aca123224a8bc7f817100add5a0a096 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:13:16 +0800 Subject: [PATCH 13/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../interface/infer_symbolic_shape/unary_infer_sym.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc index 79512fb69ea95..818d73b422374 100644 --- a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc +++ b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc @@ -912,7 +912,9 @@ bool SplitOpInferSymbolicShape(pir::Operation *op, const auto &x_dims_sym = x_shape_or_data.shape(); // axis - CHECK(op->operand_source(2).defining_op()->isa()); + PADDLE_ENFORCE( + op->operand_source(2).defining_op()->isa(), + phi::errors::InvalidArgument("Invalid input args : axis, pleace check")); int64_t axis = op->operand_source(2) .defining_op() From 23d3310a0cc0820e91c672da6ad6e23ff60b4d3b Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:18:36 +0800 Subject: [PATCH 14/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../operator/interface/infer_symbolic_shape/unary_infer_sym.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc index 818d73b422374..6dd79a34caf52 100644 --- a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc +++ b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc @@ -912,8 +912,9 @@ bool SplitOpInferSymbolicShape(pir::Operation *op, const auto &x_dims_sym = x_shape_or_data.shape(); // axis - PADDLE_ENFORCE( + PADDLE_ENFORCE_EQ( op->operand_source(2).defining_op()->isa(), + true, phi::errors::InvalidArgument("Invalid input args : axis, pleace check")); int64_t axis = op->operand_source(2) From 3f689af330984ea5c671663d939dd192973e18a0 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:21:11 +0800 Subject: [PATCH 15/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paddle/fluid/pir/dialect/operator/ir/op_dialect.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc b/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc index 487aedec58e8a..9aec0d99587a4 100644 --- a/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc +++ b/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc @@ -174,7 +174,10 @@ struct SliceOpInferSymbolicShapeInterfaceModel op->attributes().at("index").dyn_cast().data(); const auto& input_shape = infer_context->GetShapeOrDataForValue(op->operand_source(0)); - CHECK(input_shape.isa()); + PADDLE_ENFORCE_EQ(input_shape.isa(), + true, + phi::errors::InvalidArgument( + "Input shape can not be converted, please check")); const symbol::TensorListShapeOrDataDimExprs& data_shape_list = input_shape.dyn_cast(); const symbol::TensorShapeOrDataDimExprs& output_shape = From 8d326290430501e9f0f5f36f264e7a3368eab575 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:22:35 +0800 Subject: [PATCH 16/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc b/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc index 95a0313191301..7c8928df2950f 100644 --- a/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc +++ b/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc @@ -37,7 +37,8 @@ void GetMaxLenTensor(const Context& dev_ctx, max_len_tensor_data, {bsz}, {0}); - PD_CHECK(r == 0, "baidu::xpu::api::reduce_max failed."); + PADDLE_ENFORCE_EQ( + r, 0, phi::errors::Fatal("baidu::xpu::api::reduce_max failed.")); MemcpyD2HKernel(dev_ctx, max_len_tensor, 0, out); } From 634b60405090b81e8d4fff52cc4ed5113a79cdf1 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:25:41 +0800 Subject: [PATCH 17/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paddle/phi/kernels/gpu/shuffle_batch_utils.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/paddle/phi/kernels/gpu/shuffle_batch_utils.h b/paddle/phi/kernels/gpu/shuffle_batch_utils.h index dfcbcf5716f04..9bda8bfbb5f01 100644 --- a/paddle/phi/kernels/gpu/shuffle_batch_utils.h +++ b/paddle/phi/kernels/gpu/shuffle_batch_utils.h @@ -41,6 +41,10 @@ struct CacheAllocator { VLOG(2) << "deallocate "; allocation_map_type::iterator iter = busy_allocation_.find(ptr); CHECK(iter != busy_allocation_.end()); + PADDLE_ENFORCE_NE(iter, + busy_allocation_.end(), + phi::errors::InvalidArgument( + "Deallocate failed, can not find right position")); busy_allocation_.erase(iter); } From da150c151e93713dff868b31ac102190e954fc71 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:32:41 +0800 Subject: [PATCH 18/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dialect/shape/transforms/shape_optimization_pass.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc b/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc index 44fe61d8656be..d1153607bf494 100644 --- a/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc +++ b/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc @@ -288,7 +288,13 @@ void InferSymExprForOp(Operation* op, std::vector cached_result_shape_or_data = infer_context->GetOpInferSymbolicShapeCache(op_infer_cache_key) .value(); - CHECK(cached_result_shape_or_data.size() == op->num_results()); + PADDLE_ENFORCE_EQ( + cached_result_shape_or_data.size(), + op->num_results(), + phi::errors::Fatal("Cached number of result %u is not equal to the " + "given number of output %u", + cached_result_shape_or_data.size(), + op->num_results())); for (uint32_t i = 0; i < op->num_results(); ++i) { infer_context->SetShapeOrDataForValue(op->result(i), cached_result_shape_or_data[i]); From c05910609d1fcdbab7783cbb04061fae688aea42 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:50:39 +0800 Subject: [PATCH 19/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/cpp/eager/data_structure_tests/tensor_wrapper_test.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/cpp/eager/data_structure_tests/tensor_wrapper_test.cc b/test/cpp/eager/data_structure_tests/tensor_wrapper_test.cc index f2ebd8d311e91..8b02f0f21c076 100644 --- a/test/cpp/eager/data_structure_tests/tensor_wrapper_test.cc +++ b/test/cpp/eager/data_structure_tests/tensor_wrapper_test.cc @@ -78,5 +78,9 @@ TEST(TensorWrapper, Basic) { // Test Raw recover paddle::Tensor et3; auto tw2 = egr::TensorWrapper(et3); - CHECK(tw2.recover().initialized() == false); + PADDLE_ENFORCE_EQ( + tw2.recover().initialized(), + false, + phi::errors::Fatal( + "Variable `tw2` should not be initialized after recover")); } From e5f1f8dd2b6018fad9f701b60f9e7d0aa447a5ee Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:52:48 +0800 Subject: [PATCH 20/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/custom_op/custom_conj_op.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/custom_op/custom_conj_op.cc b/test/custom_op/custom_conj_op.cc index 0f76f715c427f..553247942138b 100644 --- a/test/custom_op/custom_conj_op.cc +++ b/test/custom_op/custom_conj_op.cc @@ -18,7 +18,9 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") +#define CHECK_INPUT(x) \ + PADDLE_ENFORCE_EQ( \ + x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) template using EnableComplex = typename std::enable_if< From 19b945157a309e07aead992f7c449671bf00bd1d Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:53:46 +0800 Subject: [PATCH 21/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/custom_op/custom_optional.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/custom_op/custom_optional.cc b/test/custom_op/custom_optional.cc index 9d247f4a27694..fc4c7e613c941 100644 --- a/test/custom_op/custom_optional.cc +++ b/test/custom_op/custom_optional.cc @@ -18,7 +18,9 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") +#define CHECK_INPUT(x) \ + PADDLE_ENFORCE_EQ( \ + x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) template void add_one_pointer(const data_t* x_data, data_t* out_data, int64_t numel) { From 75762eff726e8b7f09573244f5c0cd65b4c44f8c Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:55:31 +0800 Subject: [PATCH 22/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/deprecated/cpp/inference/analysis/analyzer_tester.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/deprecated/cpp/inference/analysis/analyzer_tester.cc b/test/deprecated/cpp/inference/analysis/analyzer_tester.cc index 14d525ac3714a..d00e401f1e51c 100644 --- a/test/deprecated/cpp/inference/analysis/analyzer_tester.cc +++ b/test/deprecated/cpp/inference/analysis/analyzer_tester.cc @@ -77,7 +77,10 @@ void TestWord2vecPrediction(const std::string& model_path) { // For simplicity, we set all the slots with the same data. std::vector slots(4, tensor); std::vector outputs; - CHECK(predictor->Run(slots, &outputs)); + PADDLE_ENFORCE_EQ( + predictor->Run(slots, &outputs), + true, + phi::errors::Fatal("Paddle predictor failed runing, please check")); PADDLE_ENFORCE_EQ(outputs.size(), 1UL, From 7c4fde8dbd9ffca35dc89062431e439403c61bd6 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:57:13 +0800 Subject: [PATCH 23/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc b/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc index 81c7df7887862..85e22874759f0 100644 --- a/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc +++ b/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc @@ -45,7 +45,11 @@ struct DataRecord { link_step_data_all.begin() + batch_end); // Prepare LoDs data.lod.push_back(0); - CHECK(!data.link_step_data_all.empty()) << "empty"; + PADDLE_ENFORCE_EQ( + !data.link_step_data_all.empty(), + true, + phi::errors::InvalidArgument( + "`data.link_step_data_all` is empty, please check")); for (size_t j = 0; j < data.link_step_data_all.size(); j++) { for (const auto &d : data.link_step_data_all[j]) { data.rnn_link_data.push_back(d); From 276f76c9d6c4a2a4e42296d4c38d48c389bc6c9a Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Tue, 30 Jul 2024 17:58:35 +0800 Subject: [PATCH 24/25] =?UTF-8?q?=E6=9B=BF=E6=8D=A2=E6=97=A7CHECK=E5=AE=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/ipu/custom_ops/leaky_relu_cpu.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/ipu/custom_ops/leaky_relu_cpu.cc b/test/ipu/custom_ops/leaky_relu_cpu.cc index d118aa4380246..8adefccd4c8c4 100644 --- a/test/ipu/custom_ops/leaky_relu_cpu.cc +++ b/test/ipu/custom_ops/leaky_relu_cpu.cc @@ -14,8 +14,9 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) \ - PD_CHECK(x.place() == paddle::PlaceType::kCPU, #x " must be a CPU Tensor.") +#define CHECK_INPUT(x) \ + PADDLE_ENFORCE_EQ(x.place() == paddle::PlaceType::kCPU, \ + phi::errors::Fatal(#x " must be a CPU Tensor.")) template void leaky_relu_cpu_forward_kernel(const data_t* x_data, From 5e6a5e270fd743a37053a07741c7f33d7e292605 Mon Sep 17 00:00:00 2001 From: Lans1ot Date: Fri, 2 Aug 2024 00:16:05 +0800 Subject: [PATCH 25/25] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- paddle/cinn/ir/buffer.h | 12 ++--- .../infer_sym_slice_utils.h | 10 ++-- .../infer_symbolic_shape/unary_infer_sym.cc | 3 +- .../pir/dialect/operator/ir/op_dialect.cc | 2 +- .../fusion/xpu/blha_get_max_len_kernel.cc | 2 +- .../xpu/weight_only_linear_kernel_xpu.cc | 34 ++++++------- paddle/phi/kernels/gpu/shuffle_batch_utils.h | 2 +- .../transforms/shape_optimization_pass.cc | 14 ++--- .../auto_parallel/custom_op/custom_relu_op.cc | 5 +- .../grad_node_info_test.cc | 51 ++++++++++--------- test/cpp_extension/mix_relu_and_extension.cc | 5 +- test/custom_op/custom_conj_op.cc | 4 +- test/custom_op/custom_inplace.cc | 10 ++-- test/custom_op/custom_linear_op.cc | 16 +++--- test/custom_op/custom_optional.cc | 4 +- test/custom_op/custom_relu_op.cc | 10 ++-- .../cpp/inference/analysis/analyzer_tester.cc | 2 +- .../cpp/inference/api/analyzer_dam_tester.cc | 4 +- .../cpp/inference/api/analyzer_rnn2_tester.cc | 2 +- .../analyzer_text_classification_tester.cc | 9 ++-- test/ipu/custom_ops/leaky_relu_cpu.cc | 3 +- 21 files changed, 98 insertions(+), 106 deletions(-) diff --git a/paddle/cinn/ir/buffer.h b/paddle/cinn/ir/buffer.h index c93308f18d490..fea8725da9db6 100755 --- a/paddle/cinn/ir/buffer.h +++ b/paddle/cinn/ir/buffer.h @@ -21,6 +21,7 @@ #include "paddle/cinn/common/common.h" #include "paddle/cinn/ir/ir.h" +#include "paddle/common/enforce.h" namespace cinn { namespace ir { @@ -108,16 +109,15 @@ class _Buffer_ : public ExprNode<_Buffer_> { static Buffer Make(const std::string& name, const std::vector& shape = {}); - static Buffer Make(const std::string& name, Type type) { PADDLE_ENFORCE_EQ(!type.is_void(), true, - phi::errors::InvalidArgument( + ::common::errors::InvalidArgument( "Input argument `type` should not be void")); - PADDLE_ENFORCE_EQ( - !type.is_unk(), - true, - phi::errors::InvalidArgument("Invalid input argument `type` type")); + PADDLE_ENFORCE_EQ(!type.is_unk(), + true, + ::common::errors::InvalidArgument( + "Invalid input argument `type` type")); auto n = make_shared<_Buffer_>(); n->name = name; n->dtype = type; diff --git a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h index c8fceb9bbfc1b..f225326dbea21 100644 --- a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h +++ b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/infer_sym_slice_utils.h @@ -26,7 +26,7 @@ inline ExprVec GetExprVecFromData(const ShapeOrData &shapeordata) { for (size_t i = 0; i < list.size(); i++) { PADDLE_ENFORCE_EQ(list.at(i).data().has_value(), true, - phi::errors::Fatal( + common::errors::InvalidArgument( "i-th element of list has no value, please check")); for (auto expr : list.at(i).data().value()) { result.emplace_back(expr); @@ -34,10 +34,10 @@ inline ExprVec GetExprVecFromData(const ShapeOrData &shapeordata) { } return result; } else { - PADDLE_ENFORCE_EQ( - shapeordata.data().has_value(), - true, - phi::errors::Fatal("`shapeordata.data` is empty, please check")); + PADDLE_ENFORCE_EQ(shapeordata.data().has_value(), + true, + common::errors::InvalidArgument( + "Input `shapeordata.data` is empty, please check")); return shapeordata.data().value(); } } diff --git a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc index d95564393d909..0a21f4306840a 100644 --- a/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc +++ b/paddle/fluid/pir/dialect/operator/interface/infer_symbolic_shape/unary_infer_sym.cc @@ -1271,7 +1271,8 @@ bool SplitOpInferSymbolicShape(pir::Operation *op, PADDLE_ENFORCE_EQ( op->operand_source(2).defining_op()->isa(), true, - phi::errors::InvalidArgument("Invalid input args : axis, pleace check")); + common::errors::InvalidArgument( + "Invalid input args : axis, pleace check")); int64_t axis = op->operand_source(2) .defining_op() diff --git a/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc b/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc index 9aec0d99587a4..c5880be8e0dfb 100644 --- a/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc +++ b/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc @@ -176,7 +176,7 @@ struct SliceOpInferSymbolicShapeInterfaceModel infer_context->GetShapeOrDataForValue(op->operand_source(0)); PADDLE_ENFORCE_EQ(input_shape.isa(), true, - phi::errors::InvalidArgument( + common::errors::InvalidArgument( "Input shape can not be converted, please check")); const symbol::TensorListShapeOrDataDimExprs& data_shape_list = input_shape.dyn_cast(); diff --git a/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc b/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc index 7c8928df2950f..c6b259b0ff1d8 100644 --- a/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc +++ b/paddle/phi/kernels/fusion/xpu/blha_get_max_len_kernel.cc @@ -38,7 +38,7 @@ void GetMaxLenTensor(const Context& dev_ctx, {bsz}, {0}); PADDLE_ENFORCE_EQ( - r, 0, phi::errors::Fatal("baidu::xpu::api::reduce_max failed.")); + r, 0, common::errors::Fatal("baidu::xpu::api::reduce_max failed.")); MemcpyD2HKernel(dev_ctx, max_len_tensor, 0, out); } diff --git a/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc b/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc index db4d10a710d88..ec607a4e9aa64 100644 --- a/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc +++ b/paddle/phi/kernels/fusion/xpu/weight_only_linear_kernel_xpu.cc @@ -29,7 +29,7 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, PADDLE_ENFORCE_EQ( weight_dtype, "int8", - phi::errors::Fatal( + common::errors::Fatal( "WeightOnlyLinearKernel xpu just support int8 weight only")); phi::XPUPlace place(phi::backends::xpu::GetXPUCurrentDeviceId()); auto xpu_ctx = static_cast(&dev_ctx); @@ -58,11 +58,11 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, false, weight_dtype == "int8" ? 127.f : 7.f, 0.f); - PADDLE_ENFORCE_EQ(r, - 0, - phi::errors::Fatal - "scale failed, scale related variable `r` is %d", - r); + PADDLE_ENFORCE_EQ( + r, + 0, + common::errors::Fatal( + "scale failed, scale related variable `r` is %d", r)); r = baidu::xpu::api::cast_v2( xpu_ctx->x_context(), reinterpret_cast( @@ -71,7 +71,7 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, max_value.numel()); PADDLE_ENFORCE_EQ(r, 0, - phi::errors::Fatal( + common::errors::Fatal( "cast_v2 failed, related variable `r` is %d", r)); } else if (weight_scale.dtype() == phi::DataType::FLOAT32) { r = baidu::xpu::api::scale(xpu_ctx->x_context(), @@ -81,10 +81,10 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, false, weight_dtype == "int8" ? 127.f : 7.f, 0.f); - PADDLE_ENFORCE_EQ( - r, - 0, - phi::errors::Fatal("scale failed, related variable `r` is %d", r)); + PADDLE_ENFORCE_EQ(r, + 0, + common::errors::Fatal( + "scale failed, related variable `r` is %d", r)); } else { PADDLE_THROW(phi::errors::Unimplemented( "Only support that weight scale as type float32 ot float16.")); @@ -128,12 +128,12 @@ void WeightOnlyLinearKernel(const Context& dev_ctx, : nullptr, baidu::xpu::api::Activation_t::LINEAR, max_value.data()); - PADDLE_ENFORCE_EQ( - r, - 0, - phi::errors::Fatal("baidu::xpu::api::gpt_fc_fusion failed, related " - "variable `r` is %d", - r)); + PADDLE_ENFORCE_EQ(r, + 0, + common::errors::Fatal( + "baidu::xpu::api::gpt_fc_fusion failed, related " + "variable `r` is %d", + r)); } else if (weight_dtype == "int4") { PD_THROW("only support int8 weight only now"); } diff --git a/paddle/phi/kernels/gpu/shuffle_batch_utils.h b/paddle/phi/kernels/gpu/shuffle_batch_utils.h index 9bda8bfbb5f01..807fdedd5511d 100644 --- a/paddle/phi/kernels/gpu/shuffle_batch_utils.h +++ b/paddle/phi/kernels/gpu/shuffle_batch_utils.h @@ -43,7 +43,7 @@ struct CacheAllocator { CHECK(iter != busy_allocation_.end()); PADDLE_ENFORCE_NE(iter, busy_allocation_.end(), - phi::errors::InvalidArgument( + common::errors::InvalidArgument( "Deallocate failed, can not find right position")); busy_allocation_.erase(iter); } diff --git a/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc b/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc index 88fca1e8c2c2a..bc4004f6eab12 100644 --- a/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc +++ b/paddle/pir/src/dialect/shape/transforms/shape_optimization_pass.cc @@ -288,13 +288,13 @@ void InferSymExprForOp(Operation* op, std::vector cached_result_shape_or_data = infer_context->GetOpInferSymbolicShapeCache(op_infer_cache_key) .value(); - PADDLE_ENFORCE_EQ( - cached_result_shape_or_data.size(), - op->num_results(), - phi::errors::Fatal("Cached number of result %u is not equal to the " - "given number of output %u", - cached_result_shape_or_data.size(), - op->num_results())); + PADDLE_ENFORCE_EQ(cached_result_shape_or_data.size(), + op->num_results(), + common::errors::Fatal( + "Cached number of result %u is not equal to the " + "given number of output %u", + cached_result_shape_or_data.size(), + op->num_results())); for (uint32_t i = 0; i < op->num_results(); ++i) { infer_context->SetShapeOrDataForValue(op->result(i), cached_result_shape_or_data[i]); diff --git a/test/auto_parallel/custom_op/custom_relu_op.cc b/test/auto_parallel/custom_op/custom_relu_op.cc index 6a3a052eff8cf..9041ae1058d30 100644 --- a/test/auto_parallel/custom_op/custom_relu_op.cc +++ b/test/auto_parallel/custom_op/custom_relu_op.cc @@ -21,13 +21,14 @@ #define CHECK_CPU_INPUT(x) \ PADDLE_ENFORCE_EQ( \ - x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) + x.is_cpu(), true, common::errors::Fatal(#x " must be a CPU Tensor.")) template void relu_cpu_forward_kernel(const data_t* x_data, data_t* out_data, int64_t x_numel) { - PADDLE_ENFORCE_NE(x_data, nullptr, phi::errors::Fatal("x_data is nullptr.")); + PADDLE_ENFORCE_NE( + x_data, nullptr, common::errors::Fatal("x_data is nullptr.")); PADDLE_ENFORCE_NE( out_data, nullptr, phi::errors::Fatal("out_data is nullptr.")); for (int64_t i = 0; i < x_numel; ++i) { diff --git a/test/cpp/eager/data_structure_tests/grad_node_info_test.cc b/test/cpp/eager/data_structure_tests/grad_node_info_test.cc index b23c51dbdd2e9..f231a492beacf 100644 --- a/test/cpp/eager/data_structure_tests/grad_node_info_test.cc +++ b/test/cpp/eager/data_structure_tests/grad_node_info_test.cc @@ -27,10 +27,11 @@ TEST(GradNodeInfo, GradSlotMeta) { auto grad_slot = egr::GradSlotMeta(); VLOG(6) << "Set SetStopGradient"; grad_slot.SetStopGradient(); - PADDLE_ENFORCE_EQ(grad_slot.IsStopGradient(), - true, - phi::errors::Fatal("`grad_slot.IsStopGradient()` should be " - "true, please check related function")); + PADDLE_ENFORCE_EQ( + grad_slot.IsStopGradient(), + true, + common::errors::Fatal("`grad_slot.IsStopGradient()` should be " + "true, please check related function")); } void TestGradNodeBase(bool is_remove_gradient_hook) { @@ -83,16 +84,16 @@ void TestGradNodeBase(bool is_remove_gradient_hook) { grad_test_node0->InputMeta()[1][0].GetTensorMeta().dtype, meta.dtype, phi::errors::InvalidArgument("Dtype of input tensor mismatch.")); - PADDLE_ENFORCE_EQ( - grad_test_node0->OutputMeta()[0][0].IsStopGradient(), - true, - phi::errors::Fatal("`grad_test_node0->OutputMeta()[0][0].IsStopGradient()" - "` should be true, please related function")); - PADDLE_ENFORCE_EQ( - grad_test_node0->OutputMeta()[1][0].IsStopGradient(), - true, - phi::errors::Fatal("`grad_test_node0->OutputMeta()[1][0].IsStopGradient()" - "` should be true, please related function")); + PADDLE_ENFORCE_EQ(grad_test_node0->OutputMeta()[0][0].IsStopGradient(), + true, + common::errors::Fatal( + "`grad_test_node0->OutputMeta()[0][0].IsStopGradient()" + "` should be true, please related function")); + PADDLE_ENFORCE_EQ(grad_test_node0->OutputMeta()[1][0].IsStopGradient(), + true, + common::errors::Fatal( + "`grad_test_node0->OutputMeta()[1][0].IsStopGradient()" + "` should be true, please related function")); PADDLE_ENFORCE_EQ( grad_test_node0->OutputMeta()[0][0].GetTensorMeta().dtype, meta.dtype, @@ -171,15 +172,17 @@ TEST(GradNodeInfo, Edge) { auto auto_grad1 = std::make_shared(); VLOG(6) << "Test Construct Edge"; egr::Edge edge0 = egr::Edge(); - PADDLE_ENFORCE_EQ(edge0.IsInitialized(), - false, - phi::errors::Fatal("`edge0.IsInitialized()` should be " - "false, please check related function")); + PADDLE_ENFORCE_EQ( + edge0.IsInitialized(), + false, + common::errors::Fatal("`edge0.IsInitialized()` should be " + "false, please check related function")); egr::Edge edge1 = egr::Edge(grad_test_node0, size_t(0), size_t(0)); - PADDLE_ENFORCE_EQ(edge1.IsInitialized(), - true, - phi::errors::Fatal("`edge1.IsInitialized()` should be " - "true, please check related function")); + PADDLE_ENFORCE_EQ( + edge1.IsInitialized(), + true, + common::errors::Fatal("`edge1.IsInitialized()` should be " + "true, please check related function")); egr::Edge edge2 = egr::Edge(grad_test_node0, std::make_pair(size_t(1), size_t(0))); VLOG(6) << "Test Set Edge's Grad Node"; @@ -195,8 +198,8 @@ TEST(GradNodeInfo, Edge) { PADDLE_ENFORCE_EQ( grad_node->InputMeta()[0][0].IsStopGradient(), true, - phi::errors::Fatal("`grad_node->InputMeta()[0][0].IsStopGradient()` " - "should be true, please check related function")); + common::errors::Fatal("`grad_node->InputMeta()[0][0].IsStopGradient()` " + "should be true, please check related function")); VLOG(6) << "Test Get/Set Edge Rank Info"; PADDLE_ENFORCE_EQ( edge2.GetEdgeRankInfo().first, diff --git a/test/cpp_extension/mix_relu_and_extension.cc b/test/cpp_extension/mix_relu_and_extension.cc index 80fd6ee6ff30a..3c3f4eb11e67a 100644 --- a/test/cpp_extension/mix_relu_and_extension.cc +++ b/test/cpp_extension/mix_relu_and_extension.cc @@ -20,13 +20,14 @@ #define CHECK_CPU_INPUT(x) \ PADDLE_ENFORCE_EQ( \ - x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) + x.is_cpu(), true, common::errors::Fatal(#x " must be a CPU Tensor.")) template void relu_cpu_forward_kernel(const data_t* x_data, data_t* out_data, int64_t x_numel) { - PADDLE_ENFORCE_NE(x_data, nullptr, phi::errors::Fatal("x_data is nullptr.")); + PADDLE_ENFORCE_NE( + x_data, nullptr, common::errors::Fatal("x_data is nullptr.")); PADDLE_ENFORCE_NE( out_data, nullptr, phi::errors::Fatal("out_data is nullptr.")); for (int64_t i = 0; i < x_numel; ++i) { diff --git a/test/custom_op/custom_conj_op.cc b/test/custom_op/custom_conj_op.cc index 553247942138b..0f76f715c427f 100644 --- a/test/custom_op/custom_conj_op.cc +++ b/test/custom_op/custom_conj_op.cc @@ -18,9 +18,7 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) \ - PADDLE_ENFORCE_EQ( \ - x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) +#define CHECK_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") template using EnableComplex = typename std::enable_if< diff --git a/test/custom_op/custom_inplace.cc b/test/custom_op/custom_inplace.cc index 1e91551095ad0..f7db7922bf3f7 100644 --- a/test/custom_op/custom_inplace.cc +++ b/test/custom_op/custom_inplace.cc @@ -18,9 +18,7 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) \ - PADDLE_ENFORCE_EQ( \ - x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) +#define CHECK_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") template void add_data_pointer(const data_t* x_data, data_t* out_data, int64_t numel) { @@ -115,10 +113,8 @@ std::vector AddVectorBackward( std::vector& out_grad) { // NOLINT CHECK_INPUT(x[0]); CHECK_INPUT(y); - PADDLE_ENFORCE_EQ( - x.size(), - out_grad.size(), - phi::errors::InvalidArgument("x must have the same size as out_grad.")); + PD_CHECK(x.size() == out_grad.size(), + "x must have the same size as out_grad."); paddle::Tensor y_grad = paddle::zeros(y.shape(), y.dtype(), y.place()); diff --git a/test/custom_op/custom_linear_op.cc b/test/custom_op/custom_linear_op.cc index 44f16f475c95f..268f86fd24574 100644 --- a/test/custom_op/custom_linear_op.cc +++ b/test/custom_op/custom_linear_op.cc @@ -42,16 +42,12 @@ std::vector> LinearInferShape( auto dims_y = weight_shape; auto ndims_x = x_shape.size(); auto ndims_y = weight_shape.size(); - PADDLE_ENFORCE_GT( - ndims_x, - 0, - phi::errors::InvalidArgument("The Input(x) dims size must be greater " - "than 0, but received dims size is 0. ")); - PADDLE_ENFORCE_GT( - ndims_y, - 0, - phi::errors::InvalidArgument("The Input(y) dims size must be greater " - "than 0, but received dims size is 0. ")); + PD_CHECK(ndims_x > 0, + "The Input(x) dims size must be greater than 0," + " but received dims size is 0. "); + PD_CHECK(ndims_y > 0, + "The Input(y) dims size must be greater than 0," + " but received dims size is 0. "); bool x_broadcasted = false, y_broadcasted = false; if (ndims_x == 1) { diff --git a/test/custom_op/custom_optional.cc b/test/custom_op/custom_optional.cc index fc4c7e613c941..9d247f4a27694 100644 --- a/test/custom_op/custom_optional.cc +++ b/test/custom_op/custom_optional.cc @@ -18,9 +18,7 @@ #include "paddle/extension.h" -#define CHECK_INPUT(x) \ - PADDLE_ENFORCE_EQ( \ - x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) +#define CHECK_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") template void add_one_pointer(const data_t* x_data, data_t* out_data, int64_t numel) { diff --git a/test/custom_op/custom_relu_op.cc b/test/custom_op/custom_relu_op.cc index 863d5262be2f9..5627bb28b921f 100644 --- a/test/custom_op/custom_relu_op.cc +++ b/test/custom_op/custom_relu_op.cc @@ -17,18 +17,14 @@ #include "paddle/extension.h" -#define CHECK_CPU_INPUT(x) \ - PADDLE_ENFORCE_EQ( \ - x.is_cpu(), true, phi::errors::Fatal(#x " must be a CPU Tensor.")) +#define CHECK_CPU_INPUT(x) PD_CHECK(x.is_cpu(), #x " must be a CPU Tensor.") template void relu_cpu_forward_kernel(const data_t* x_data, data_t* out_data, int64_t x_numel) { - PADDLE_ENFORCE_NE( - x_data, nullptr, phi::errors::InvalidArgument("x_data is nullptr.")); - PADDLE_ENFORCE_NE( - out_data, nullptr, phi::errors::InvalidArgument "out_data is nullptr."); + PD_CHECK(x_data != nullptr, "x_data is nullptr."); + PD_CHECK(out_data != nullptr, "out_data is nullptr."); for (int64_t i = 0; i < x_numel; ++i) { out_data[i] = std::max(static_cast(0.), x_data[i]); } diff --git a/test/deprecated/cpp/inference/analysis/analyzer_tester.cc b/test/deprecated/cpp/inference/analysis/analyzer_tester.cc index b997864f82854..ac86ade2f747b 100644 --- a/test/deprecated/cpp/inference/analysis/analyzer_tester.cc +++ b/test/deprecated/cpp/inference/analysis/analyzer_tester.cc @@ -80,7 +80,7 @@ void TestWord2vecPrediction(const std::string& model_path) { PADDLE_ENFORCE_EQ( predictor->Run(slots, &outputs), true, - phi::errors::Fatal("Paddle predictor failed runing, please check")); + common::errors::Fatal("Paddle predictor failed runing, please check")); PADDLE_ENFORCE_EQ(outputs.size(), 1UL, diff --git a/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc b/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc index ddf4ad72f2273..ab0e732aa33e0 100644 --- a/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc +++ b/test/deprecated/cpp/inference/api/analyzer_dam_tester.cc @@ -72,12 +72,12 @@ struct DataRecord { response_mask.begin() + batch_end); PADDLE_ENFORCE_EQ(!data.response.empty(), true, - phi::errors::Fatal( + common::errors::Fatal( "Variable `data` response is empty, please check")); PADDLE_ENFORCE_EQ( !data.response_mask.empty(), true, - phi::errors::Fatal( + common::errors::Fatal( "Variable `data` response mask is empty, please check")); PADDLE_ENFORCE_EQ(data.response.size(), data.response_mask.size(), diff --git a/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc b/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc index 83177c6bd307d..c94d7150590ee 100644 --- a/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc +++ b/test/deprecated/cpp/inference/api/analyzer_rnn2_tester.cc @@ -48,7 +48,7 @@ struct DataRecord { PADDLE_ENFORCE_EQ( !data.link_step_data_all.empty(), true, - phi::errors::InvalidArgument( + common::errors::InvalidArgument( "`data.link_step_data_all` is empty, please check")); for (size_t j = 0; j < data.link_step_data_all.size(); j++) { for (const auto &d : data.link_step_data_all[j]) { diff --git a/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc b/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc index 59c7cefe955cf..82e81d5dc40cf 100644 --- a/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc +++ b/test/deprecated/cpp/inference/api/analyzer_text_classification_tester.cc @@ -42,10 +42,11 @@ struct DataReader { PADDLE_ENFORCE_NE( tensor.data.data(), nullptr, - phi::errors::Fatal("Variable `tensor.data.data()` is nullptr")); - PADDLE_ENFORCE_EQ(data.data(), - nullptr, - phi::errors::Fatal("Variable `data.data()` is nullptr")); + common::errors::Fatal("Variable `tensor.data.data()` is nullptr")); + PADDLE_ENFORCE_NE( + data.data(), + nullptr, + common::errors::Fatal("Variable `data.data()` is nullptr")); memcpy(tensor.data.data(), data.data(), data.size() * sizeof(int64_t)); tensor.shape.push_back(data.size()); tensor.shape.push_back(1); diff --git a/test/ipu/custom_ops/leaky_relu_cpu.cc b/test/ipu/custom_ops/leaky_relu_cpu.cc index 8adefccd4c8c4..f47fa43d30b2e 100644 --- a/test/ipu/custom_ops/leaky_relu_cpu.cc +++ b/test/ipu/custom_ops/leaky_relu_cpu.cc @@ -16,7 +16,8 @@ #define CHECK_INPUT(x) \ PADDLE_ENFORCE_EQ(x.place() == paddle::PlaceType::kCPU, \ - phi::errors::Fatal(#x " must be a CPU Tensor.")) + true, \ + common::errors::Fatal(#x " must be a CPU Tensor.")) template void leaky_relu_cpu_forward_kernel(const data_t* x_data,