From bf89513ae442031818589c34ef45ada810562eea Mon Sep 17 00:00:00 2001 From: Liyulingyue <852433440@qq.com> Date: Sat, 16 Mar 2024 20:10:54 +0800 Subject: [PATCH 1/3] try convert check_ into pd_enforce --- paddle/cinn/frontend/decomposer/broadcast.cc | 34 +++++++++++++++----- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/paddle/cinn/frontend/decomposer/broadcast.cc b/paddle/cinn/frontend/decomposer/broadcast.cc index ece85caccc7da..26b494e2d6095 100644 --- a/paddle/cinn/frontend/decomposer/broadcast.cc +++ b/paddle/cinn/frontend/decomposer/broadcast.cc @@ -51,10 +51,18 @@ void GetReduceDimsForY(const std::vector& dy_shape, void elementwise_add(const Instruction& instr, const DecomposerContext& context) { - CHECK_EQ(instr->inputs.size(), 2UL) - << " 2 input tensors for " << instr->op_type; - CHECK_EQ(instr->outputs.size(), 1UL) - << "1 output tensor for " << instr->op_type; + PADDLE_ENFORCE_EQ(instr->inputs.size(), + 2UL, + platform::errors::InvalidArgument( + "The size of inputs in elementwise_add is incorrect. " + "Expected size is 2, but receive %d. ", + instr->inputs.size())); + PADDLE_ENFORCE_EQ(instr->outputs.size(), + 1UL, + platform::errors::InvalidArgument( + "The size of outputs in elementwise_add is incorrect. " + "Expected size is 1, but receive %d. ", + instr->outputs.size())); auto x = instr->inputs[0]; auto y = instr->inputs[1]; auto output = instr->outputs[0]; @@ -120,10 +128,20 @@ void elementwise_add(const Instruction& instr, void elementwise_add_grad(const Instruction& instr, const DecomposerContext& context) { - CHECK_EQ(instr->inputs.size(), 3UL) - << " 3 input tensors for " << instr->op_type; - CHECK_EQ(instr->outputs.size(), 2UL) - << "2 output tensors for " << instr->op_type; + PADDLE_ENFORCE_EQ( + instr->inputs.size(), + 3UL, + platform::errors::InvalidArgument( + "The size of inputs in elementwise_add_grad is incorrect. " + "Expected size is 3, but receive %d. ", + instr->inputs.size())); + PADDLE_ENFORCE_EQ( + instr->outputs.size(), + 2UL, + platform::errors::InvalidArgument( + "The size of outputs in elementwise_add_grad is incorrect. " + "Expected size is 2, but receive %d. ", + instr->outputs.size())); auto dout = instr->inputs[0]; auto dx = instr->outputs[0]; auto dy = instr->outputs[1]; From 4340812971b0b48cba14f5dab5a270e0447c2d4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Tue, 19 Mar 2024 19:35:50 +0800 Subject: [PATCH 2/3] Update broadcast.cc --- paddle/cinn/frontend/decomposer/broadcast.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/paddle/cinn/frontend/decomposer/broadcast.cc b/paddle/cinn/frontend/decomposer/broadcast.cc index 26b494e2d6095..5301701afbca0 100644 --- a/paddle/cinn/frontend/decomposer/broadcast.cc +++ b/paddle/cinn/frontend/decomposer/broadcast.cc @@ -14,6 +14,7 @@ #include "paddle/cinn/frontend/decomposer_registry.h" #include "paddle/cinn/frontend/syntax.h" +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { From 9465e18d5134efa18771c1349ada5c6e9ff61636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E6=98=A5=E4=B9=94?= <83450930+Liyulingyue@users.noreply.github.com> Date: Wed, 20 Mar 2024 18:36:02 +0800 Subject: [PATCH 3/3] Apply suggestions from code review --- paddle/cinn/frontend/decomposer/broadcast.cc | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/paddle/cinn/frontend/decomposer/broadcast.cc b/paddle/cinn/frontend/decomposer/broadcast.cc index 5301701afbca0..86c70bf65f1c1 100644 --- a/paddle/cinn/frontend/decomposer/broadcast.cc +++ b/paddle/cinn/frontend/decomposer/broadcast.cc @@ -54,13 +54,13 @@ void elementwise_add(const Instruction& instr, const DecomposerContext& context) { PADDLE_ENFORCE_EQ(instr->inputs.size(), 2UL, - platform::errors::InvalidArgument( + phi::errors::InvalidArgument( "The size of inputs in elementwise_add is incorrect. " "Expected size is 2, but receive %d. ", instr->inputs.size())); PADDLE_ENFORCE_EQ(instr->outputs.size(), 1UL, - platform::errors::InvalidArgument( + phi::errors::InvalidArgument( "The size of outputs in elementwise_add is incorrect. " "Expected size is 1, but receive %d. ", instr->outputs.size())); @@ -132,14 +132,14 @@ void elementwise_add_grad(const Instruction& instr, PADDLE_ENFORCE_EQ( instr->inputs.size(), 3UL, - platform::errors::InvalidArgument( + phi::errors::InvalidArgument( "The size of inputs in elementwise_add_grad is incorrect. " "Expected size is 3, but receive %d. ", instr->inputs.size())); PADDLE_ENFORCE_EQ( instr->outputs.size(), 2UL, - platform::errors::InvalidArgument( + phi::errors::InvalidArgument( "The size of outputs in elementwise_add_grad is incorrect. " "Expected size is 2, but receive %d. ", instr->outputs.size()));