From cc38216d6625f362ddf5373b78645b49a469e29c Mon Sep 17 00:00:00 2001 From: Mingdong Wang <78149749+winter-wang@users.noreply.github.com> Date: Tue, 21 May 2024 14:55:28 +0800 Subject: [PATCH 01/13] remove unuseful c_allgather op for pir autp parallel. (#64465) --- .../transforms/dist_to_dense_pass.cc | 17 +++++++++ .../auto_parallel/static/engine.py | 35 ++++++++++++++----- .../auto_parallel/static/pir_pass.py | 2 +- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/pir/dialect/distributed/transforms/dist_to_dense_pass.cc b/paddle/fluid/pir/dialect/distributed/transforms/dist_to_dense_pass.cc index 172b79317c99d..db6fc4947e5ed 100644 --- a/paddle/fluid/pir/dialect/distributed/transforms/dist_to_dense_pass.cc +++ b/paddle/fluid/pir/dialect/distributed/transforms/dist_to_dense_pass.cc @@ -122,6 +122,22 @@ void VerifyDenseBlock(pir::Block* block) { } } +void RemoveUnusefulCallgatherOp(pir::Block* block) { + std::vector del_ops; + for (auto& op : *block) { + if (op.isa()) { + auto nrank = op.attribute("nranks").data(); + if (nrank == 1) { + op.result(0).ReplaceAllUsesWith(op.operand_source(0)); + del_ops.emplace_back(&op); + } + } + } + for (auto op : del_ops) { + op->Erase(); + } +} + std::shared_ptr DistToDensePass(pir::Program* prog) { if (FLAGS_print_ir) { VLOG(0) << "IR before DistToDense Pass = " << *prog; @@ -135,6 +151,7 @@ std::shared_ptr DistToDensePass(pir::Program* prog) { ctx->GetOrRegisterDialect(); ProcessDistBlock(new_prog->block()); + RemoveUnusefulCallgatherOp(new_prog->block()); VLOG(6) << "IR before VerifyDenseBlock Pass = " << *new_prog; VerifyDenseBlock(new_prog->block()); diff --git a/python/paddle/distributed/auto_parallel/static/engine.py b/python/paddle/distributed/auto_parallel/static/engine.py index 1fa8fa20bb8de..e522a592bae33 100644 --- a/python/paddle/distributed/auto_parallel/static/engine.py +++ b/python/paddle/distributed/auto_parallel/static/engine.py @@ -28,7 +28,7 @@ from paddle.distributed import fleet from paddle.framework import ( IrGraph, - _current_expected_place as _get_device, + _current_expected_place_ as _get_device, core, in_dynamic_mode, ) @@ -714,6 +714,10 @@ def _prepare_program(self, mode, init_parameters=True): # TODO(zhiqiu): fit the processes below for pir if self._in_pir_mode: self._parallel_pir(mode) + # Init comm + self._init_comm() + # startup program + self._initialize(mode, init_parameters) self._has_prepared[mode] = True return # Do the planning process @@ -1024,22 +1028,35 @@ def _init_comm(self): for process_group in all_process_groups: process_group.instantiate() - def _init_lr(self): + def _init_lr(self, main_program): # hack to find learning_rate op lr_name = None - for op in self.main_program.global_block().ops: + for op in main_program.global_block().ops: if ( op.name() == "pd_op.data" and 'learning_rate' in op.attrs()["name"] ): lr_name = op.attrs()["name"] break + if ( + op.name() == "builtin.parameter" + and 'learning_rate' in op.attrs()["parameter_name"] + ): + lr_name = op.attrs()["parameter_name"] + break if lr_name is not None: buffer_tensor = global_scope().var(lr_name).get_tensor() - buffer_tensor.set( - np.float32(self._optimizer._learning_rate), self._place - ) + from paddle.optimizer.lr import LRScheduler + + if isinstance(self._optimizer._learning_rate, float): + buffer_tensor.set( + np.float32(self._optimizer._learning_rate), self._place + ) + elif isinstance(self._optimizer._learning_rate, LRScheduler): + buffer_tensor.set( + np.float32(self._optimizer._learning_rate()), self._place + ) def _initialize(self, mode, init_parameters=True): self._place = _get_device() @@ -1058,10 +1075,12 @@ def _initialize(self, mode, init_parameters=True): # 6. vpp init adaption self.program_helper.init_pir( - self._pir_dense_main_progs[mode], self._place + self._pir_dist_main_progs[mode], self._place ) - self._init_lr() + self._init_lr(self._pir_dense_main_progs[mode]) + if self._executor is None: + self._executor = paddle.static.Executor(self._place) return if self._strategy.seed: diff --git a/python/paddle/distributed/auto_parallel/static/pir_pass.py b/python/paddle/distributed/auto_parallel/static/pir_pass.py index 77836556c5e5f..624a8f0e88280 100644 --- a/python/paddle/distributed/auto_parallel/static/pir_pass.py +++ b/python/paddle/distributed/auto_parallel/static/pir_pass.py @@ -56,7 +56,7 @@ def reshard_combine_value(op, operand, attr): reshard_vars = [] for inner_operand, inner_attr in zip(combine_op.operands(), array_attr): reshard_vars.append(reshard_single_value(op, inner_operand, inner_attr)) - paddle.pir.set_insertion_point(combine_op) + paddle.pir.set_insertion_point(op) return paddle._C_ops.builtin_combine(reshard_vars) From 9c41fa5eef03cba92731a79fd8dbcbe1acee4682 Mon Sep 17 00:00:00 2001 From: cyberslack_lee Date: Tue, 21 May 2024 14:58:20 +0800 Subject: [PATCH 02/13] =?UTF-8?q?=E3=80=90Error=20Message=20No.18=E3=80=91?= =?UTF-8?q?=20part=203=20of=20`paddle/cinn/frontend/op=5Fmappers/*`=20-par?= =?UTF-8?q?t=20(#64409)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix part * fix * fix * fix * fix --- .../cinn/frontend/op_mappers/paddle/relu.cc | 37 +++++++++++---- .../frontend/op_mappers/paddle/reshape.cc | 47 +++++++++++++++---- .../frontend/op_mappers/paddle/reverse.cc | 12 +++-- .../cinn/frontend/op_mappers/paddle/roll.cc | 47 ++++++++++++++----- .../cinn/frontend/op_mappers/paddle/scale.cc | 17 +++++-- .../frontend/op_mappers/paddle/scatter.cc | 33 +++++++++---- .../cinn/frontend/op_mappers/paddle/slice.cc | 27 ++++++++--- .../frontend/op_mappers/paddle/softmax.cc | 12 +++-- .../frontend/op_mappers/paddle/squeeze.cc | 17 +++++-- .../op_mappers/paddle/strided_slice.cc | 37 +++++++++++---- .../op_mappers/paddle/take_along_axis.cc | 17 +++++-- .../cinn/frontend/op_mappers/paddle/tile.cc | 26 +++++++--- .../cinn/frontend/op_mappers/paddle/top_k.cc | 22 +++++++-- .../frontend/op_mappers/paddle/transpose.cc | 27 ++++++++--- .../op_mappers/paddle/triangular_solve.cc | 17 +++++-- .../cinn/frontend/op_mappers/paddle/unary.cc | 12 +++-- .../op_mappers/paddle/uniform_random.cc | 7 ++- .../frontend/op_mappers/paddle/unsqueeze.cc | 17 +++++-- 18 files changed, 329 insertions(+), 102 deletions(-) diff --git a/paddle/cinn/frontend/op_mappers/paddle/relu.cc b/paddle/cinn/frontend/op_mappers/paddle/relu.cc index 0bfc802dbef3e..4596da3c39a34 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/relu.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/relu.cc @@ -14,16 +14,22 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void ReluOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Relu op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Relu op must be 1.")); auto out_name = op_desc.Output("Out").front(); auto x = ctx.GetVar(x_name); auto out = ctx.Builder()->Relu(x); @@ -34,9 +40,15 @@ void ReluOpMapper(const paddle::cpp::OpDesc& op_desc, void Relu6OpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Relu6 op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Relu6 op must be 1.")); auto out_name = op_desc.Output("Out").front(); auto threshold = utils::GetAttrOrDefault(op_desc, "threshold", 6.0f); @@ -49,11 +61,20 @@ void Relu6OpMapper(const paddle::cpp::OpDesc& op_desc, void ReluGradOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input(paddle::GradVarName("Out")).size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input(paddle::GradVarName("Out")).size(), + 1UL, + phi::errors::InvalidArgument("The input of ReluGrad op must be 1.")); auto dout_name = op_desc.Input(paddle::GradVarName("Out")).front(); - CHECK_EQ(op_desc.Input("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Out").size(), + 1UL, + phi::errors::InvalidArgument("The input of ReluGrad op must be 1.")); auto out_name = op_desc.Input("Out").front(); - CHECK_EQ(op_desc.Output(paddle::GradVarName("X")).size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output(paddle::GradVarName("X")).size(), + 1UL, + phi::errors::InvalidArgument("The output of ReluGrad op must be 1.")); auto dx_name = op_desc.Output(paddle::GradVarName("X")).front(); auto dout = ctx.GetVar(dout_name); diff --git a/paddle/cinn/frontend/op_mappers/paddle/reshape.cc b/paddle/cinn/frontend/op_mappers/paddle/reshape.cc index f284501c71a5b..cd77944b3d7f1 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/reshape.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/reshape.cc @@ -15,14 +15,17 @@ #include "paddle/cinn/backends/cuda_util.h" #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void ReshapeOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Reshape op must be 1.")); auto x_name = op_desc.Input("X").front(); auto x = ctx.GetVar(x_name); @@ -33,7 +36,10 @@ void ReshapeOpMapper(const paddle::cpp::OpDesc& op_desc, auto out = ctx.Builder()->Reshape(x, shape); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Reshape op must be 1.")); auto out_name = op_desc.Output("Out").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); @@ -42,13 +48,19 @@ void ReshapeOpMapper(const paddle::cpp::OpDesc& op_desc, void ReshapeGradOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { auto get_input_var = [&op_desc, &ctx](const std::string& op_name) { - CHECK_EQ(op_desc.Input(op_name).size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input(op_name).size(), + 1UL, + phi::errors::InvalidArgument("The input of ReshapeGrad op must be 1.")); auto var_name = op_desc.Input(op_name).front(); return ctx.GetVar(var_name); }; auto get_output_name = [&op_desc](const std::string& op_name) { - CHECK_EQ(op_desc.Output(op_name).size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Output(op_name).size(), + 1UL, + phi::errors::InvalidArgument( + "The output of ReshapeGrad op must be 1.")); return op_desc.Output(op_name).front(); }; @@ -67,7 +79,10 @@ void ReshapeGradOpMapper(const paddle::cpp::OpDesc& op_desc, void Reshape2OpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Reshape2 op must be 1.")); auto x_name = op_desc.Input("X").front(); auto x = ctx.GetVar(x_name); @@ -78,7 +93,10 @@ void Reshape2OpMapper(const paddle::cpp::OpDesc& op_desc, auto out = ctx.Builder()->Reshape(x, shape); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Reshape2 op must be 1.")); auto out_name = op_desc.Output("Out").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); @@ -89,7 +107,10 @@ void Reshape2OpMapper(const paddle::cpp::OpDesc& op_desc, // will be used in Reshape_grad, in this way, the framework can reuse // the memory of X immediately the Reshape2_op is finished. // Considering compatibility issues, we could not fix Reshape2_op - CHECK_EQ(op_desc.Output("XShape").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("XShape").size(), + 1UL, + phi::errors::InvalidArgument("The output of Reshape2 op must be 1.")); auto xshape_name = op_desc.Output("XShape").front(); auto xshape = ctx.Builder()->Identity(x); @@ -102,13 +123,19 @@ void Reshape2OpMapper(const paddle::cpp::OpDesc& op_desc, void Reshape2GradOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { auto get_input_var = [&op_desc, &ctx](const std::string& op_name) { - CHECK_EQ(op_desc.Input(op_name).size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Input(op_name).size(), + 1UL, + phi::errors::InvalidArgument( + "The input of Reshape2Grad op must be 1.")); auto var_name = op_desc.Input(op_name).front(); return ctx.GetVar(var_name); }; auto get_output_name = [&op_desc](const std::string& op_name) { - CHECK_EQ(op_desc.Output(op_name).size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Output(op_name).size(), + 1UL, + phi::errors::InvalidArgument( + "The output of Reshape2Grad op must be 1.")); return op_desc.Output(op_name).front(); }; diff --git a/paddle/cinn/frontend/op_mappers/paddle/reverse.cc b/paddle/cinn/frontend/op_mappers/paddle/reverse.cc index 17418263ae0c5..883040fd101fc 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/reverse.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/reverse.cc @@ -14,16 +14,22 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void ReverseOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Reverse op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Reverse op must be 1.")); auto out_name = op_desc.Output("Out").front(); auto axes = utils::GetAttrOrDefault>( diff --git a/paddle/cinn/frontend/op_mappers/paddle/roll.cc b/paddle/cinn/frontend/op_mappers/paddle/roll.cc index 9b268c2856888..918ffe67e15cd 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/roll.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/roll.cc @@ -15,7 +15,7 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/frontend/var_type_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { @@ -23,15 +23,27 @@ namespace paddle_mappers { void RollOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { // input - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Roll op must be 1.")); auto x_name = op_desc.Input("X").front(); // output - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Roll op must be 1.")); auto out_name = op_desc.Output("Out").front(); // attr shifts and axis - CHECK(op_desc.HasAttr("shifts")); - CHECK(op_desc.HasAttr("axis")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("shifts"), + true, + phi::errors::InvalidArgument("Roll op must have shifts attribute")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("axis"), + true, + phi::errors::InvalidArgument("Roll op must have axis attribute")); std::vector shifts = utils::ToShapeType( utils::GetAttrOrDefault>(op_desc, "shifts", {1})); std::vector axis = utils::ToShapeType( @@ -44,8 +56,11 @@ void RollOpMapper(const paddle::cpp::OpDesc& op_desc, // check axis and shifts and when axis is None, we should flatten x. bool axis_None = false; if (axis.size() == 0) { - CHECK_EQ(shifts.size(), 1) - << "shifts.size() should be equal to 1 when axis is None"; + PADDLE_ENFORCE_EQ( + shifts.size(), + 1UL, + phi::errors::InvalidArgument( + "shifts.size() should be equal to 1 when axis is None")); axis.push_back(0); axis_None = true; int reshape_num = 1; @@ -55,8 +70,10 @@ void RollOpMapper(const paddle::cpp::OpDesc& op_desc, vec_x_dims = std::vector{reshape_num}; x = ctx.Builder()->Reshape(x, vec_x_dims); } else { - CHECK_EQ(shifts.size(), axis.size()) - << "shifts.size() should be equal to axis.size()"; + PADDLE_ENFORCE_EQ(shifts.size(), + axis.size(), + phi::errors::InvalidArgument( + "shifts.size() should be equal to axis.size()")); } // preprocessing the shifts and axis @@ -64,10 +81,14 @@ void RollOpMapper(const paddle::cpp::OpDesc& op_desc, std::unordered_map axis_to_shifts; for (int i = 0; i < shifts_size; ++i) { int vec_x_dims_size = vec_x_dims.size(); - CHECK_GE(axis[i], -vec_x_dims_size) - << "axis value should be >= " << -vec_x_dims_size; - CHECK_LT(axis[i], vec_x_dims_size) - << "axis value should be < " << vec_x_dims_size; + PADDLE_ENFORCE_GE(axis[i], + -vec_x_dims_size, + phi::errors::InvalidArgument( + "axis value should be >= -vec_x_dims_size")); + PADDLE_ENFORCE_LT( + axis[i], + vec_x_dims_size, + phi::errors::InvalidArgument("axis value should be < vec_x_dims_size")); if (axis[i] < 0) { axis[i] += vec_x_dims_size; } diff --git a/paddle/cinn/frontend/op_mappers/paddle/scale.cc b/paddle/cinn/frontend/op_mappers/paddle/scale.cc index 639af845edefe..06483956e6d97 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/scale.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/scale.cc @@ -17,16 +17,22 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/utils/string.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void ScaleOpMapper(const paddle::cpp::OpDesc& op_desc, const cinn::frontend::OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Scale op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Scale op must be 1.")); auto out_name = op_desc.Output("Out").front(); auto bias = utils::GetAttrOrDefault(op_desc, "bias", 0.0f); @@ -38,7 +44,10 @@ void ScaleOpMapper(const paddle::cpp::OpDesc& op_desc, absl::optional out; if (op_desc.HasInput("ScaleTensor") && !op_desc.Input("ScaleTensor").empty()) { - CHECK_EQ(op_desc.Input("ScaleTensor").size(), 1); + PADDLE_ENFORCE_EQ( + op_desc.Input("ScaleTensor").size(), + 1UL, + phi::errors::InvalidArgument("The input of ScaleTensor must be 1.")); auto scale_name = op_desc.Input("ScaleTensor").front(); auto scale_tensor = ctx.GetVar(scale_name); diff --git a/paddle/cinn/frontend/op_mappers/paddle/scatter.cc b/paddle/cinn/frontend/op_mappers/paddle/scatter.cc index 8be9b563b4cd1..e8bdbb3a1bd5c 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/scatter.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/scatter.cc @@ -15,20 +15,32 @@ #include "paddle/cinn/common/type.h" #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void ScatterOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Scatter op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Input("Ids").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Ids").size(), + 1UL, + phi::errors::InvalidArgument("The input of Scatter op must be 1.")); auto ids_name = op_desc.Input("Ids").front(); - CHECK_EQ(op_desc.Input("Updates").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Updates").size(), + 1UL, + phi::errors::InvalidArgument("The input of Scatter op must be 1.")); auto updates_name = op_desc.Input("Updates").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Scatter op must be 1.")); auto out_name = op_desc.Output("Out").front(); bool overwrite = utils::GetAttrOrDefault(op_desc, "overwrite", true); @@ -38,8 +50,10 @@ void ScatterOpMapper(const paddle::cpp::OpDesc& op_desc, const auto& input = ctx.GetVar(x_name); auto indices = ctx.GetVar(ids_name); const auto& updates = ctx.GetVar(updates_name); - CHECK(input->type == updates->type) - << "checks whether the type of the input and the updates are the same."; + PADDLE_ENFORCE_EQ(input->type == updates->type, + true, + phi::errors::InvalidArgument( + "The type of input and updates should be the same.")); CHECK(indices->type == cinn::common::Int(32) || indices->type == cinn::common::Int(64)) << "checks whether the data type of the indices is either int32 or int64"; @@ -47,7 +61,10 @@ void ScatterOpMapper(const paddle::cpp::OpDesc& op_desc, indices = ctx.Builder()->Cast( indices, cinn::common::Type2Str(cinn::common::Int(32))); } - CHECK_LE(indices->shape.size(), 2) << "Ids should be 0, 1 or 2 in scatter_op"; + PADDLE_ENFORCE_LE(indices->shape.size(), + 2UL, + phi::errors::InvalidArgument( + "The rank of indices should be less than 2.")); if (indices->shape.size() == 0) { indices = ctx.Builder()->Reshape(indices, {1}); } diff --git a/paddle/cinn/frontend/op_mappers/paddle/slice.cc b/paddle/cinn/frontend/op_mappers/paddle/slice.cc index 6b62ec72410e6..6e5b3cac8c722 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/slice.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/slice.cc @@ -14,23 +14,38 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void SliceOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("Input").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Input").size(), + 1UL, + phi::errors::InvalidArgument("The input of Slice op must be 1.")); auto x_name = op_desc.Input("Input").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Slice op must be 1.")); auto out_name = op_desc.Output("Out").front(); - CHECK(op_desc.HasAttr("starts")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("starts"), + true, + phi::errors::InvalidArgument("Slice op must have starts attribute")); auto starts = utils::GetAttrOrDefault>(op_desc, "starts"); - CHECK(op_desc.HasAttr("ends")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("ends"), + true, + phi::errors::InvalidArgument("Slice op must have ends attribute")); auto ends = utils::GetAttrOrDefault>(op_desc, "ends"); - CHECK(op_desc.HasAttr("axes")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("axes"), + true, + phi::errors::InvalidArgument("Slice op must have axes attribute")); auto axes = utils::GetAttrOrDefault>(op_desc, "axes"); auto infer_flags = diff --git a/paddle/cinn/frontend/op_mappers/paddle/softmax.cc b/paddle/cinn/frontend/op_mappers/paddle/softmax.cc index 654c21c56c0b4..2e1959f8a1aa5 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/softmax.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/softmax.cc @@ -14,16 +14,22 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void SoftmaxOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Softmax op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Softmax op must be 1.")); auto out_name = op_desc.Output("Out").front(); auto axis = utils::GetAttrOrDefault(op_desc, "axis", -1); diff --git a/paddle/cinn/frontend/op_mappers/paddle/squeeze.cc b/paddle/cinn/frontend/op_mappers/paddle/squeeze.cc index ee7606675bad4..732488ffee224 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/squeeze.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/squeeze.cc @@ -14,14 +14,17 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void Squeeze2OpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Squeeze2 op must be 1.")); auto x_name = op_desc.Input("X").front(); auto x = ctx.GetVar(x_name); @@ -32,7 +35,10 @@ void Squeeze2OpMapper(const paddle::cpp::OpDesc& op_desc, auto out = ctx.Builder()->Squeeze(x, axes); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Squeeze2 op must be 1.")); auto out_name = op_desc.Output("Out").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); @@ -43,7 +49,10 @@ void Squeeze2OpMapper(const paddle::cpp::OpDesc& op_desc, // squeeze_grad, in this way, the framework can reuse the memory of X // immediately the squeeze2_op is finished. // Considering compatibility issues, we could not fix squeeze2_op - CHECK_EQ(op_desc.Output("XShape").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("XShape").size(), + 1UL, + phi::errors::InvalidArgument("The output of Squeeze2 op must be 1.")); auto xshape_name = op_desc.Output("XShape").front(); auto xshape = ctx.Builder()->Identity(x); diff --git a/paddle/cinn/frontend/op_mappers/paddle/strided_slice.cc b/paddle/cinn/frontend/op_mappers/paddle/strided_slice.cc index 8a0a5765de555..befd29bebe478 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/strided_slice.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/strided_slice.cc @@ -15,31 +15,52 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/frontend/var_type_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void StridedSliceOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("Input").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Input").size(), + 1UL, + phi::errors::InvalidArgument("The input of StridedSlice op must be 1.")); auto x_name = op_desc.Input("Input").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of StridedSlice op must be 1.")); auto out_name = op_desc.Output("Out").front(); - CHECK(op_desc.HasAttr("starts")); + PADDLE_ENFORCE_EQ(op_desc.HasAttr("starts"), + true, + phi::errors::InvalidArgument( + "StridedSlice op must have starts attribute")); auto starts = utils::ToShapeType( utils::GetAttrOrDefault>(op_desc, "starts")); - CHECK(op_desc.HasAttr("ends")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("ends"), + true, + phi::errors::InvalidArgument("StridedSlice op must have ends attribute")); auto ends = utils::ToShapeType( utils::GetAttrOrDefault>(op_desc, "ends")); - CHECK(op_desc.HasAttr("axes")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("axes"), + true, + phi::errors::InvalidArgument("StridedSlice op must have axes attribute")); auto axes = utils::ToShapeType( utils::GetAttrOrDefault>(op_desc, "axes")); - CHECK(op_desc.HasAttr("strides")); + PADDLE_ENFORCE_EQ(op_desc.HasAttr("strides"), + true, + phi::errors::InvalidArgument( + "StridedSlice op must have strides attribute")); auto strides = utils::ToShapeType( utils::GetAttrOrDefault>(op_desc, "strides")); - CHECK(op_desc.HasAttr("infer_flags")); + PADDLE_ENFORCE_EQ(op_desc.HasAttr("infer_flags"), + true, + phi::errors::InvalidArgument( + "StridedSlice op must have infer_flags attribute")); auto infer_flags = utils::ToShapeType( utils::GetAttrOrDefault>(op_desc, "infer_flags")); auto decrease_axis = utils::ToShapeType( diff --git a/paddle/cinn/frontend/op_mappers/paddle/take_along_axis.cc b/paddle/cinn/frontend/op_mappers/paddle/take_along_axis.cc index deec9a0ee9c41..5d91cd2d45700 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/take_along_axis.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/take_along_axis.cc @@ -15,17 +15,23 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/frontend/syntax.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void TakeAlongAxis2OpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("Input").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Input").size(), + 1UL, + phi::errors::InvalidArgument("The input of TakeAlongAxis op must be 1.")); auto x_name = op_desc.Input("Input").front(); auto x = ctx.GetVar(x_name); - CHECK_EQ(op_desc.Input("Index").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("Index").size(), + 1UL, + phi::errors::InvalidArgument("The input of TakeAlongAxis op must be 1.")); auto index_name = op_desc.Input("Index").front(); auto index = ctx.GetVar(index_name); @@ -37,7 +43,10 @@ void TakeAlongAxis2OpMapper(const paddle::cpp::OpDesc& op_desc, auto out = ctx.Builder()->Gather(x, index, axis); - CHECK_EQ(op_desc.Output("Result").size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Output("Result").size(), + 1UL, + phi::errors::InvalidArgument( + "The output of TakeAlongAxis op must be 1.")); auto out_name = op_desc.Output("Result").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); diff --git a/paddle/cinn/frontend/op_mappers/paddle/tile.cc b/paddle/cinn/frontend/op_mappers/paddle/tile.cc index 3ce331dc4a209..5d8b0afd5658c 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/tile.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/tile.cc @@ -15,7 +15,7 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/frontend/var_type_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { @@ -23,10 +23,16 @@ namespace paddle_mappers { void TileOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { // input - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Tile op must be 1.")); auto x_name = op_desc.Input("X").front(); // output - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Tile op must be 1.")); auto out_name = op_desc.Output("Out").front(); // attr repeat_times @@ -34,7 +40,10 @@ void TileOpMapper(const paddle::cpp::OpDesc& op_desc, op_desc.GetAttr>("repeat_times"); for (auto i : repeat_times) { - CHECK_GT(i, 0) << "repeat_times's element must be greater than 0"; + PADDLE_ENFORCE_GT(i, + 0, + phi::errors::InvalidArgument( + "repeat_times's element must be greater than 0")); } auto x = ctx.GetVar(x_name); @@ -49,9 +58,12 @@ void TileOpMapper(const paddle::cpp::OpDesc& op_desc, vec_x_dims.insert(vec_x_dims.begin(), diff, 1); } - CHECK_EQ(vec_x_dims.size(), repeat_times.size()) - << "vec_x_dims's size must be equal to repeat_times's size after " - "promotion"; + PADDLE_ENFORCE_EQ( + vec_x_dims.size(), + repeat_times.size(), + phi::errors::InvalidArgument( + "vec_x_dims's size must be equal to repeat_times's size " + "after promotion")); // output's shape std::vector output_shape = vec_x_dims; diff --git a/paddle/cinn/frontend/op_mappers/paddle/top_k.cc b/paddle/cinn/frontend/op_mappers/paddle/top_k.cc index 07ab1c12b8802..dfe869cbf21bf 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/top_k.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/top_k.cc @@ -14,22 +14,34 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void TopKOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of TopK op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of TopK op must be 1.")); auto out_name = op_desc.Output("Out").front(); - CHECK_EQ(op_desc.Output("Indices").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Indices").size(), + 1UL, + phi::errors::InvalidArgument("The output of TopK op must be 1.")); auto indices_name = op_desc.Output("Indices").front(); auto x = ctx.GetVar(x_name); - CHECK(op_desc.HasAttr("k")); + PADDLE_ENFORCE_EQ( + op_desc.HasAttr("k"), + true, + phi::errors::InvalidArgument("TopK op must have k attribute")); auto k = utils::GetAttrOrDefault(op_desc, "k"); auto outs = ctx.Builder()->TopK(x, k, -1, true); diff --git a/paddle/cinn/frontend/op_mappers/paddle/transpose.cc b/paddle/cinn/frontend/op_mappers/paddle/transpose.cc index e835a930ad641..09102427edcc2 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/transpose.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/transpose.cc @@ -15,14 +15,17 @@ #include "paddle/cinn/backends/cuda_util.h" #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void TransposeOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Transpose op must be 1.")); auto x_name = op_desc.Input("X").front(); auto x = ctx.GetVar(x_name); @@ -33,7 +36,10 @@ void TransposeOpMapper(const paddle::cpp::OpDesc& op_desc, auto out = ctx.Builder()->Transpose(x, axis); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Transpose op must be 1.")); auto out_name = op_desc.Output("Out").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); @@ -41,7 +47,10 @@ void TransposeOpMapper(const paddle::cpp::OpDesc& op_desc, void Transpose2OpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of Transpose2 op must be 1.")); auto x_name = op_desc.Input("X").front(); auto x = ctx.GetVar(x_name); @@ -52,7 +61,10 @@ void Transpose2OpMapper(const paddle::cpp::OpDesc& op_desc, auto out = ctx.Builder()->Transpose(x, axis); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of Transpose2 op must be 1.")); auto out_name = op_desc.Output("Out").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); @@ -63,7 +75,10 @@ void Transpose2OpMapper(const paddle::cpp::OpDesc& op_desc, // will be used in transpose_grad, in this way, the framework can reuse // the memory of X immediately the transpose2_op is finished. // Considering compatibility issues, we could not fix transpose2_op - CHECK_EQ(op_desc.Output("XShape").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("XShape").size(), + 1UL, + phi::errors::InvalidArgument("The output of Transpose2 op must be 1.")); auto xshape_name = op_desc.Output("XShape").front(); auto xshape = ctx.Builder()->Identity(x); diff --git a/paddle/cinn/frontend/op_mappers/paddle/triangular_solve.cc b/paddle/cinn/frontend/op_mappers/paddle/triangular_solve.cc index 756a335d604dc..c4c62955c3de4 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/triangular_solve.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/triangular_solve.cc @@ -14,18 +14,27 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void TriangularSolveOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument( + "The input of TriangularSolve op must be 1.")); auto x_name = op_desc.Input("X").front(); - CHECK_EQ(op_desc.Input("Y").size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Input("Y").size(), + 1UL, + phi::errors::InvalidArgument( + "The input of TriangularSolve op must be 1.")); auto y_name = op_desc.Input("Y").front(); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument( + "The output of TriangularSolve op must be 1.")); auto out_name = op_desc.Output("Out").front(); constexpr bool left_side = true; diff --git a/paddle/cinn/frontend/op_mappers/paddle/unary.cc b/paddle/cinn/frontend/op_mappers/paddle/unary.cc index 575b2d04eb188..b13f548cac29c 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/unary.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/unary.cc @@ -14,7 +14,7 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { @@ -22,9 +22,15 @@ namespace paddle_mappers { #define UNARY_OPMAPPER_FUNCTION(OP_NAME) \ void OP_NAME##OpMapper(const paddle::cpp::OpDesc& op_desc, \ const OpMapperContext& ctx) { \ - CHECK_EQ(op_desc.Input("X").size(), 1UL); \ + PADDLE_ENFORCE_EQ( \ + op_desc.Input("X").size(), \ + 1UL, \ + phi::errors::InvalidArgument("The input of x op must be 1.")); \ auto x_name = op_desc.Input("X").front(); \ - CHECK_EQ(op_desc.Output("Out").size(), 1UL); \ + PADDLE_ENFORCE_EQ( \ + op_desc.Output("Out").size(), \ + 1UL, \ + phi::errors::InvalidArgument("The output of x op must be 1.")); \ auto out_name = op_desc.Output("Out").front(); \ auto x = ctx.GetVar(x_name); \ VLOG(4) << #OP_NAME << " X:" << x_name << "[" \ diff --git a/paddle/cinn/frontend/op_mappers/paddle/uniform_random.cc b/paddle/cinn/frontend/op_mappers/paddle/uniform_random.cc index c477072c9877f..c5a5b69c1fe66 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/uniform_random.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/uniform_random.cc @@ -15,14 +15,17 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/frontend/var_type_utils.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void UniformRandomOpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ(op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument( + "The output of uniform_random op must be 1.")); auto out_name = op_desc.Output("Out").front(); auto shape_origin = diff --git a/paddle/cinn/frontend/op_mappers/paddle/unsqueeze.cc b/paddle/cinn/frontend/op_mappers/paddle/unsqueeze.cc index 80ad42c3dd3cd..c7175df8d63a1 100644 --- a/paddle/cinn/frontend/op_mappers/paddle/unsqueeze.cc +++ b/paddle/cinn/frontend/op_mappers/paddle/unsqueeze.cc @@ -15,14 +15,17 @@ #include "paddle/cinn/frontend/op_mapper_registry.h" #include "paddle/cinn/frontend/op_mappers/common_utils.h" #include "paddle/cinn/frontend/syntax.h" - +#include "paddle/common/enforce.h" namespace cinn { namespace frontend { namespace paddle_mappers { void UnSqueeze2OpMapper(const paddle::cpp::OpDesc& op_desc, const OpMapperContext& ctx) { - CHECK_EQ(op_desc.Input("X").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Input("X").size(), + 1UL, + phi::errors::InvalidArgument("The input of UnSqueeze2 op must be 1.")); auto x_name = op_desc.Input("X").front(); auto x = ctx.GetVar(x_name); @@ -33,7 +36,10 @@ void UnSqueeze2OpMapper(const paddle::cpp::OpDesc& op_desc, const auto& out = ctx.Builder()->ExpandDims(x, axes); - CHECK_EQ(op_desc.Output("Out").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("Out").size(), + 1UL, + phi::errors::InvalidArgument("The output of UnSqueeze2 op must be 1.")); auto out_name = op_desc.Output("Out").front(); ctx.AddVar(out_name, out); ctx.AddVarModelToProgram(out_name, out->id); @@ -44,7 +50,10 @@ void UnSqueeze2OpMapper(const paddle::cpp::OpDesc& op_desc, // squeeze_grad, in this way, the framework can reuse the memory of X // immediately the squeeze2_op is finished. // Considering compatibility issues, we could not fix squeeze2_op - CHECK_EQ(op_desc.Output("XShape").size(), 1UL); + PADDLE_ENFORCE_EQ( + op_desc.Output("XShape").size(), + 1UL, + phi::errors::InvalidArgument("The output of UnSqueeze2 op must be 1.")); auto xshape_name = op_desc.Output("XShape").front(); auto xshape = ctx.Builder()->Identity(x); From b9c7c6b040bc0a0982139acadade29903e41bb99 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Tue, 21 May 2024 15:14:08 +0800 Subject: [PATCH 03/13] fix pir api 8 (#64457) --- .../legacy_test/test_cholesky_solve_op.py | 289 ------------------ 1 file changed, 289 deletions(-) delete mode 100644 test/deprecated/legacy_test/test_cholesky_solve_op.py diff --git a/test/deprecated/legacy_test/test_cholesky_solve_op.py b/test/deprecated/legacy_test/test_cholesky_solve_op.py deleted file mode 100644 index 914a6de628120..0000000000000 --- a/test/deprecated/legacy_test/test_cholesky_solve_op.py +++ /dev/null @@ -1,289 +0,0 @@ -# Copyright (c) 2021 PaddlePaddle Authors. All Rights Reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License.w - -import sys -import unittest - -import numpy as np -import scipy -import scipy.linalg - -sys.path.append("..") -from op_test import OpTest - -import paddle -from paddle import base -from paddle.base import Program, core, program_guard -from paddle.pir_utils import test_with_pir_api - -paddle.enable_static() - - -# cholesky_solve implement 1 -def cholesky_solution(X, B, upper=True): - if upper: - A = np.triu(X) - L = A.T - U = A - else: - A = np.tril(X) - L = A - U = A.T - return scipy.linalg.solve_triangular( - U, scipy.linalg.solve_triangular(L, B, lower=True) - ) - - -# cholesky_solve implement 2 -def scipy_cholesky_solution(X, B, upper=True): - if upper: - umat = np.triu(X) - A = umat.T @ umat - else: - umat = np.tril(X) - A = umat @ umat.T - K = scipy.linalg.cho_factor(A) - return scipy.linalg.cho_solve(K, B) - - -# broadcast function used by cholesky_solve -def broadcast_shape(matA, matB): - shapeA = matA.shape - shapeB = matB.shape - Broadshape = [] - for idx in range(len(shapeA) - 2): - if shapeA[idx] == shapeB[idx]: - Broadshape.append(shapeA[idx]) - continue - elif shapeA[idx] == 1 or shapeB[idx] == 1: - Broadshape.append(max(shapeA[idx], shapeB[idx])) - else: - raise Exception( - f'shapeA and shapeB should be broadcasted, but got {shapeA} and {shapeB}' - ) - bsA = Broadshape + list(shapeA[-2:]) - bsB = Broadshape + list(shapeB[-2:]) - return np.broadcast_to(matA, bsA), np.broadcast_to(matB, bsB) - - -# cholesky_solve implement in batch -def scipy_cholesky_solution_batch(bumat, bB, upper=True): - bumat, bB = broadcast_shape(bumat, bB) - ushape = bumat.shape - bshape = bB.shape - bumat = bumat.reshape((-1, ushape[-2], ushape[-1])) - bB = bB.reshape((-1, bshape[-2], bshape[-1])) - batch = 1 - for d in ushape[:-2]: - batch *= d - bx = [] - for b in range(batch): - # x = scipy_cholesky_solution(bumat[b], bB[b], upper) #large matrix result error - x = cholesky_solution(bumat[b], bB[b], upper) - bx.append(x) - return np.array(bx).reshape(bshape) - - -# test condition: shape: 2D + 2D , upper=False -# based on OpTest class -class TestCholeskySolveOp(OpTest): - """ - case 1 - """ - - # test condition set - def config(self): - self.y_shape = [15, 15] - self.x_shape = [15, 5] - self.upper = False - self.dtype = ( - np.float64 - ) # Here cholesky_solve Op only supports float64/float32 type, please check others if Op supports more types. - - # get scipy result - def set_output(self): - umat = self.inputs['Y'] - self.output = scipy_cholesky_solution_batch( - umat, self.inputs['X'], upper=self.upper - ) - - def setUp(self): - self.op_type = "cholesky_solve" - self.python_api = paddle.tensor.cholesky_solve - self.config() - - if self.upper: - umat = np.triu(np.random.random(self.y_shape).astype(self.dtype)) - else: - umat = np.tril(np.random.random(self.y_shape).astype(self.dtype)) - - self.inputs = { - 'X': np.random.random(self.x_shape).astype(self.dtype), - 'Y': umat, - } - self.attrs = {'upper': self.upper} - self.set_output() - self.outputs = {'Out': self.output} - - # check Op forward result - def test_check_output(self): - self.check_output(check_pir=True) - - # check Op grad - def test_check_grad_normal(self): - self.check_grad(['Y'], 'Out', max_relative_error=0.01, check_pir=True) - - -# test condition: 3D(broadcast) + 3D, upper=True -class TestCholeskySolveOp3(TestCholeskySolveOp): - """ - case 3 - """ - - def config(self): - self.y_shape = [1, 10, 10] - self.x_shape = [2, 10, 5] - self.upper = True - self.dtype = np.float64 - - -# API function test -class TestCholeskySolveAPI(unittest.TestCase): - def setUp(self): - np.random.seed(2021) - self.place = [paddle.CPUPlace()] - self.dtype = "float64" - self.upper = True - if core.is_compiled_with_cuda(): - self.place.append(paddle.CUDAPlace(0)) - - @test_with_pir_api - def check_static_result(self, place): - paddle.enable_static() - with paddle.static.program_guard( - paddle.static.Program(), paddle.static.Program() - ): - x = paddle.static.data(name="x", shape=[10, 2], dtype=self.dtype) - y = paddle.static.data(name="y", shape=[10, 10], dtype=self.dtype) - z = paddle.linalg.cholesky_solve(x, y, upper=self.upper) - - x_np = np.random.random([10, 2]).astype(self.dtype) - y_np = np.random.random([10, 10]).astype(self.dtype) - if self.upper: - umat = np.triu(y_np) - else: - umat = np.tril(y_np) - z_np = cholesky_solution(umat, x_np, upper=self.upper) - z2_np = scipy_cholesky_solution(umat, x_np, upper=self.upper) - - exe = base.Executor(place) - fetches = exe.run( - feed={"x": x_np, "y": umat}, - fetch_list=[z], - ) - np.testing.assert_allclose(fetches[0], z_np, rtol=1e-05) - - # test in static graph mode - def test_static(self): - for place in self.place: - self.check_static_result(place=place) - - # test in dynamic mode - def test_dygraph(self): - def run(place): - paddle.disable_static(place) - x_np = np.random.random([20, 2]).astype(self.dtype) - y_np = np.random.random([20, 20]).astype(self.dtype) - z_np = scipy_cholesky_solution(y_np, x_np, upper=self.upper) - - x = paddle.to_tensor(x_np) - y = paddle.to_tensor(y_np) - z = paddle.linalg.cholesky_solve(x, y, upper=self.upper) - - np.testing.assert_allclose(z_np, z.numpy(), rtol=1e-05) - self.assertEqual(z_np.shape, z.numpy().shape) - paddle.enable_static() - - for idx, place in enumerate(self.place): - run(place) - - # test input with broadcast - def test_broadcast(self): - def run(place): - paddle.disable_static() - x_np = np.random.random([1, 30, 2]).astype(self.dtype) - y_np = np.random.random([2, 30, 30]).astype(self.dtype) - nx_np = np.concatenate((x_np, x_np), axis=0) - - z_sci = scipy_cholesky_solution_batch(y_np, nx_np, upper=self.upper) - - x = paddle.to_tensor(x_np) - y = paddle.to_tensor(y_np) - z = paddle.linalg.cholesky_solve(x, y, upper=self.upper) - self.assertEqual(z_sci.shape, z.numpy().shape) - np.testing.assert_allclose(z_sci, z.numpy(), rtol=1e-05) - - for idx, place in enumerate(self.place): - run(place) - - -# test condition out of bounds -class TestCholeskySolveOpError(unittest.TestCase): - def test_errors_1(self): - paddle.enable_static() - with program_guard(Program(), Program()): - # The input type of solve_op must be Variable. - x1 = base.create_lod_tensor( - np.array([[-1]]), [[1]], base.CPUPlace() - ) - y1 = base.create_lod_tensor( - np.array([[-1]]), [[1]], base.CPUPlace() - ) - self.assertRaises(TypeError, paddle.linalg.cholesky_solve, x1, y1) - - @test_with_pir_api - def test_errors_2(self): - paddle.enable_static() - with program_guard(Program(), Program()): - # The data type of input must be float32 or float64. - x2 = paddle.static.data(name="x2", shape=[30, 30], dtype="bool") - y2 = paddle.static.data(name="y2", shape=[30, 10], dtype="bool") - self.assertRaises(TypeError, paddle.linalg.cholesky_solve, x2, y2) - - x3 = paddle.static.data(name="x3", shape=[30, 30], dtype="int32") - y3 = paddle.static.data(name="y3", shape=[30, 10], dtype="int32") - self.assertRaises(TypeError, paddle.linalg.cholesky_solve, x3, y3) - - x4 = paddle.static.data(name="x4", shape=[30, 30], dtype="float16") - y4 = paddle.static.data(name="y4", shape=[30, 10], dtype="float16") - self.assertRaises(TypeError, paddle.linalg.cholesky_solve, x4, y4) - - # The number of dimensions of input'X must be >= 2. - x5 = paddle.static.data(name="x5", shape=[30], dtype="float64") - y5 = paddle.static.data(name="y5", shape=[30, 30], dtype="float64") - self.assertRaises(ValueError, paddle.linalg.cholesky_solve, x5, y5) - - # The number of dimensions of input'Y must be >= 2. - x6 = paddle.static.data(name="x6", shape=[30, 30], dtype="float64") - y6 = paddle.static.data(name="y6", shape=[30], dtype="float64") - self.assertRaises(ValueError, paddle.linalg.cholesky_solve, x6, y6) - - # The inner-most 2 dimensions of input'X should be equal to each other - x7 = paddle.static.data(name="x7", shape=[2, 3, 4], dtype="float64") - y7 = paddle.static.data(name="y7", shape=[2, 4, 3], dtype="float64") - self.assertRaises(ValueError, paddle.linalg.cholesky_solve, x7, y7) - - -if __name__ == "__main__": - unittest.main() From e2c9020276f031648b609c11e564e1ae7d8e0e04 Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Tue, 21 May 2024 15:45:57 +0800 Subject: [PATCH 04/13] fix pir api 6 (#64454) --- python/paddle/base/layer_helper.py | 3 ++- test/deprecated/legacy_test/CMakeLists.txt | 8 +++++--- ...est_conv2d_api.py => test_conv2d_api_deprecated.py} | 0 ...test_dist_fleet_a_sync_optimizer_geo_deprecated.py} | 0 ...program.py => test_eager_run_program_deprecated.py} | 0 ...ader.py => test_generator_dataloader_deprecated.py} | 0 tools/gpups_test.sh | 2 +- tools/parallel_UT_rule.py | 10 +++++----- tools/static_mode_white_list.py | 2 +- tools/test_run_by_protobuf_3.py | 2 +- tools/windows/run_unittests.sh | 8 ++++---- 11 files changed, 19 insertions(+), 16 deletions(-) rename test/deprecated/legacy_test/{test_conv2d_api.py => test_conv2d_api_deprecated.py} (100%) rename test/deprecated/legacy_test/{test_dist_fleet_a_sync_optimizer_geo.py => test_dist_fleet_a_sync_optimizer_geo_deprecated.py} (100%) rename test/deprecated/legacy_test/{test_eager_run_program.py => test_eager_run_program_deprecated.py} (100%) rename test/deprecated/legacy_test/{test_generator_dataloader.py => test_generator_dataloader_deprecated.py} (100%) diff --git a/python/paddle/base/layer_helper.py b/python/paddle/base/layer_helper.py index 00a7a4b729a58..c31a0e1d0aa9d 100644 --- a/python/paddle/base/layer_helper.py +++ b/python/paddle/base/layer_helper.py @@ -172,8 +172,9 @@ def _append_activation_in_pir(input, act=None, use_cudnn=None): attrs = () if use_cudnn: attrs = ('use_cudnn', use_cudnn) - act_op = getattr(_C_ops, act) + if act == 'softmax': + return act_op(input, -1) return act_op(input, *attrs) return _append_activation_in_pir(input_var, act_type, use_cudnn) diff --git a/test/deprecated/legacy_test/CMakeLists.txt b/test/deprecated/legacy_test/CMakeLists.txt index 4d6d49fd51f33..7ff456d1feb47 100644 --- a/test/deprecated/legacy_test/CMakeLists.txt +++ b/test/deprecated/legacy_test/CMakeLists.txt @@ -514,7 +514,8 @@ endif() set_tests_properties(test_conv2d_op_depthwise_conv PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") -set_tests_properties(test_conv2d_api PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") +set_tests_properties(test_conv2d_api_deprecated PROPERTIES LABELS + "RUN_TYPE=EXCLUSIVE") set_tests_properties(test_conv_nn_grad PROPERTIES LABELS "RUN_TYPE=EXCLUSIVE") if(WITH_DISTRIBUTE) # FIXME(typhoonzero): add these tests back @@ -714,7 +715,8 @@ set_tests_properties(test_sigmoid_cross_entropy_with_logits_op set_tests_properties(test_imperative_optimizer_v2 PROPERTIES TIMEOUT 150) set_tests_properties(test_partial_sum_op PROPERTIES TIMEOUT 120) set_tests_properties(test_sgd_op PROPERTIES TIMEOUT 250) -set_tests_properties(test_generator_dataloader PROPERTIES TIMEOUT 120) +set_tests_properties(test_generator_dataloader_deprecated PROPERTIES TIMEOUT + 120) set_tests_properties(test_partial_concat_op PROPERTIES TIMEOUT 120) set_tests_properties(test_reduce_op PROPERTIES TIMEOUT 500) set_tests_properties(test_conv_nn_grad PROPERTIES TIMEOUT 220) @@ -724,7 +726,7 @@ set_tests_properties(test_bilinear_interp_op PROPERTIES TIMEOUT 120) set_tests_properties(test_decoupled_py_reader PROPERTIES TIMEOUT 120) set_tests_properties(test_fuse_bn_act_pass PROPERTIES TIMEOUT 120) set_tests_properties(test_conv2d_op_depthwise_conv PROPERTIES TIMEOUT 120) -set_tests_properties(test_conv2d_api PROPERTIES TIMEOUT 120) +set_tests_properties(test_conv2d_api_deprecated PROPERTIES TIMEOUT 120) set_tests_properties(test_elementwise_mul_op PROPERTIES TIMEOUT 120) set_tests_properties(test_dygraph_multi_forward PROPERTIES TIMEOUT 120) set_tests_properties(test_imperative_ocr_attention_model PROPERTIES TIMEOUT 120) diff --git a/test/deprecated/legacy_test/test_conv2d_api.py b/test/deprecated/legacy_test/test_conv2d_api_deprecated.py similarity index 100% rename from test/deprecated/legacy_test/test_conv2d_api.py rename to test/deprecated/legacy_test/test_conv2d_api_deprecated.py diff --git a/test/deprecated/legacy_test/test_dist_fleet_a_sync_optimizer_geo.py b/test/deprecated/legacy_test/test_dist_fleet_a_sync_optimizer_geo_deprecated.py similarity index 100% rename from test/deprecated/legacy_test/test_dist_fleet_a_sync_optimizer_geo.py rename to test/deprecated/legacy_test/test_dist_fleet_a_sync_optimizer_geo_deprecated.py diff --git a/test/deprecated/legacy_test/test_eager_run_program.py b/test/deprecated/legacy_test/test_eager_run_program_deprecated.py similarity index 100% rename from test/deprecated/legacy_test/test_eager_run_program.py rename to test/deprecated/legacy_test/test_eager_run_program_deprecated.py diff --git a/test/deprecated/legacy_test/test_generator_dataloader.py b/test/deprecated/legacy_test/test_generator_dataloader_deprecated.py similarity index 100% rename from test/deprecated/legacy_test/test_generator_dataloader.py rename to test/deprecated/legacy_test/test_generator_dataloader_deprecated.py diff --git a/tools/gpups_test.sh b/tools/gpups_test.sh index f97a37aa3a141..07122405a21d7 100644 --- a/tools/gpups_test.sh +++ b/tools/gpups_test.sh @@ -58,7 +58,7 @@ parallel_list="^init_phi_test$|\ ^test_collective_cpu_barrier_with_gloo$|\ ^test_conv1d_layer$|\ ^test_conv1d_transpose_layer$|\ -^test_conv2d_api$|\ +^test_conv2d_api_deprecated$|\ ^test_conv2d_layer$|\ ^test_conv2d_op_depthwise_conv$|\ ^test_conv2d_transpose_layer$|\ diff --git a/tools/parallel_UT_rule.py b/tools/parallel_UT_rule.py index 7775d67135589..e6908e9df955a 100755 --- a/tools/parallel_UT_rule.py +++ b/tools/parallel_UT_rule.py @@ -556,7 +556,7 @@ 'test_dist_sparse_tensor_load_sgd', 'test_dist_fleet_a_sync_optimizer_auto_geo', 'test_dist_lookup_sparse_table_fuse_ops', - 'test_dist_fleet_a_sync_optimizer_geo', + 'test_dist_fleet_a_sync_optimizer_geo_deprecated', 'test_multiprocess_dataloader_iterable_dataset_static', 'test_dist_fleet_grad_clip', 'test_fleet_pipeline_meta_optimizer_with_recompute', @@ -1359,7 +1359,7 @@ 'test_instance_norm_op', 'test_lambv2_op', 'test_yolo_box_op', - 'test_generator_dataloader', + 'test_generator_dataloader_deprecated', 'test_conv2d_transpose_op_depthwise_conv', 'test_imperative_save_load_v2', 'test_lookahead', @@ -1501,7 +1501,7 @@ 'test_multiprocess_dataloader_iterable_dataset_dynamic', 'test_imperative_se_resnext', 'test_norm_nn_grad', - 'test_conv2d_api', + 'test_conv2d_api_deprecated', ] SIXTH_PARALLEL_JOB_NEW = [ @@ -2027,7 +2027,7 @@ 'test_parallel_dygraph_sparse_embedding', 'test_dist_mnist_ring_allreduce', 'test_fleet_launch_async', - 'test_dist_fleet_a_sync_optimizer_geo', + 'test_dist_fleet_a_sync_optimizer_geo_deprecated', 'test_auto_checkpoint', 'test_fleet_pipeline_meta_optimizer', 'test_dist_fleet_heter_ctr', @@ -2438,7 +2438,7 @@ 'test_cuda_empty_cache', 'test_randn_op', 'test_maximum_op', - 'test_conv2d_api', + 'test_conv2d_api_deprecated', 'test_add_position_encoding_op', 'test_tensor_methods', 'test_imperative_partitial_backward', diff --git a/tools/static_mode_white_list.py b/tools/static_mode_white_list.py index 11905af7de4e8..a6dbad6038a2d 100755 --- a/tools/static_mode_white_list.py +++ b/tools/static_mode_white_list.py @@ -231,7 +231,7 @@ 'test_generate_mask_labels_op', 'test_generate_proposal_labels_op', 'test_generate_proposals_op', - 'test_generator_dataloader', + 'test_generator_dataloader_deprecated', 'test_get_places_op', 'test_get_tensor_from_selected_rows_op', 'test_gradient_clip', diff --git a/tools/test_run_by_protobuf_3.py b/tools/test_run_by_protobuf_3.py index 688b724436de2..52ce36683e380 100644 --- a/tools/test_run_by_protobuf_3.py +++ b/tools/test_run_by_protobuf_3.py @@ -24,7 +24,7 @@ 'test_dist_fleet_a_sync_optimizer_async', 'test_dist_fleet_a_sync_optimizer_auto', 'test_dist_fleet_a_sync_optimizer_sync', - 'test_dist_fleet_a_sync_optimizer_geo', + 'test_dist_fleet_a_sync_optimizer_geo_deprecated', 'test_dist_fleet_a_sync_optimizer_auto_geo', 'test_dist_fleet_a_sync_optimizer_auto_async', 'test_fleet_fp16_allreduce_meta_optimizer', diff --git a/tools/windows/run_unittests.sh b/tools/windows/run_unittests.sh index 2aad5e082b20f..ebca6e41296fd 100644 --- a/tools/windows/run_unittests.sh +++ b/tools/windows/run_unittests.sh @@ -21,7 +21,7 @@ disable_wingpu_test="^test_model$|\ ^test_add_reader_dependency_for_interpretercore$|\ ^test_decoupled_py_reader$|\ ^test_decoupled_py_reader_static_build$|\ -^test_generator_dataloader$|\ +^test_generator_dataloader_deprecated$|\ ^test_parallel_dygraph_sync_batch_norm$|\ ^test_py_reader_using_executor$|\ ^test_program_prune_backward$|\ @@ -83,7 +83,7 @@ disable_wingpu_cuda12_test="^test_cholesky_op$|\ ^test_switch_autotune$|\ ^test_elementwise_div_op$|\ ^test_elementwise_mul_op$|\ -^test_conv2d_api$|\ +^test_conv2d_api_deprecated$|\ ^test_fused_gemm_epilogue_pass$|\ ^test_cuda_graphed_layer$|\ ^test_quant_linear_op$|\ @@ -220,7 +220,7 @@ disable_wingpu_cuda12_test="^test_cholesky_op$|\ ^test_matmul_op$|\ ^test_decoupled_py_reader_data_check$|\ ^test_decoupled_py_reader$|\ -^test_generator_dataloader$|\ +^test_generator_dataloader_deprecated$|\ ^test_py_reader_combination$|\ ^test_reader_reset$|\ ^test_sync_batch_norm_op$|\ @@ -400,7 +400,7 @@ disable_win_inference_test="^trt_quant_int8_yolov3_r50_test$|\ ^test_compat$|\ ^test_decoupled_py_reader$|\ ^test_decoupled_py_reader_static_build$|\ -^test_generator_dataloader$|\ +^test_generator_dataloader_deprecated$|\ ^test_py_reader_using_executor$|\ ^test_dataloader_keep_order$|\ ^test_dataloader_unkeep_order$|\ From c4435f3a3359e7a96b1268f6c744e9c89728c56b Mon Sep 17 00:00:00 2001 From: walkalone20 <73780235+walkalone20@users.noreply.github.com> Date: Tue, 21 May 2024 15:47:30 +0800 Subject: [PATCH 05/13] =?UTF-8?q?=E3=80=90Hackathon=206th=20Fundable=20Pro?= =?UTF-8?q?jects=202=20No.39=E3=80=91Fix=20performance-for-range-copy=20fi?= =?UTF-8?q?nal=20(#64429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * for-range * formater --- paddle/fluid/distributed/rpc/rpc_agent.cc | 2 +- paddle/phi/api/lib/data_transform.cc | 2 +- paddle/phi/core/distributed/comm_task_manager.cc | 2 +- paddle/pir/src/dialect/shape/utils/shape_analysis.cc | 2 +- paddle/pir/src/dialect/shape/utils/shape_or_data_expr.cc | 3 ++- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/paddle/fluid/distributed/rpc/rpc_agent.cc b/paddle/fluid/distributed/rpc/rpc_agent.cc index 9ff4e6cd9fcea..ce20a67486f1e 100644 --- a/paddle/fluid/distributed/rpc/rpc_agent.cc +++ b/paddle/fluid/distributed/rpc/rpc_agent.cc @@ -32,7 +32,7 @@ std::shared_ptr RpcAgent::rpc_agent_instance_ = nullptr; RpcAgent::RpcAgent(std::string name, std::vector infos) { name_ = std::move(name); - for (auto info : infos) { + for (const auto &info : infos) { name_to_infos_.insert({info.name_, info}); id_to_infos_.insert({info.id_, info}); } diff --git a/paddle/phi/api/lib/data_transform.cc b/paddle/phi/api/lib/data_transform.cc index 01eb529a11b2c..2eab308522c8e 100644 --- a/paddle/phi/api/lib/data_transform.cc +++ b/paddle/phi/api/lib/data_transform.cc @@ -972,7 +972,7 @@ PrepareDataForDistTensor( const TransformFlag& transform_flag, bool is_stride_kernel) { std::vector> out; - for (auto tensor_in : input) { + for (const auto& tensor_in : input) { if (tensor_in) { phi::distributed::DistTensor* dist_tensor = static_cast(tensor_in.get()); diff --git a/paddle/phi/core/distributed/comm_task_manager.cc b/paddle/phi/core/distributed/comm_task_manager.cc index ae7de42291358..8f79e8a0ecbaf 100644 --- a/paddle/phi/core/distributed/comm_task_manager.cc +++ b/paddle/phi/core/distributed/comm_task_manager.cc @@ -158,7 +158,7 @@ void CommTaskManager::CommTaskLoop() { } else { // case 2: all group is not empty, but all last task is completed // case 3: all group is not empty, some group task started but not - for (auto iter : group_last_comm_task_) { + for (const auto& iter : group_last_comm_task_) { LogLongStr("Find last group comm task:", iter.second->GetTraceMsg()); } } diff --git a/paddle/pir/src/dialect/shape/utils/shape_analysis.cc b/paddle/pir/src/dialect/shape/utils/shape_analysis.cc index ea75ee1bbb3a0..89cc46e7ec779 100644 --- a/paddle/pir/src/dialect/shape/utils/shape_analysis.cc +++ b/paddle/pir/src/dialect/shape/utils/shape_analysis.cc @@ -228,7 +228,7 @@ InferSymbolicShapeContext::SimplifyBroadcastForShapeOrData( }, [&](const symbol::TensorListShapeOrDataDimExprs& tensor_list) { symbol::TensorListShapeOrDataDimExprs simplified_tensor_list; - for (symbol::TensorShapeOrDataDimExprs tensor_shape_or_data : + for (const symbol::TensorShapeOrDataDimExprs& tensor_shape_or_data : tensor_list) { simplified_tensor_list.push_back( TensorShapeOrDataVisitor(tensor_shape_or_data)); diff --git a/paddle/pir/src/dialect/shape/utils/shape_or_data_expr.cc b/paddle/pir/src/dialect/shape/utils/shape_or_data_expr.cc index fd72a2d8196d3..60e322ff0d31d 100644 --- a/paddle/pir/src/dialect/shape/utils/shape_or_data_expr.cc +++ b/paddle/pir/src/dialect/shape/utils/shape_or_data_expr.cc @@ -53,7 +53,8 @@ ShapeOrDataDimExprs SubstituteShapeOrData( }, [&](const TensorListShapeOrDataDimExprs& tensor_list) { TensorListShapeOrDataDimExprs substituted_tensor_list; - for (TensorShapeOrDataDimExprs tensor_shape_or_data : tensor_list) { + for (const TensorShapeOrDataDimExprs& tensor_shape_or_data : + tensor_list) { substituted_tensor_list.push_back(SubstituteTensorShapeOrData( tensor_shape_or_data, substitution_pattern)); } From 7c9b08a04a537b126b0417e7450cec2c40102007 Mon Sep 17 00:00:00 2001 From: fanhaoxuee <129482555+ApricityXX@users.noreply.github.com> Date: Tue, 21 May 2024 16:24:31 +0800 Subject: [PATCH 06/13] =?UTF-8?q?=E3=80=90Hackathon=206th=20Fundable=20Pro?= =?UTF-8?q?jects=202=20No.32=E3=80=91=20modernize-pass-by-value=5F2-part?= =?UTF-8?q?=20(#64026)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 5.3 * 5.3 * 5.3 * 5.3 * 5.3 * 5.3 * 5.5 * 5.7 * 5.7 * 5.19 * 5.19 --- .../memory/allocation/aligned_allocator.cc | 8 +++-- .../memory/allocation/aligned_allocator.h | 2 +- .../memory/allocation/allocator_facade.cc | 5 ++-- .../auto_growth_best_fit_allocator.cc | 5 ++-- .../auto_growth_best_fit_allocator.h | 11 ++++--- .../dialect/operator/ir/ir_selected_rows.cc | 10 +++++-- .../dialect/operator/ir/ir_selected_rows.h | 2 +- .../pir/dialect/operator/ir/ir_tensor.cc | 10 +++++-- .../fluid/pir/dialect/operator/ir/ir_tensor.h | 2 +- .../operator/utils/op_yaml_info_parser.cc | 7 +++-- .../operator/utils/op_yaml_info_parser.h | 2 +- .../pir/drr/include/drr_rewrite_pattern.h | 11 ++++--- paddle/fluid/pir/drr/src/match_context.cc | 3 +- paddle/fluid/pir/drr/src/rewrite_pattern.cc | 5 ++-- .../gpu/fused_weight_only_linear_pass.cc | 12 +++++--- .../conv_activation_onednn_fuse_pass.cc | 16 ++++++---- .../transforms/onednn/conv_bias_fuse_pass.cc | 8 +++-- ...conv_concat_activation_onednn_fuse_pass.cc | 18 +++++++----- .../conv_elementwise_add_onednn_fuse_pass.cc | 29 +++++++++++-------- 19 files changed, 100 insertions(+), 66 deletions(-) diff --git a/paddle/fluid/memory/allocation/aligned_allocator.cc b/paddle/fluid/memory/allocation/aligned_allocator.cc index 141cf91258449..b27b1db26b0fa 100644 --- a/paddle/fluid/memory/allocation/aligned_allocator.cc +++ b/paddle/fluid/memory/allocation/aligned_allocator.cc @@ -14,11 +14,12 @@ #include "paddle/fluid/memory/allocation/aligned_allocator.h" +#include + #include "paddle/common/macros.h" #include "paddle/fluid/platform/enforce.h" REGISTER_FILE_SYMBOLS(aligned_allocator); - namespace paddle { namespace memory { namespace allocation { @@ -39,8 +40,9 @@ class AlignedAllocation : public Allocation { }; AlignedAllocator::AlignedAllocator( - const std::shared_ptr& underlying_allocator, size_t alignment) - : underlying_allocator_(underlying_allocator), alignment_(alignment) { + std::shared_ptr underlying_allocator, size_t alignment) + : underlying_allocator_(std::move(underlying_allocator)), + alignment_(alignment) { PADDLE_ENFORCE_GT( alignment_, 0, diff --git a/paddle/fluid/memory/allocation/aligned_allocator.h b/paddle/fluid/memory/allocation/aligned_allocator.h index b129249a673bd..5dc15646e8856 100644 --- a/paddle/fluid/memory/allocation/aligned_allocator.h +++ b/paddle/fluid/memory/allocation/aligned_allocator.h @@ -24,7 +24,7 @@ namespace allocation { class AlignedAllocator : public Allocator { public: - AlignedAllocator(const std::shared_ptr& underlying_allocator, + AlignedAllocator(std::shared_ptr underlying_allocator, size_t alignment); bool IsAllocThreadSafe() const override; diff --git a/paddle/fluid/memory/allocation/allocator_facade.cc b/paddle/fluid/memory/allocation/allocator_facade.cc index d1f627070f4e9..158c56d7f94f6 100644 --- a/paddle/fluid/memory/allocation/allocator_facade.cc +++ b/paddle/fluid/memory/allocation/allocator_facade.cc @@ -31,6 +31,7 @@ #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) #include +#include #include "paddle/fluid/memory/allocation/cuda_allocator.h" #include "paddle/fluid/memory/allocation/cuda_managed_allocator.h" @@ -141,8 +142,8 @@ class CUDAGraphAllocator DecoratedAllocationPtr underlying_allocation_; }; - explicit CUDAGraphAllocator(const std::shared_ptr& allocator) - : underlying_allocator_(allocator) {} + explicit CUDAGraphAllocator(std::shared_ptr allocator) + : underlying_allocator_(std::move(allocator)) {} public: ~CUDAGraphAllocator() override = default; diff --git a/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.cc b/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.cc index 2dcc1295fec25..0d4ddca4f237e 100644 --- a/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.cc +++ b/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.cc @@ -16,6 +16,7 @@ #include #include // NOLINT +#include #include "paddle/fluid/memory/allocation/aligned_allocator.h" #include "paddle/fluid/platform/flags.h" @@ -46,12 +47,12 @@ namespace memory { namespace allocation { AutoGrowthBestFitAllocator::AutoGrowthBestFitAllocator( - const std::shared_ptr &underlying_allocator, + std::shared_ptr underlying_allocator, size_t alignment, size_t chunk_size, bool allow_free_idle_chunk, int extra_padding_size) - : underlying_allocator_(underlying_allocator), + : underlying_allocator_(std::move(underlying_allocator)), alignment_(alignment), chunk_size_(std::max(AlignedSize(chunk_size, alignment), alignment)), allow_free_idle_chunk_(allow_free_idle_chunk), diff --git a/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h b/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h index 572ca695cef9a..112555bfe4118 100644 --- a/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h +++ b/paddle/fluid/memory/allocation/auto_growth_best_fit_allocator.h @@ -29,12 +29,11 @@ namespace allocation { class AutoGrowthBestFitAllocator : public Allocator { public: - AutoGrowthBestFitAllocator( - const std::shared_ptr &underlying_allocator, - size_t alignment, - size_t chunk_size = 0, - bool allow_free_idle_chunk = true, - int extra_padding_size = 0); + AutoGrowthBestFitAllocator(std::shared_ptr underlying_allocator, + size_t alignment, + size_t chunk_size = 0, + bool allow_free_idle_chunk = true, + int extra_padding_size = 0); bool IsAllocThreadSafe() const override { return true; } diff --git a/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.cc b/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.cc index 384560ef591fc..3e191ff4d2fec 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.cc +++ b/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.cc @@ -13,6 +13,8 @@ // limitations under the License. #include "paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h" + +#include #include "paddle/common/enforce.h" namespace paddle { @@ -20,9 +22,13 @@ namespace dialect { IrSelectedRows::IrSelectedRows(phi::DataType dtype, const phi::DDim& dims, phi::DataLayout layout, - const LoD& lod, + LoD lod, size_t offset) - : dims_(dims), dtype_(dtype), layout_(layout), lod_(lod), offset_(offset) {} + : dims_(dims), + dtype_(dtype), + layout_(layout), + lod_(std::move(lod)), + offset_(offset) {} IrSelectedRows::IrSelectedRows(const IrSelectedRows& other) { dims_ = other.dims(); diff --git a/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h b/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h index 856ddb2f7542c..dd41a7467a78d 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h +++ b/paddle/fluid/pir/dialect/operator/ir/ir_selected_rows.h @@ -34,7 +34,7 @@ class IrSelectedRows IrSelectedRows(phi::DataType dtype, const phi::DDim& dims, phi::DataLayout layout, - const LoD& lod, + LoD lod, size_t offset = 0); IrSelectedRows(IrSelectedRows&& other) = default; diff --git a/paddle/fluid/pir/dialect/operator/ir/ir_tensor.cc b/paddle/fluid/pir/dialect/operator/ir/ir_tensor.cc index 131a8b1848bd4..07849efab963a 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ir_tensor.cc +++ b/paddle/fluid/pir/dialect/operator/ir/ir_tensor.cc @@ -14,6 +14,8 @@ #include "paddle/fluid/pir/dialect/operator/ir/ir_tensor.h" +#include + #include "paddle/common/enforce.h" namespace paddle { @@ -21,9 +23,13 @@ namespace dialect { IrTensor::IrTensor(phi::DataType dtype, const phi::DDim& dims, phi::DataLayout layout, - const LoD& lod, + LoD lod, size_t offset) - : dims_(dims), dtype_(dtype), layout_(layout), lod_(lod), offset_(offset) {} + : dims_(dims), + dtype_(dtype), + layout_(layout), + lod_(std::move(lod)), + offset_(offset) {} IrTensor::IrTensor(const IrTensor& other) { dims_ = other.dims(); diff --git a/paddle/fluid/pir/dialect/operator/ir/ir_tensor.h b/paddle/fluid/pir/dialect/operator/ir/ir_tensor.h index 45847d3080387..7d58bb63e5586 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ir_tensor.h +++ b/paddle/fluid/pir/dialect/operator/ir/ir_tensor.h @@ -33,7 +33,7 @@ class IrTensor : public phi::TensorBase, IrTensor(phi::DataType dtype, const phi::DDim& dims, phi::DataLayout layout, - const LoD& lod, + LoD lod, size_t offset = 0); IrTensor(IrTensor&& other) = default; diff --git a/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.cc b/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.cc index aeecd67bcf920..32c45d20f8d25 100644 --- a/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.cc +++ b/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.cc @@ -13,14 +13,15 @@ // limitations under the License. #include "paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h" + +#include #include "paddle/phi/core/enforce.h" namespace paddle { namespace dialect { -OpYamlInfoParser::OpYamlInfoParser(const OpInfoTuple& op_info_tuple, - bool is_legacy_op) - : op_info_tuple_(op_info_tuple), is_legacy_op_(is_legacy_op) { +OpYamlInfoParser::OpYamlInfoParser(OpInfoTuple op_info_tuple, bool is_legacy_op) + : op_info_tuple_(std::move(op_info_tuple)), is_legacy_op_(is_legacy_op) { parse(); } diff --git a/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h b/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h index 4ff03f336dae2..b72e8ef1327cb 100644 --- a/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h +++ b/paddle/fluid/pir/dialect/operator/utils/op_yaml_info_parser.h @@ -23,7 +23,7 @@ class OpYamlInfoParser { public: OpYamlInfoParser() = delete; - TEST_API explicit OpYamlInfoParser(const OpInfoTuple& op_info_tuple, + TEST_API explicit OpYamlInfoParser(OpInfoTuple op_info_tuple, bool is_legacy_op = false); TEST_API bool IsTensorAttribute(size_t index) const; diff --git a/paddle/fluid/pir/drr/include/drr_rewrite_pattern.h b/paddle/fluid/pir/drr/include/drr_rewrite_pattern.h index 5778263750e5e..60b1e40441320 100644 --- a/paddle/fluid/pir/drr/include/drr_rewrite_pattern.h +++ b/paddle/fluid/pir/drr/include/drr_rewrite_pattern.h @@ -39,12 +39,11 @@ class ResultPatternGraph; class DrrRewritePattern : public pir::RewritePattern { public: - DrrRewritePattern( - const std::string& pattern_name, - const DrrPatternContext& drr_context, - pir::IrContext* context, - pir::PatternBenefit benefit, - const std::shared_ptr& drr_pattern_owner); + DrrRewritePattern(const std::string& pattern_name, + const DrrPatternContext& drr_context, + pir::IrContext* context, + pir::PatternBenefit benefit, + std::shared_ptr drr_pattern_owner); bool MatchAndRewrite( pir::Operation* op, diff --git a/paddle/fluid/pir/drr/src/match_context.cc b/paddle/fluid/pir/drr/src/match_context.cc index 64d8ed588484a..572f75c43e9e5 100644 --- a/paddle/fluid/pir/drr/src/match_context.cc +++ b/paddle/fluid/pir/drr/src/match_context.cc @@ -13,6 +13,7 @@ // limitations under the License. #include +#include #include "paddle/fluid/pir/drr/include/drr_match_context.h" #include "paddle/fluid/pir/drr/src/match_context_impl.h" @@ -22,7 +23,7 @@ namespace paddle { namespace drr { MatchContext::MatchContext(std::shared_ptr impl) - : impl_(impl) {} + : impl_(std::move(impl)) {} const pir::Value& MatchContext::Tensor(const std::string& tensor_name) const { return impl_->Tensor(tensor_name); diff --git a/paddle/fluid/pir/drr/src/rewrite_pattern.cc b/paddle/fluid/pir/drr/src/rewrite_pattern.cc index 7752881b76697..f4b846db7f612 100644 --- a/paddle/fluid/pir/drr/src/rewrite_pattern.cc +++ b/paddle/fluid/pir/drr/src/rewrite_pattern.cc @@ -14,6 +14,7 @@ #include #include +#include #include "glog/vlog_is_on.h" #include "paddle/fluid/pir/drr/include/drr_pattern_base.h" @@ -33,7 +34,7 @@ DrrRewritePattern::DrrRewritePattern( const DrrPatternContext& drr_context, pir::IrContext* context, pir::PatternBenefit benefit, - const std::shared_ptr& drr_pattern_owner) + std::shared_ptr drr_pattern_owner) : pir::RewritePattern( (*drr_context.source_pattern_graph()->OutputNodes().begin())->name(), benefit, @@ -44,7 +45,7 @@ DrrRewritePattern::DrrRewritePattern( constraints_(drr_context.constraints()), post_processes_(drr_context.post_processes()), result_pattern_graph_(drr_context.result_pattern_graph()), - drr_pattern_owner_(drr_pattern_owner) { + drr_pattern_owner_(std::move(drr_pattern_owner)) { PADDLE_ENFORCE_NE(source_pattern_graph_->owned_op_call().empty(), true, phi::errors::InvalidArgument( diff --git a/paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.cc b/paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.cc index f6c312fa7a8d3..efe0053b5bee3 100644 --- a/paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.cc +++ b/paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.cc @@ -14,6 +14,8 @@ #include "paddle/fluid/pir/transforms/gpu/fused_weight_only_linear_pass.h" +#include + #include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" #include "paddle/fluid/pir/drr/include/drr_pattern_base.h" #include "paddle/fluid/pir/utils/general_functions.h" @@ -46,9 +48,11 @@ class FusedWeightOnlyLinearWithBiasPattern public: FusedWeightOnlyLinearWithBiasPattern(bool reverse_add, - const std::string &algo, + std::string algo, int sm_version) - : reverse_add_(reverse_add), algo_(algo), sm_version_(sm_version) {} + : reverse_add_(reverse_add), + algo_(std::move(algo)), + sm_version_(sm_version) {} std::string name() const override { return "FusedWeightOnlyLinearWithBiasPattern"; @@ -165,8 +169,8 @@ class FusedWeightOnlyLinearNoBiasPattern : public paddle::drr::DrrPatternBase { int sm_version_; public: - FusedWeightOnlyLinearNoBiasPattern(const std::string &algo, int sm_version) - : algo_(algo), sm_version_(sm_version) {} + FusedWeightOnlyLinearNoBiasPattern(std::string algo, int sm_version) + : algo_(std::move(algo)), sm_version_(sm_version) {} public: std::string name() const override { diff --git a/paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.cc b/paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.cc index d7d1d4286159e..4f0267b3b9f3e 100644 --- a/paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.cc +++ b/paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.cc @@ -14,6 +14,8 @@ #include "paddle/fluid/pir/transforms/onednn/conv_activation_onednn_fuse_pass.h" +#include + #include "paddle/fluid/pir/dialect/operator/ir/onednn_op.h" #include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" #include "paddle/fluid/pir/drr/include/drr_pattern_base.h" @@ -38,10 +40,10 @@ class ConvActivationFusePattern : public paddle::drr::DrrPatternBase { public: ConvActivationFusePattern(size_t activation_count, - const std::string &activation_name, + std::string activation_name, int fused_level) : activation_count_(activation_count), - activation_name_(activation_name), + activation_name_(std::move(activation_name)), fused_level_(fused_level) {} std::string name() const override { @@ -224,8 +226,9 @@ class ConvGeluFusePattern : public paddle::drr::DrrPatternBase { const int fused_level_; public: - ConvGeluFusePattern(const std::string &activation_name, int fused_level) - : activation_name_(activation_name), fused_level_(fused_level) {} + ConvGeluFusePattern(std::string activation_name, int fused_level) + : activation_name_(std::move(activation_name)), + fused_level_(fused_level) {} std::string name() const override { return "ConvGeluFusePattern"; } @@ -367,8 +370,9 @@ class ConvClipFusePattern : public paddle::drr::DrrPatternBase { const int fused_level_; public: - ConvClipFusePattern(const std::string &activation_name, int fused_level) - : activation_name_(activation_name), fused_level_(fused_level) {} + ConvClipFusePattern(std::string activation_name, int fused_level) + : activation_name_(std::move(activation_name)), + fused_level_(fused_level) {} std::string name() const override { return "ConvClipFusePattern"; } diff --git a/paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.cc b/paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.cc index beb509cbceb65..248f0602049de 100644 --- a/paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.cc +++ b/paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.cc @@ -14,6 +14,8 @@ #include "paddle/fluid/pir/transforms/onednn/conv_bias_fuse_pass.h" +#include + #include "paddle/fluid/pir/dialect/operator/ir/onednn_op.h" #include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" #include "paddle/fluid/pir/drr/include/drr_pattern_base.h" @@ -30,9 +32,9 @@ class ConvBiasFusePattern : public paddle::drr::DrrPatternBase { std::string fused_conv_name_; public: - ConvBiasFusePattern(const std::string &conv_name, - const std::string &fused_conv_name) - : conv_name_(conv_name), fused_conv_name_(fused_conv_name) {} + ConvBiasFusePattern(std::string conv_name, std::string fused_conv_name) + : conv_name_(std::move(conv_name)), + fused_conv_name_(std::move(fused_conv_name)) {} std::string name() const override { return "ConvBiasFusePattern"; } diff --git a/paddle/fluid/pir/transforms/onednn/conv_concat_activation_onednn_fuse_pass.cc b/paddle/fluid/pir/transforms/onednn/conv_concat_activation_onednn_fuse_pass.cc index 910a78dcdd84c..53f456e477f8f 100644 --- a/paddle/fluid/pir/transforms/onednn/conv_concat_activation_onednn_fuse_pass.cc +++ b/paddle/fluid/pir/transforms/onednn/conv_concat_activation_onednn_fuse_pass.cc @@ -14,6 +14,8 @@ #include "paddle/fluid/pir/transforms/onednn/conv_concat_activation_onednn_fuse_pass.h" +#include + #include "paddle/fluid/pir/dialect/operator/ir/onednn_op.h" #include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" #include "paddle/fluid/pir/drr/include/drr_pattern_base.h" @@ -38,11 +40,11 @@ class NConvConcatActivationFusePattern : public paddle::drr::DrrPatternBase { public: NConvConcatActivationFusePattern(size_t concat_count, - const std::string &activation_name, + std::string activation_name, int fused_level, int benefit) : concat_count_(concat_count), - activation_name_(activation_name), + activation_name_(std::move(activation_name)), fused_level_(fused_level), benefit_(benefit) {} @@ -293,10 +295,10 @@ class NConvConcatHardSigmoidFusePattern : public paddle::drr::DrrPatternBase { public: NConvConcatHardSigmoidFusePattern(size_t concat_count, - const std::string &activation_name, + std::string activation_name, int fused_level) : concat_count_(concat_count), - activation_name_(activation_name), + activation_name_(std::move(activation_name)), fused_level_(fused_level) {} std::string name() const override { @@ -512,10 +514,10 @@ class NConvConcatGeluFusePattern : public paddle::drr::DrrPatternBase { public: NConvConcatGeluFusePattern(size_t concat_count, - const std::string &activation_name, + std::string activation_name, int fused_level) : concat_count_(concat_count), - activation_name_(activation_name), + activation_name_(std::move(activation_name)), fused_level_(fused_level) {} std::string name() const override { @@ -737,10 +739,10 @@ class NConvConcatClipFusePattern : public paddle::drr::DrrPatternBase { public: NConvConcatClipFusePattern(size_t concat_count, - const std::string &activation_name, + std::string activation_name, int fused_level) : concat_count_(concat_count), - activation_name_(activation_name), + activation_name_(std::move(activation_name)), fused_level_(fused_level) {} std::string name() const override { diff --git a/paddle/fluid/pir/transforms/onednn/conv_elementwise_add_onednn_fuse_pass.cc b/paddle/fluid/pir/transforms/onednn/conv_elementwise_add_onednn_fuse_pass.cc index 5a1af48a55726..c1990f632fd1e 100644 --- a/paddle/fluid/pir/transforms/onednn/conv_elementwise_add_onednn_fuse_pass.cc +++ b/paddle/fluid/pir/transforms/onednn/conv_elementwise_add_onednn_fuse_pass.cc @@ -14,6 +14,8 @@ #include "paddle/fluid/pir/transforms/onednn/conv_elementwise_add_onednn_fuse_pass.h" +#include + #include "paddle/fluid/pir/dialect/operator/ir/onednn_op.h" #include "paddle/fluid/pir/dialect/operator/ir/pd_op.h" #include "paddle/fluid/pir/drr/include/drr_pattern_base.h" @@ -30,9 +32,9 @@ class ConvElementwiseAddPattern : public paddle::drr::DrrPatternBase { std::string fused_conv_name_; public: - ConvElementwiseAddPattern(const std::string &conv_name, - const std::string &fused_conv_name) - : conv_name_(conv_name), fused_conv_name_(fused_conv_name) {} + ConvElementwiseAddPattern(std::string conv_name, std::string fused_conv_name) + : conv_name_(std::move(conv_name)), + fused_conv_name_(std::move(fused_conv_name)) {} std::string name() const override { return "ConvElementwiseAddPattern"; } @@ -109,9 +111,10 @@ class ConvElementwiseAddAsYPattern : public paddle::drr::DrrPatternBase { std::string fused_conv_name_; public: - ConvElementwiseAddAsYPattern(const std::string &conv_name, - const std::string &fused_conv_name) - : conv_name_(conv_name), fused_conv_name_(fused_conv_name) {} + ConvElementwiseAddAsYPattern(std::string conv_name, + std::string fused_conv_name) + : conv_name_(std::move(conv_name)), + fused_conv_name_(std::move(fused_conv_name)) {} std::string name() const override { return "ConvElementwiseAddAsYPattern"; } @@ -188,9 +191,10 @@ class FusedConvBiasElementwiseAddPattern : public paddle::drr::DrrPatternBase { std::string fused_conv_name_; public: - FusedConvBiasElementwiseAddPattern(const std::string &conv_name, - const std::string &fused_conv_name) - : conv_name_(conv_name), fused_conv_name_(fused_conv_name) {} + FusedConvBiasElementwiseAddPattern(std::string conv_name, + std::string fused_conv_name) + : conv_name_(std::move(conv_name)), + fused_conv_name_(std::move(fused_conv_name)) {} std::string name() const override { return "FusedConvBiasElementwiseAddPattern"; @@ -284,9 +288,10 @@ class FusedConvBiasElementwiseAddAsYPattern std::string fused_conv_name_; public: - FusedConvBiasElementwiseAddAsYPattern(const std::string &conv_name, - const std::string &fused_conv_name) - : conv_name_(conv_name), fused_conv_name_(fused_conv_name) {} + FusedConvBiasElementwiseAddAsYPattern(std::string conv_name, + std::string fused_conv_name) + : conv_name_(std::move(conv_name)), + fused_conv_name_(std::move(fused_conv_name)) {} std::string name() const override { return "FusedConvBiasElementwiseAddAsYPattern"; From a8e29ef3c2ae2f6d339f614618d015682bf23ae6 Mon Sep 17 00:00:00 2001 From: huangjiyi <43315610+huangjiyi@users.noreply.github.com> Date: Tue, 21 May 2024 16:27:34 +0800 Subject: [PATCH 07/13] Unify operator yamls directory (#64446) * yaml normalization * move tensor_operands.yaml * update * update * rename yaml * fix * fix * refine file and dir name * fix --- .gitignore | 2 - .../hlir/dialect/operator/ir/CMakeLists.txt | 2 +- .../generator/CMakeLists.txt | 6 +- .../generator/eager_gen.py | 8 +- .../ir_adaptor/translator/CMakeLists.txt | 4 +- .../ir_adaptor/translator/op_compat_gen.py | 16 +- .../ir_adaptor/translator/op_translator.cc | 2 +- .../fluid/operators/generator/CMakeLists.txt | 138 ++++++++---------- .../operators/generator/ops_extra_info_gen.py | 2 +- .../operators/generator/templates/op.c.j2 | 2 +- .../generator/templates/sparse_ks.c.j2 | 2 +- .../generator/templates/sparse_op.c.j2 | 2 +- paddle/fluid/pir/dialect/CMakeLists.txt | 117 ++++++--------- .../fluid/pir/dialect/operator/ir/.gitignore | 2 - paddle/fluid/pir/drr/CMakeLists.txt | 33 ++--- .../api/auto_code_generated/CMakeLists.txt | 12 +- .../prim/api/auto_code_generated/eager_gen.py | 2 +- .../tensor_operants_gen.py | 2 +- paddle/fluid/primitive/codegen/CMakeLists.txt | 42 ++---- paddle/phi/CMakeLists.txt | 8 + paddle/phi/README.md | 4 +- paddle/phi/api/CMakeLists.txt | 7 - .../phi/api/{yaml => }/generator/api_base.py | 0 .../phi/api/{yaml => }/generator/api_gen.py | 2 +- .../{yaml => }/generator/backward_api_gen.py | 2 +- .../api/{yaml => }/generator/dist_api_gen.py | 2 +- .../{yaml => }/generator/dist_bw_api_gen.py | 2 +- .../generator/intermediate_api_gen.py | 4 +- .../{yaml => }/generator/sparse_api_gen.py | 2 +- .../{yaml => }/generator/sparse_bw_api_gen.py | 2 +- .../{yaml => }/generator/strings_api_gen.py | 2 +- .../generator/tensor_operants_gen.py | 16 +- .../generator/wrapped_infermeta_gen.py | 2 +- paddle/phi/api/lib/CMakeLists.txt | 46 +++--- .../api/{yaml => lib}/tensor_operants.yaml | 0 paddle/phi/{api => ops}/yaml/backward.yaml | 0 .../phi/{api => ops}/yaml/fused_backward.yaml | 0 paddle/phi/{api => ops}/yaml/fused_ops.yaml | 0 .../yaml/inconsistent/dygraph_backward.yaml} | 0 .../yaml/inconsistent/dygraph_ops.yaml} | 0 .../yaml/inconsistent/onednn_ops_extra.yaml} | 0 .../ops/yaml/inconsistent/onednn_static.yaml} | 0 .../yaml/inconsistent/static_backward.yaml} | 2 +- .../ops/yaml/inconsistent/static_ops.yaml} | 2 +- .../ops/yaml/inconsistent}/update_ops.yaml | 2 +- .../yaml/legacy}/static_backward.yaml | 0 .../yaml => ops/yaml/legacy}/static_ops.yaml | 0 paddle/phi/{api => ops}/yaml/op_compat.yaml | 0 paddle/phi/{api => ops}/yaml/op_version.yaml | 0 paddle/phi/{api => ops}/yaml/ops.yaml | 0 .../{api => ops}/yaml/sparse_backward.yaml | 0 paddle/phi/{api => ops}/yaml/sparse_ops.yaml | 0 paddle/phi/{api => ops}/yaml/strings_ops.yaml | 0 python/CMakeLists.txt | 8 +- .../incubate/autograd/composite_rules.py | 2 +- .../incubate/autograd/generate_op_map.py | 2 +- .../test_registered_phi_kernels.py | 8 +- tools/auto_parallel/target_path_lists.sh | 4 +- tools/check_api_yaml_same.py | 12 +- tools/check_file_diff_approvals.sh | 12 +- 60 files changed, 242 insertions(+), 309 deletions(-) delete mode 100644 paddle/fluid/pir/dialect/operator/ir/.gitignore rename paddle/phi/api/{yaml => }/generator/api_base.py (100%) rename paddle/phi/api/{yaml => }/generator/api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/backward_api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/dist_api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/dist_bw_api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/intermediate_api_gen.py (98%) rename paddle/phi/api/{yaml => }/generator/sparse_api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/sparse_bw_api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/strings_api_gen.py (99%) rename paddle/phi/api/{yaml => }/generator/tensor_operants_gen.py (97%) rename paddle/phi/api/{yaml => }/generator/wrapped_infermeta_gen.py (99%) rename paddle/phi/api/{yaml => lib}/tensor_operants.yaml (100%) rename paddle/phi/{api => ops}/yaml/backward.yaml (100%) rename paddle/phi/{api => ops}/yaml/fused_backward.yaml (100%) rename paddle/phi/{api => ops}/yaml/fused_ops.yaml (100%) rename paddle/phi/{api/yaml/legacy_backward.yaml => ops/yaml/inconsistent/dygraph_backward.yaml} (100%) rename paddle/phi/{api/yaml/legacy_ops.yaml => ops/yaml/inconsistent/dygraph_ops.yaml} (100%) rename paddle/{fluid/pir/dialect/operator/ir/ops_onednn_extra.yaml => phi/ops/yaml/inconsistent/onednn_ops_extra.yaml} (100%) rename paddle/{fluid/pir/dialect/operator/ir/onednn.yaml => phi/ops/yaml/inconsistent/onednn_static.yaml} (100%) rename paddle/{fluid/pir/dialect/operator/ir/ops_backward.yaml => phi/ops/yaml/inconsistent/static_backward.yaml} (99%) rename paddle/{fluid/pir/dialect/operator/ir/ops.yaml => phi/ops/yaml/inconsistent/static_ops.yaml} (99%) rename paddle/{fluid/pir/dialect/operator/ir => phi/ops/yaml/inconsistent}/update_ops.yaml (93%) rename paddle/phi/{api/yaml => ops/yaml/legacy}/static_backward.yaml (100%) rename paddle/phi/{api/yaml => ops/yaml/legacy}/static_ops.yaml (100%) rename paddle/phi/{api => ops}/yaml/op_compat.yaml (100%) rename paddle/phi/{api => ops}/yaml/op_version.yaml (100%) rename paddle/phi/{api => ops}/yaml/ops.yaml (100%) rename paddle/phi/{api => ops}/yaml/sparse_backward.yaml (100%) rename paddle/phi/{api => ops}/yaml/sparse_ops.yaml (100%) rename paddle/phi/{api => ops}/yaml/strings_ops.yaml (100%) diff --git a/.gitignore b/.gitignore index 8f87c4094fce1..67a6319a7a416 100644 --- a/.gitignore +++ b/.gitignore @@ -87,8 +87,6 @@ paddle/fluid/operators/generated_sparse_op.cc paddle/fluid/operators/generated_static_op.cc paddle/fluid/operators/generated_fused_op.cc paddle/fluid/operators/ops_signature/generated_*.cc -paddle/phi/api/yaml/parsed_apis/ -paddle/fluid/operators/generator/parsed_ops/ paddle/fluid/pybind/tmp_eager_op_function_impl.h paddle/fluid/pybind/eager_op_function_impl.h paddle/fluid/pybind/eager_op_function_impl.h diff --git a/paddle/cinn/hlir/dialect/operator/ir/CMakeLists.txt b/paddle/cinn/hlir/dialect/operator/ir/CMakeLists.txt index ba58a034fb4bb..90decb6b1d699 100644 --- a/paddle/cinn/hlir/dialect/operator/ir/CMakeLists.txt +++ b/paddle/cinn/hlir/dialect/operator/ir/CMakeLists.txt @@ -9,7 +9,7 @@ set(cinn_op_gen_file ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/op_generator/op_gen.py) set(cinn_op_compat_yaml_file - ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) + ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml) set(cinn_op_yaml_file ${PADDLE_SOURCE_DIR}/paddle/cinn/hlir/dialect/operator/ir/ops.yaml) diff --git a/paddle/fluid/eager/auto_code_generator/generator/CMakeLists.txt b/paddle/fluid/eager/auto_code_generator/generator/CMakeLists.txt index 3c5685f580b5b..674786ab108ef 100644 --- a/paddle/fluid/eager/auto_code_generator/generator/CMakeLists.txt +++ b/paddle/fluid/eager/auto_code_generator/generator/CMakeLists.txt @@ -1,8 +1,8 @@ set(api_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/fused_ops.yaml" + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/fused_ops.yaml" ) set(backward_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/backward.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_backward.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_backward.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/fused_backward.yaml" + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/backward.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_backward.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/fused_backward.yaml" ) set(tmp_forwards_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/eager/api/generated/eager_generated/forwards/tmp_dygraph_functions.cc" @@ -30,7 +30,7 @@ set(nodes_h_path ) # StringTensor only needs forward api set(fwd_api_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/strings_ops.yaml") + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/strings_ops.yaml") message("Final State Eager CodeGen") add_custom_target( diff --git a/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py b/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py index d7379ffb4e444..907b88cf18edf 100644 --- a/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py +++ b/paddle/fluid/eager/auto_code_generator/generator/eager_gen.py @@ -3117,11 +3117,11 @@ def GenerateForwardHFile(filepath, forward_function_declaration_str): forward_declaration_str = "" forward_definition_str = "" - # merge legacy_ops.yaml and ops.yaml, legacy_backward.yaml and backward.yaml + # merge dygraph_ops.yaml and ops.yaml, dygraph_backward.yaml and backward.yaml all_ops = [] all_bw = [] for api_yaml_path in api_yaml_paths: - if api_yaml_path.endswith("legacy_ops.yaml") or api_yaml_path.endswith( + if api_yaml_path.endswith("dygraph_ops.yaml") or api_yaml_path.endswith( "/ops.yaml" ): with open(api_yaml_path, 'r') as f: @@ -3129,7 +3129,7 @@ def GenerateForwardHFile(filepath, forward_function_declaration_str): for bw_yaml_path in backward_yaml_paths: if bw_yaml_path.endswith( - "legacy_backward.yaml" + "dygraph_backward.yaml" ) or bw_yaml_path.endswith("/backward.yaml"): with open(bw_yaml_path, 'r') as f: all_bw += yaml.safe_load(f) @@ -3143,7 +3143,7 @@ def GenerateForwardHFile(filepath, forward_function_declaration_str): else: backward_yaml_path = None - if api_yaml_path.endswith('/legacy_ops.yaml'): + if api_yaml_path.endswith('/dygraph_ops.yaml'): continue if api_yaml_path.endswith('/ops.yaml'): generator = DygraphForwardAndNodesGenerator( diff --git a/paddle/fluid/ir_adaptor/translator/CMakeLists.txt b/paddle/fluid/ir_adaptor/translator/CMakeLists.txt index 6b7540e0db75b..c8b145c449e37 100644 --- a/paddle/fluid/ir_adaptor/translator/CMakeLists.txt +++ b/paddle/fluid/ir_adaptor/translator/CMakeLists.txt @@ -3,9 +3,9 @@ set(PD_PROGRAM_TRANSLATOR_BINARY_DIR "${PADDLE_BINARY_DIR}/paddle/fluid/ir_adaptor/translator/") set(op_gen_file ${PD_PROGRAM_TRANSLATOR_SOURCE_DIR}/op_compat_gen.py) -set(op_compat_yaml_file ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) +set(op_compat_yaml_file ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml) set(sparse_op_yaml - ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_backward.yaml + ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_ops.yaml,${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_backward.yaml ) set(op_compat_source_file ${PD_PROGRAM_TRANSLATOR_SOURCE_DIR}/op_compat_info.cc) set(op_compat_templat_file diff --git a/paddle/fluid/ir_adaptor/translator/op_compat_gen.py b/paddle/fluid/ir_adaptor/translator/op_compat_gen.py index 2e6f870d5449d..5a95e6c5093b5 100644 --- a/paddle/fluid/ir_adaptor/translator/op_compat_gen.py +++ b/paddle/fluid/ir_adaptor/translator/op_compat_gen.py @@ -89,41 +89,41 @@ def insert_new_mutable_attributes( ].insert(0, v) _, legacy_name = insert_new_mappings(op_compat_item["op"]) - legacy_backward_op_names = [] + dygraph_backward_op_names = [] if "backward" in op_compat_item: backward_op_name_mapping_paris = op_compat_item["backward"].split( "," ) for pair in backward_op_name_mapping_paris: - _, legacy_backward_op_name = insert_new_mappings(pair) - legacy_backward_op_names.append(legacy_backward_op_name) + _, dygraph_backward_op_name = insert_new_mappings(pair) + dygraph_backward_op_names.append(dygraph_backward_op_name) if "inputs" in op_compat_item: insert_new_arg_mappings(legacy_name, op_compat_item["inputs"]) - for backward_op in legacy_backward_op_names: + for backward_op in dygraph_backward_op_names: insert_new_arg_mappings(backward_op, op_compat_item["inputs"]) if "attrs" in op_compat_item: insert_new_arg_mappings(legacy_name, op_compat_item["attrs"]) - for backward_op in legacy_backward_op_names: + for backward_op in dygraph_backward_op_names: insert_new_arg_mappings(backward_op, op_compat_item["attrs"]) if "outputs" in op_compat_item: insert_new_arg_mappings(legacy_name, op_compat_item["outputs"]) - for backward_op in legacy_backward_op_names: + for backward_op in dygraph_backward_op_names: insert_new_arg_mappings(backward_op, op_compat_item["outputs"]) if "int_array" in op_compat_item: insert_new_mutable_attributes( legacy_name, op_compat_item["int_array"] ) - for backward_op in legacy_backward_op_names: + for backward_op in dygraph_backward_op_names: insert_new_mutable_attributes( backward_op, op_compat_item["int_array"] ) if "scalar" in op_compat_item: insert_new_mutable_attributes(legacy_name, op_compat_item["scalar"]) - for backward_op in legacy_backward_op_names: + for backward_op in dygraph_backward_op_names: insert_new_mutable_attributes( backward_op, op_compat_item["scalar"] ) diff --git a/paddle/fluid/ir_adaptor/translator/op_translator.cc b/paddle/fluid/ir_adaptor/translator/op_translator.cc index 8c071ea081c42..cf355b361ac0a 100644 --- a/paddle/fluid/ir_adaptor/translator/op_translator.cc +++ b/paddle/fluid/ir_adaptor/translator/op_translator.cc @@ -1088,7 +1088,7 @@ struct IncrementOpTranscriber : public OpTranscriber { }; // The `assign_value` in static_ops.yaml is different from the one in -// `legacy_ops.yaml`. For this op we simulate the logic in +// `dygraph_ops.yaml`. For this op we simulate the logic in // python/paddle/tensor/creation.py::assign(x, output) struct AssignValueOpTranscriber : public OpTranscriber { pir::OpInfo LookUpOpInfo(pir::IrContext* ctx, diff --git a/paddle/fluid/operators/generator/CMakeLists.txt b/paddle/fluid/operators/generator/CMakeLists.txt index f48896e694d46..a6c47ce506ebb 100644 --- a/paddle/fluid/operators/generator/CMakeLists.txt +++ b/paddle/fluid/operators/generator/CMakeLists.txt @@ -2,20 +2,22 @@ include(operators) # set yaml file path -set(op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/ops.yaml) -set(legacy_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_ops.yaml) -set(bw_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/backward.yaml) -set(static_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/static_ops.yaml) -set(fused_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/fused_ops.yaml) +set(op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/ops.yaml) +set(legacy_op_yaml_file + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml) +set(bw_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/backward.yaml) +set(static_op_yaml_file + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/legacy/static_ops.yaml) +set(fused_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/fused_ops.yaml) set(legacy_bw_op_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_backward.yaml) -set(sparse_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_ops.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml) +set(sparse_op_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_ops.yaml) set(sparse_bw_op_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_backward.yaml) set(static_bw_op_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/static_backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/legacy/static_backward.yaml) set(fused_bw_op_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/fused_backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/fused_backward.yaml) if(NOT PYTHONINTERP_FOUND) find_package(PythonInterp REQUIRED) @@ -64,8 +66,7 @@ install_py_pyyaml() install_py_jinja2() # parse ops -set(parsed_op_dir - ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator/parsed_ops) +set(parsed_op_dir ${CMAKE_BINARY_DIR}/paddle/phi/ops/yaml) set(generated_op_path_1 ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generated_op1.cc) set(generated_op_path_2 @@ -110,46 +111,35 @@ message( execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator - COMMAND ${CMAKE_COMMAND} -E make_directory - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops + COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir} + COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir}/inconsistent + COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir}/legacy COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${op_yaml_file} - --output_path ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/ops.parsed.yaml - COMMAND - ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${legacy_op_yaml_file} - --output_path ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/legacy_ops.parsed.yaml - COMMAND - ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${bw_op_yaml_file} - --output_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/backward_ops.parsed.yaml --backward + --output_path ${parsed_op_dir}/ops.parsed.yaml + COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${legacy_op_yaml_file} + --output_path ${parsed_op_dir}/inconsistent/dygraph_ops.parsed.yaml + COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${bw_op_yaml_file} + --output_path ${parsed_op_dir}/backward.parsed.yaml --backward COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${legacy_bw_op_yaml_file} - --output_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/legacy_backward_ops.parsed.yaml + --output_path ${parsed_op_dir}/inconsistent/dygraph_backward.parsed.yaml --backward - COMMAND - ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${static_op_yaml_file} - --output_path ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/static_ops.parsed.yaml - COMMAND - ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${fused_op_yaml_file} - --output_path ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/fused_ops.parsed.yaml - COMMAND - ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${sparse_op_yaml_file} - --output_path ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/sparse_ops.parsed.yaml + COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${static_op_yaml_file} + --output_path ${parsed_op_dir}/legacy/static_ops.parsed.yaml + COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${fused_op_yaml_file} + --output_path ${parsed_op_dir}/fused_ops.parsed.yaml + COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${sparse_op_yaml_file} + --output_path ${parsed_op_dir}/sparse_ops.parsed.yaml COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${sparse_bw_op_yaml_file} - --output_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/sparse_backward.parsed.yaml - --backward + --output_path ${parsed_op_dir}/sparse_backward.parsed.yaml --backward COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${static_bw_op_yaml_file} - --output_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/static_backward.parsed.yaml - --backward + --output_path ${parsed_op_dir}/legacy/static_backward.parsed.yaml --backward COMMAND ${PYTHON_EXECUTABLE} parse_op.py --op_yaml_path ${fused_bw_op_yaml_file} - --output_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/fused_backward.parsed.yaml - --backward RESULTS_VARIABLE _results) + --output_path ${parsed_op_dir}/fused_backward.parsed.yaml --backward + RESULTS_VARIABLE _results) foreach(_result in ${_results}) if(${_result}) message(FATAL_ERROR "op yaml parsing failed, exiting.") @@ -159,16 +149,15 @@ endforeach() # validation of op yamls message("validate op yaml: - ${parsed_op_dir}/ops.parsed.yaml -- ${parsed_op_dir}/backward_ops.parsed.yaml") +- ${parsed_op_dir}/backward.parsed.yaml") execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} cross_validate.py --forward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/ops.parsed.yaml - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/legacy_ops.parsed.yaml - --backward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/backward_ops.parsed.yaml - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/legacy_backward_ops.parsed.yaml + ${parsed_op_dir}/ops.parsed.yaml + ${parsed_op_dir}/inconsistent/dygraph_ops.parsed.yaml --backward_yaml_paths + ${parsed_op_dir}/backward.parsed.yaml + ${parsed_op_dir}/inconsistent/dygraph_backward.parsed.yaml RESULT_VARIABLE _result) if(${_result}) message(FATAL_ERROR "ops validation failed, exiting.") @@ -178,9 +167,8 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} cross_validate.py --forward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/static_ops.parsed.yaml - --backward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/static_backward.parsed.yaml + ${parsed_op_dir}/legacy/static_ops.parsed.yaml --backward_yaml_paths + ${parsed_op_dir}/legacy/static_backward.parsed.yaml RESULT_VARIABLE _result) if(${_result}) message(FATAL_ERROR "static ops validation failed, exiting.") @@ -190,9 +178,8 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} cross_validate.py --forward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/fused_ops.parsed.yaml - --backward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/fused_backward.parsed.yaml + ${parsed_op_dir}/fused_ops.parsed.yaml --backward_yaml_paths + ${parsed_op_dir}/fused_backward.parsed.yaml RESULT_VARIABLE _result) if(${_result}) message(FATAL_ERROR "fused ops validation failed, exiting.") @@ -202,9 +189,8 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} cross_validate.py --forward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/sparse_ops.parsed.yaml - --backward_yaml_paths - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/sparse_backward.parsed.yaml + ${parsed_op_dir}/sparse_ops.parsed.yaml --backward_yaml_paths + ${parsed_op_dir}/sparse_backward.parsed.yaml RESULT_VARIABLE _result) if(${_result}) message(FATAL_ERROR "sparse ops validation failed, exiting.") @@ -219,11 +205,10 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} generate_op.py --ops_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/ops.parsed.yaml --backward_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/backward_ops.parsed.yaml - --op_version_yaml_path - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_version.yaml - --op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml + ${parsed_op_dir}/ops.parsed.yaml --backward_yaml_path + ${parsed_op_dir}/backward.parsed.yaml --op_version_yaml_path + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_version.yaml + --op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml --output_op_path "${generated_op_path_1}.tmp" "${generated_op_path_2}.tmp" "${generated_op_path_3}.tmp" "${generated_op_path_4}.tmp" --output_arg_map_path "${generated_argument_mapping_path}.tmp" @@ -236,12 +221,10 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} generate_op.py --ops_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/static_ops.parsed.yaml - --backward_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/static_backward.parsed.yaml - --op_version_yaml_path - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_version.yaml - --op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml + ${parsed_op_dir}/legacy/static_ops.parsed.yaml --backward_yaml_path + ${parsed_op_dir}/legacy/static_backward.parsed.yaml --op_version_yaml_path + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_version.yaml + --op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml --output_op_path "${generated_static_op_path}.tmp" --output_arg_map_path "${generated_static_argument_mapping_path}.tmp" RESULT_VARIABLE _result) @@ -253,12 +236,10 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} generate_op.py --ops_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/fused_ops.parsed.yaml - --backward_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/fused_backward.parsed.yaml - --op_version_yaml_path - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_version.yaml - --op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml + ${parsed_op_dir}/fused_ops.parsed.yaml --backward_yaml_path + ${parsed_op_dir}/fused_backward.parsed.yaml --op_version_yaml_path + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_version.yaml + --op_compat_yaml_path ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml --output_op_path "${generated_fused_op_path}.tmp" --output_arg_map_path "${generated_fused_argument_mapping_path}.tmp" RESULT_VARIABLE _result) @@ -270,10 +251,9 @@ execute_process( WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator COMMAND ${PYTHON_EXECUTABLE} generate_sparse_op.py --ops_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/sparse_ops.parsed.yaml - --backward_ops_yaml_path - ${CMAKE_CURRENT_BINARY_DIR}/parsed_ops/sparse_backward.parsed.yaml - --output_op_path "${generated_sparse_ops_path}.tmp" --output_arg_map_path + ${parsed_op_dir}/sparse_ops.parsed.yaml --backward_ops_yaml_path + ${parsed_op_dir}/sparse_backward.parsed.yaml --output_op_path + "${generated_sparse_ops_path}.tmp" --output_arg_map_path "${generated_sparse_argument_mapping_path}.tmp" RESULT_VARIABLE _result) if(${_result}) @@ -326,7 +306,7 @@ endif() # op extra info file set(ops_extra_info_gen_file ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/generator/ops_extra_info_gen.py) -set(op_compat_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) +set(op_compat_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml) set(ops_extra_info_file ${CMAKE_SOURCE_DIR}/paddle/fluid/operators/ops_extra_info.cc) diff --git a/paddle/fluid/operators/generator/ops_extra_info_gen.py b/paddle/fluid/operators/generator/ops_extra_info_gen.py index a6482908ba631..ea994d34751b0 100644 --- a/paddle/fluid/operators/generator/ops_extra_info_gen.py +++ b/paddle/fluid/operators/generator/ops_extra_info_gen.py @@ -142,7 +142,7 @@ def main(): parser.add_argument( '--op_compat_yaml_path', help='path to api compat yaml file', - default='paddle/phi/api/yaml/op_compat.yaml', + default='paddle/phi/ops/yaml/op_compat.yaml', ) parser.add_argument( diff --git a/paddle/fluid/operators/generator/templates/op.c.j2 b/paddle/fluid/operators/generator/templates/op.c.j2 index 7c5eaa98223fb..1aa08041c4aff 100644 --- a/paddle/fluid/operators/generator/templates/op.c.j2 +++ b/paddle/fluid/operators/generator/templates/op.c.j2 @@ -1,5 +1,5 @@ {% from "operator_utils.c.j2" import op_maker, backward_op_maker, backward_op_reused_maker, operator, register_op_with_components, register_op_version, composite_grad_op_maker %} -// this file is generated by paddle/phi/api/yaml/generator/generate_op.py, do not edit. +// this file is generated by paddle/phi/api/generator/generate_op.py, do not edit. #include #include "paddle/fluid/framework/convert_utils.h" #include "paddle/fluid/framework/infershape_utils.h" diff --git a/paddle/fluid/operators/generator/templates/sparse_ks.c.j2 b/paddle/fluid/operators/generator/templates/sparse_ks.c.j2 index 66eba5ecc298e..5e2c85899f7cf 100644 --- a/paddle/fluid/operators/generator/templates/sparse_ks.c.j2 +++ b/paddle/fluid/operators/generator/templates/sparse_ks.c.j2 @@ -1,5 +1,5 @@ {% from "operator_utils.c.j2" import sparse_op_name_map, register_name_map, register_base_kernel_name %} -// this file is generated by paddle/phi/api/yaml/generator/generate_op.py, do not edit. +// this file is generated by paddle/phi/api/generator/generate_op.py, do not edit. #include "paddle/phi/core/compat/op_utils.h" #include "paddle/utils/small_vector.h" diff --git a/paddle/fluid/operators/generator/templates/sparse_op.c.j2 b/paddle/fluid/operators/generator/templates/sparse_op.c.j2 index 553cea9a57653..b7a81a7dd2e73 100644 --- a/paddle/fluid/operators/generator/templates/sparse_op.c.j2 +++ b/paddle/fluid/operators/generator/templates/sparse_op.c.j2 @@ -1,5 +1,5 @@ {% from "operator_utils.c.j2" import op_maker, backward_op_maker, backward_op_reused_maker, operator, register_op_with_components, register_op_version %} -// this file is generated by paddle/phi/api/yaml/generator/generate_op.py, do not edit. +// this file is generated by paddle/phi/api/generator/generate_op.py, do not edit. #include #include "paddle/fluid/framework/infershape_utils.h" #include "paddle/fluid/framework/op_registry.h" diff --git a/paddle/fluid/pir/dialect/CMakeLists.txt b/paddle/fluid/pir/dialect/CMakeLists.txt index 78968aaee3e95..044fe96366c9d 100644 --- a/paddle/fluid/pir/dialect/CMakeLists.txt +++ b/paddle/fluid/pir/dialect/CMakeLists.txt @@ -1,86 +1,70 @@ -set(PD_DIALECT_SOURCE_DIR - "${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir") +set(PIR_DIALECT_BINARY_DIR + ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir) # Generate pd_op_dialect files defining op using op_gen_file -set(op_gen_parsed_yaml_file +set(op_parse_file ${PADDLE_SOURCE_DIR}/paddle/fluid/operators/generator/parse_op.py) - set(op_gen_file ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/op_generator/op_gen.py) -set(op_compat_yaml_file ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) +set(ops_yaml_dir ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml) +set(parsed_op_dir ${PADDLE_BINARY_DIR}/paddle/phi/ops/yaml) + +set(op_compat_yaml_file ${ops_yaml_dir}/op_compat.yaml) # YAML files for defining operators -set(op_fwd_yaml - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/ops.parsed.yaml -) -set(op_bwd_yaml - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/backward_ops.parsed.yaml -) -set(fused_op_fwd_yaml - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_ops.parsed.yaml -) -set(fused_op_bwd_yaml - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_backward.parsed.yaml -) -set(pir_op_fwd_src_yaml - ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/ops.yaml) -set(pir_op_bwd_src_yaml - ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml) -set(pir_update_op_fwd_src_yaml - ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/update_ops.yaml) - -set(parsed_op_dir - ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir/generated) -set(pir_op_fwd_yaml ${parsed_op_dir}/ops.parsed.yaml) -set(pir_op_bwd_yaml ${parsed_op_dir}/ops_backward.parsed.yaml) -set(pir_update_op_fwd_yaml ${parsed_op_dir}/update_ops.parsed.yaml) +set(op_fwd_yaml ${parsed_op_dir}/ops.parsed.yaml) +set(op_bwd_yaml ${parsed_op_dir}/backward.parsed.yaml) +set(fused_op_fwd_yaml ${parsed_op_dir}/fused_ops.parsed.yaml) +set(fused_op_bwd_yaml ${parsed_op_dir}/fused_backward.parsed.yaml) +set(pir_op_fwd_src_yaml ${ops_yaml_dir}/inconsistent/static_ops.yaml) +set(pir_op_bwd_src_yaml ${ops_yaml_dir}/inconsistent/static_backward.yaml) +set(pir_update_op_fwd_src_yaml ${ops_yaml_dir}/inconsistent/update_ops.yaml) + +set(pir_op_fwd_yaml ${parsed_op_dir}/inconsistent/static_ops.parsed.yaml) +set(pir_op_bwd_yaml ${parsed_op_dir}/inconsistent/static_backward.parsed.yaml) +set(pir_update_op_fwd_yaml ${parsed_op_dir}/inconsistent/update_ops.parsed.yaml) # SRC files for defining operators set(op_namespace paddle,dialect) set(dialect_name pd_op) -set(op_header_file ${PD_DIALECT_SOURCE_DIR}/pd_op.h) +set(op_header_file ${PIR_DIALECT_BINARY_DIR}/pd_op.h) set(op_header_file_tmp ${op_header_file}.tmp) -set(op_info_file ${PD_DIALECT_SOURCE_DIR}/pd_op_info.cc) +set(op_info_file ${PIR_DIALECT_BINARY_DIR}/pd_op_info.cc) set(op_info_file_tmp ${op_info_file}.tmp) -set(op_vjp_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op_vjp.cc) +set(op_vjp_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op_vjp.cc) set(op_vjp_source_file_tmp ${op_vjp_source_file}.tmp) -set(op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op.cc) +set(op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op.cc) set(op_source_file_tmp ${op_source_file}.tmp) -set(bwd_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op_bwd.cc) +set(bwd_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op_bwd.cc) set(bwd_op_source_file_tmp ${bwd_op_source_file}.tmp) -set(fused_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op_fused.cc) +set(fused_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op_fused.cc) set(fused_op_source_file_tmp ${fused_op_source_file}.tmp) -set(bwd_fused_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op_fused_bwd.cc) +set(bwd_fused_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op_fused_bwd.cc) set(bwd_fused_op_source_file_tmp ${bwd_fused_op_source_file}.tmp) -set(pir_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_pir_op.cc) +set(pir_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_pir_op.cc) set(pir_op_source_file_tmp ${pir_op_source_file}.tmp) -set(pir_bwd_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_pir_op_bwd.cc) +set(pir_bwd_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_pir_op_bwd.cc) set(pir_bwd_op_source_file_tmp ${pir_bwd_op_source_file}.tmp) -set(pir_update_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_pir_op_update.cc) +set(pir_update_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_pir_op_update.cc) set(pir_update_op_source_file_tmp ${pir_update_op_source_file}.tmp) # YAML files for defining sparse operators -set(pir_op_fwd_sparse_src_yaml - ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_ops.yaml) -set(pir_op_bwd_sparse_src_yaml - ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_backward.yaml) - set(pir_op_fwd_sparse_yaml ${parsed_op_dir}/sparse_ops.parsed.yaml) set(pir_op_bfd_sparse_yaml ${parsed_op_dir}/sparse_backward.parsed.yaml) # SRC files for defining sparse operators -set(sparse_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op_sparse.cc) -set(bwd_sparse_op_source_file ${PD_DIALECT_SOURCE_DIR}/pd_op_sparse_bwd.cc) +set(sparse_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op_sparse.cc) +set(bwd_sparse_op_source_file ${PIR_DIALECT_BINARY_DIR}/pd_op_sparse_bwd.cc) set(sparse_op_source_file_tmp ${sparse_op_source_file}.tmp) set(bwd_sparse_op_source_file_tmp ${bwd_sparse_op_source_file}.tmp) @@ -97,21 +81,15 @@ set(op_vjp_src_file_tmp ${op_vjp_source_file_tmp}) # Auto code gen execute_process( - COMMAND ${CMAKE_COMMAND} -E make_directory ${parsed_op_dir} - COMMAND ${PYTHON_EXECUTABLE} ${op_gen_parsed_yaml_file} --op_yaml_path + COMMAND ${PYTHON_EXECUTABLE} ${op_parse_file} --op_yaml_path ${pir_op_fwd_src_yaml} --output_path ${pir_op_fwd_yaml} - COMMAND ${PYTHON_EXECUTABLE} ${op_gen_parsed_yaml_file} --op_yaml_path + COMMAND ${PYTHON_EXECUTABLE} ${op_parse_file} --op_yaml_path ${pir_update_op_fwd_src_yaml} --output_path ${pir_update_op_fwd_yaml} - COMMAND ${PYTHON_EXECUTABLE} ${op_gen_parsed_yaml_file} --op_yaml_path - ${pir_op_bwd_src_yaml} --output_path ${pir_op_bwd_yaml} --backward - COMMAND ${PYTHON_EXECUTABLE} ${op_gen_parsed_yaml_file} --op_yaml_path - ${pir_op_fwd_sparse_src_yaml} --output_path ${pir_op_fwd_sparse_yaml} - COMMAND - ${PYTHON_EXECUTABLE} ${op_gen_parsed_yaml_file} --op_yaml_path - ${pir_op_bwd_sparse_src_yaml} --output_path ${pir_op_bfd_sparse_yaml} - --backward) + COMMAND ${PYTHON_EXECUTABLE} ${op_parse_file} --op_yaml_path + ${pir_op_bwd_src_yaml} --output_path ${pir_op_bwd_yaml} --backward) execute_process( + COMMAND ${CMAKE_COMMAND} -E make_directory ${PIR_DIALECT_BINARY_DIR} COMMAND ${PYTHON_EXECUTABLE} ${op_gen_file} --op_yaml_files ${op_yaml_files} --op_compat_yaml_file ${op_compat_yaml_file} --namespaces ${op_namespace} @@ -135,27 +113,26 @@ set(generated_files_pd_op "${bwd_sparse_op_source_file}") if(WITH_ONEDNN) - set(pir_op_onednn_yaml ${parsed_op_dir}/onednn.parsed.yaml) + set(pir_op_onednn_yaml + ${parsed_op_dir}/inconsistent/onednn_static.parsed.yaml) - set(pd_onednn_op_yaml_file - ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/onednn.yaml) + set(pd_onednn_op_yaml_file ${ops_yaml_dir}/inconsistent/onednn_static.yaml) set(pd_ops_onednn_extra_yaml_file - ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/ops_onednn_extra.yaml - ) + ${ops_yaml_dir}/inconsistent/onednn_ops_extra.yaml) - set(op_onednn_info_file ${PD_DIALECT_SOURCE_DIR}/onednn_op_info.cc) + set(op_onednn_info_file ${PIR_DIALECT_BINARY_DIR}/onednn_op_info.cc) set(op_onednn_info_file_tmp ${op_onednn_info_file}.tmp) set(onednn_op_namespace paddle,onednn,dialect) set(onednn_dialect_name onednn_op) - set(onednn_op_header_file ${PD_DIALECT_SOURCE_DIR}/onednn_op.h) - set(onednn_op_source_file ${PD_DIALECT_SOURCE_DIR}/onednn_op.cc) + set(onednn_op_header_file ${PIR_DIALECT_BINARY_DIR}/onednn_op.h) + set(onednn_op_source_file ${PIR_DIALECT_BINARY_DIR}/onednn_op.cc) set(onednn_op_header_file_tmp ${onednn_op_header_file}.tmp) set(onednn_op_source_file_tmp ${onednn_op_source_file}.tmp) execute_process( - COMMAND ${PYTHON_EXECUTABLE} ${op_gen_parsed_yaml_file} --op_yaml_path + COMMAND ${PYTHON_EXECUTABLE} ${op_parse_file} --op_yaml_path ${pd_onednn_op_yaml_file} --output_path ${pir_op_onednn_yaml}) execute_process( @@ -176,8 +153,8 @@ set(api_gen_yaml_files ) set(api_gen_file ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/op_generator/api_gen.py) -set(api_header_file ${PD_DIALECT_SOURCE_DIR}/pd_api.h) -set(api_source_file ${PD_DIALECT_SOURCE_DIR}/pd_api.cc) +set(api_header_file ${PIR_DIALECT_BINARY_DIR}/pd_api.h) +set(api_source_file ${PIR_DIALECT_BINARY_DIR}/pd_api.cc) set(api_header_file_tmp ${api_header_file}.tmp) set(api_source_file_tmp ${api_source_file}.tmp) @@ -313,8 +290,8 @@ cc_library( DEPS ${op_dialect_deps}) #Note(risemeup1):compile some *.cc files which depend on primitive_vjp_experimental into op_dialect_vjp.a/lib -set(op_decomp_source_file ${PD_DIALECT_SOURCE_DIR}/op_decomp.cc) -# set(op_decomp_vjp_source_file ${PD_DIALECT_SOURCE_DIR}/op_decomp_vjp.cc) +set(op_decomp_source_file ${PIR_DIALECT_BINARY_DIR}/op_decomp.cc) +# set(op_decomp_vjp_source_file ${PIR_DIALECT_BINARY_DIR}/op_decomp_vjp.cc) set(op_dialect_vjp_srcs ${CMAKE_CURRENT_SOURCE_DIR}/operator/ir/manual_op_decomp.cc ${CMAKE_CURRENT_SOURCE_DIR}/operator/ir/manual_op_decomp_vjp.cc diff --git a/paddle/fluid/pir/dialect/operator/ir/.gitignore b/paddle/fluid/pir/dialect/operator/ir/.gitignore deleted file mode 100644 index 83769fe882624..0000000000000 --- a/paddle/fluid/pir/dialect/operator/ir/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -generated/* -generated/** diff --git a/paddle/fluid/pir/drr/CMakeLists.txt b/paddle/fluid/pir/drr/CMakeLists.txt index ded64839dc97f..4375532ff00e1 100644 --- a/paddle/fluid/pir/drr/CMakeLists.txt +++ b/paddle/fluid/pir/drr/CMakeLists.txt @@ -3,26 +3,18 @@ file(GLOB_RECURSE DRR_SRCS "*.cc") set(op_creator_gen_file ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/op_generator/op_creator_drr_gen.py ) -set(op_compat_yaml_file ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml) -set(op_forward_yaml_file - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/ops.parsed.yaml -) -set(op_backward_yaml_file - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/backward_ops.parsed.yaml -) -set(fused_op_forward_yaml_file - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_ops.parsed.yaml -) -set(fused_op_backward_yaml_file - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_backward.parsed.yaml -) +set(op_compat_yaml_file ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml) + +set(parsed_op_dir ${PADDLE_BINARY_DIR}/paddle/phi/ops/yaml) -set(parsed_op_dir - ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir/generated) +set(op_forward_yaml_file ${parsed_op_dir}/ops.parsed.yaml) +set(op_backward_yaml_file ${parsed_op_dir}/backward.parsed.yaml) +set(fused_op_forward_yaml_file ${parsed_op_dir}/fused_ops.parsed.yaml) +set(fused_op_backward_yaml_file ${parsed_op_dir}/fused_backward.parsed.yaml) -set(op_yaml_file_1 ${parsed_op_dir}/ops.parsed.yaml) -set(op_yaml_file_2 ${parsed_op_dir}/ops_backward.parsed.yaml) -set(op_yaml_file_3 ${parsed_op_dir}/update_ops.parsed.yaml) +set(op_yaml_file_1 ${parsed_op_dir}/inconsistent/static_ops.parsed.yaml) +set(op_yaml_file_2 ${parsed_op_dir}/inconsistent/static_backward.parsed.yaml) +set(op_yaml_file_3 ${parsed_op_dir}/inconsistent/update_ops.parsed.yaml) set(op_yaml_files ${op_forward_yaml_file},${op_backward_yaml_file},${fused_op_forward_yaml_file},${fused_op_backward_yaml_file},${op_yaml_file_1},${op_yaml_file_2},${op_yaml_file_3} @@ -90,10 +82,9 @@ endif() if(WITH_ONEDNN) set(onednn_dialect_name onednn_op) set(pir_op_onednn_yaml - ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir/generated/onednn.parsed.yaml - ) + ${parsed_op_dir}/inconsistent/onednn_static.parsed.yaml) set(pd_ops_onednn_extra_yaml_file - ${PADDLE_SOURCE_DIR}/paddle/fluid/pir/dialect/operator/ir/ops_onednn_extra.yaml + ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/onednn_ops_extra.yaml ) set(onednn_op_creator_file ${PADDLE_BINARY_DIR}/paddle/fluid/pir/drr/src/onednn_op_factory_generated.cc diff --git a/paddle/fluid/prim/api/auto_code_generated/CMakeLists.txt b/paddle/fluid/prim/api/auto_code_generated/CMakeLists.txt index 8a941e67b2329..b1fce123fcc38 100644 --- a/paddle/fluid/prim/api/auto_code_generated/CMakeLists.txt +++ b/paddle/fluid/prim/api/auto_code_generated/CMakeLists.txt @@ -1,14 +1,12 @@ -set(api_yaml_path - "${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/ops.parsed.yaml" -) +set(api_yaml_path "${PADDLE_BINARY_DIR}/paddle/phi/ops/yaml/ops.parsed.yaml") set(legacy_api_yaml_path - "${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/legacy_ops.parsed.yaml" + "${PADDLE_BINARY_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_ops.parsed.yaml" ) set(api_compat_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml") + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml") set(api_prim_yaml_path "${PADDLE_SOURCE_DIR}/paddle/fluid/prim/api/api.yaml") set(api_version_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_version.yaml") + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_version.yaml") set(tmp_eager_prim_api_cc_path "${PADDLE_SOURCE_DIR}/paddle/fluid/prim/api/generated_prim/eager_prim_api.cc.tmp" ) @@ -93,7 +91,7 @@ set(tmp_eager_tensor_operants_h_path ${eager_tensor_operants_h_path}.tmp) set(tmp_static_tensor_operants_cc_path ${static_tensor_operants_cc_path}.tmp) set(tmp_static_tensor_operants_h_path ${static_tensor_operants_h_path}.tmp) set(tensor_api_yaml_path - ${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/tensor_operants.yaml) + ${PADDLE_SOURCE_DIR}/paddle/phi/api/lib/tensor_operants.yaml) message("Prim tensor operants code generator") execute_process( diff --git a/paddle/fluid/prim/api/auto_code_generated/eager_gen.py b/paddle/fluid/prim/api/auto_code_generated/eager_gen.py index 558fb153b65ae..dfc949697dcc3 100644 --- a/paddle/fluid/prim/api/auto_code_generated/eager_gen.py +++ b/paddle/fluid/prim/api/auto_code_generated/eager_gen.py @@ -422,7 +422,7 @@ def main(): '--api_yaml_path', help='path to api yaml file', nargs='+', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( diff --git a/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py b/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py index 704ef988b7f50..a5f22c762a177 100644 --- a/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py +++ b/paddle/fluid/prim/api/auto_code_generated/tensor_operants_gen.py @@ -490,7 +490,7 @@ def main(): '--api_yaml_path', help='path to api yaml file', nargs='+', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( diff --git a/paddle/fluid/primitive/codegen/CMakeLists.txt b/paddle/fluid/primitive/codegen/CMakeLists.txt index 1a1f756641505..2f14685f11da0 100644 --- a/paddle/fluid/primitive/codegen/CMakeLists.txt +++ b/paddle/fluid/primitive/codegen/CMakeLists.txt @@ -1,35 +1,21 @@ -set(parsed_yaml_path - "${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops") +set(parsed_yaml_path ${PADDLE_BINARY_DIR}/paddle/phi/ops/yaml) set(fwd_path ${parsed_yaml_path}/ops.parsed.yaml) -set(rev_path ${parsed_yaml_path}/backward_ops.parsed.yaml) -set(fwd_pd_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir/generated/ops.parsed.yaml -) +set(rev_path ${parsed_yaml_path}/backward.parsed.yaml) +set(fwd_pd_op_path ${parsed_yaml_path}/inconsistent/static_ops.parsed.yaml) set(update_fwd_pd_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir/generated/update_ops.parsed.yaml -) -set(rev_pd_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/pir/dialect/operator/ir/generated/ops_backward.parsed.yaml -) -set(fused_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_ops.parsed.yaml -) -set(fused_rev_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/fused_backward.parsed.yaml -) + ${parsed_yaml_path}/inconsistent/update_ops.parsed.yaml) +set(rev_pd_op_path ${parsed_yaml_path}/inconsistent/static_backward.parsed.yaml) +set(fused_op_path ${parsed_yaml_path}/fused_ops.parsed.yaml) +set(fused_rev_op_path ${parsed_yaml_path}/fused_backward.parsed.yaml) -set(sparse_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/sparse_ops.parsed.yaml -) -set(sparse_rev_op_path - ${PADDLE_BINARY_DIR}/paddle/fluid/operators/generator/parsed_ops/sparse_backward.parsed.yaml -) -set(prim_path "${PADDLE_SOURCE_DIR}/paddle/fluid/primitive/primitive.yaml") +set(sparse_op_path ${parsed_yaml_path}/sparse_ops.parsed.yaml) +set(sparse_rev_op_path ${parsed_yaml_path}/sparse_backward.parsed.yaml) +set(prim_path ${PADDLE_SOURCE_DIR}/paddle/fluid/primitive/primitive.yaml) set(templates_dir - "${PADDLE_SOURCE_DIR}/paddle/fluid/primitive/codegen/templates/") -set(compat_path "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml") -set(destination_dir "${PADDLE_BINARY_DIR}/paddle/fluid/primitive/") -set(scripts "${PADDLE_SOURCE_DIR}/paddle/fluid/primitive/codegen/gen.py") + ${PADDLE_SOURCE_DIR}/paddle/fluid/primitive/codegen/templates/) +set(compat_path ${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml) +set(destination_dir ${PADDLE_BINARY_DIR}/paddle/fluid/primitive/) +set(scripts ${PADDLE_SOURCE_DIR}/paddle/fluid/primitive/codegen/gen.py) message("Automatic code generation for paddle/fluid/primitive") execute_process( diff --git a/paddle/phi/CMakeLists.txt b/paddle/phi/CMakeLists.txt index ee4fcec12c257..0788d6994ce3d 100644 --- a/paddle/phi/CMakeLists.txt +++ b/paddle/phi/CMakeLists.txt @@ -32,6 +32,14 @@ if(WITH_CUSTOM_DEVICE) add_subdirectory(capi) endif() +if(WIN32) + file(GLOB_RECURSE YAML_FILE "${CMAKE_CURRENT_SOURCE_DIR}/ops/yaml/*.yaml") + set_property( + DIRECTORY + APPEND + PROPERTY CMAKE_CONFIGURE_DEPENDS ${YAML_FILE}) +endif() + set(PHI_DEPS phi_profiler_proto auto_parallel_proto diff --git a/paddle/phi/README.md b/paddle/phi/README.md index 07c8b0a925846..bd27fa562196e 100644 --- a/paddle/phi/README.md +++ b/paddle/phi/README.md @@ -382,8 +382,8 @@ Described as follows: The automatic generation of the C++ API is generated by parsing the YAML configuration file. The YAML configuration file is divided into: -- Forward API configuration file(`paddle/phi/api/yaml/api.yaml`. After parsing, the generated code file is `paddle/phi/api/include/api.h` and `paddle/phi/api/lib/api.cc`) -- Backward API configuration file(`paddle/phi/api/yaml/backward.yaml`. After parsing, the generated code file is `paddle/phi/api/backward/backward_api.h` and `paddle/phi/api/lib/backward_api.cc`) +- Forward API configuration file(`paddle/phi/ops/yaml/ops.yaml`. After parsing, the generated code file is `paddle/phi/api/include/api.h` and `paddle/phi/api/lib/api.cc`) +- Backward API configuration file(`paddle/phi/ops/yaml/backward.yaml`. After parsing, the generated code file is `paddle/phi/api/backward/backward_api.h` and `paddle/phi/api/lib/backward_api.cc`) The key to C++ API generation lies in the configuration of the YAML file. Taking `matmul` as an example, the forward and backward configuration are as follows: diff --git a/paddle/phi/api/CMakeLists.txt b/paddle/phi/api/CMakeLists.txt index b06c40cf41a6e..1827dfbeb7f64 100644 --- a/paddle/phi/api/CMakeLists.txt +++ b/paddle/phi/api/CMakeLists.txt @@ -1,9 +1,2 @@ add_subdirectory(profiler) add_subdirectory(lib) -if(WIN32) - file(GLOB YAML_FILE "${CMAKE_CURRENT_SOURCE_DIR}/yaml/*.yaml") - set_property( - DIRECTORY - APPEND - PROPERTY CMAKE_CONFIGURE_DEPENDS ${YAML_FILE}) -endif() diff --git a/paddle/phi/api/yaml/generator/api_base.py b/paddle/phi/api/generator/api_base.py similarity index 100% rename from paddle/phi/api/yaml/generator/api_base.py rename to paddle/phi/api/generator/api_base.py diff --git a/paddle/phi/api/yaml/generator/api_gen.py b/paddle/phi/api/generator/api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/api_gen.py rename to paddle/phi/api/generator/api_gen.py index 59eedd4a83de4..1499fee086f3d 100644 --- a/paddle/phi/api/yaml/generator/api_gen.py +++ b/paddle/phi/api/generator/api_gen.py @@ -522,7 +522,7 @@ def main(): '--api_yaml_path', help='path to api yaml file', nargs='+', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/backward_api_gen.py b/paddle/phi/api/generator/backward_api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/backward_api_gen.py rename to paddle/phi/api/generator/backward_api_gen.py index 2201d74093b90..4185f8acb32a6 100644 --- a/paddle/phi/api/yaml/generator/backward_api_gen.py +++ b/paddle/phi/api/generator/backward_api_gen.py @@ -375,7 +375,7 @@ def main(): '--backward_yaml_path', help='path to backward yaml file', nargs='+', - default=['paddle/phi/api/yaml/backward.yaml'], + default=['paddle/phi/ops/yaml/backward.yaml'], ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/dist_api_gen.py b/paddle/phi/api/generator/dist_api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/dist_api_gen.py rename to paddle/phi/api/generator/dist_api_gen.py index 842c1f725dec3..54605d19b256d 100644 --- a/paddle/phi/api/yaml/generator/dist_api_gen.py +++ b/paddle/phi/api/generator/dist_api_gen.py @@ -2032,7 +2032,7 @@ def main(): '--api_yaml_path', help='path to api yaml file', nargs='+', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/dist_bw_api_gen.py b/paddle/phi/api/generator/dist_bw_api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/dist_bw_api_gen.py rename to paddle/phi/api/generator/dist_bw_api_gen.py index 0d2d4d16a2b63..1d57d552d7767 100644 --- a/paddle/phi/api/yaml/generator/dist_bw_api_gen.py +++ b/paddle/phi/api/generator/dist_bw_api_gen.py @@ -526,7 +526,7 @@ def main(): '--backward_yaml_path', help='path to backward yaml file', nargs='+', - default=['paddle/phi/api/yaml/backward.yaml'], + default=['paddle/phi/ops/yaml/backward.yaml'], ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/intermediate_api_gen.py b/paddle/phi/api/generator/intermediate_api_gen.py similarity index 98% rename from paddle/phi/api/yaml/generator/intermediate_api_gen.py rename to paddle/phi/api/generator/intermediate_api_gen.py index 7d449e71414ef..4bf2e7ac8690b 100644 --- a/paddle/phi/api/yaml/generator/intermediate_api_gen.py +++ b/paddle/phi/api/generator/intermediate_api_gen.py @@ -158,13 +158,13 @@ def main(): '--api_yaml_path', nargs='+', help='path to api yaml file', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( '--sparse_api_yaml_path', help='path to sparse api yaml file', - default='paddle/phi/api/yaml/sparse_ops.yaml', + default='paddle/phi/ops/yaml/sparse_ops.yaml', ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/sparse_api_gen.py b/paddle/phi/api/generator/sparse_api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/sparse_api_gen.py rename to paddle/phi/api/generator/sparse_api_gen.py index ba5d2ddf2048f..a0bfe187b250b 100644 --- a/paddle/phi/api/yaml/generator/sparse_api_gen.py +++ b/paddle/phi/api/generator/sparse_api_gen.py @@ -498,7 +498,7 @@ def main(): parser.add_argument( '--api_yaml_path', help='path to sparse api yaml file', - default='paddle/phi/api/yaml/sparse_ops.yaml', + default='paddle/phi/ops/yaml/sparse_ops.yaml', ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/sparse_bw_api_gen.py b/paddle/phi/api/generator/sparse_bw_api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/sparse_bw_api_gen.py rename to paddle/phi/api/generator/sparse_bw_api_gen.py index 90c2caf9c431e..c43c22881a43c 100644 --- a/paddle/phi/api/yaml/generator/sparse_bw_api_gen.py +++ b/paddle/phi/api/generator/sparse_bw_api_gen.py @@ -191,7 +191,7 @@ def main(): parser.add_argument( '--api_yaml_path', help='path to sparse api yaml file', - default='paddle/phi/api/yaml/sparse_backward.yaml', + default='paddle/phi/ops/yaml/sparse_backward.yaml', ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/strings_api_gen.py b/paddle/phi/api/generator/strings_api_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/strings_api_gen.py rename to paddle/phi/api/generator/strings_api_gen.py index 20b51851267cf..a677aba1dee21 100644 --- a/paddle/phi/api/yaml/generator/strings_api_gen.py +++ b/paddle/phi/api/generator/strings_api_gen.py @@ -394,7 +394,7 @@ def main(): parser.add_argument( '--api_yaml_path', help='path to sparse api yaml file', - default='paddle/phi/api/yaml/strings_ops.yaml', + default='paddle/phi/ops/yaml/strings_ops.yaml', ) parser.add_argument( diff --git a/paddle/phi/api/yaml/generator/tensor_operants_gen.py b/paddle/phi/api/generator/tensor_operants_gen.py similarity index 97% rename from paddle/phi/api/yaml/generator/tensor_operants_gen.py rename to paddle/phi/api/generator/tensor_operants_gen.py index ffc74fc2a388f..2f3e41c014d19 100644 --- a/paddle/phi/api/yaml/generator/tensor_operants_gen.py +++ b/paddle/phi/api/generator/tensor_operants_gen.py @@ -33,7 +33,7 @@ specific_ops_map = {"elementwise_pow": "pow"} -operants_base_include = """// Generated by paddle/phi/api/yaml/generator/tensor_operants_gen.py +operants_base_include = """// Generated by paddle/phi/api/generator/tensor_operants_gen.py #pragma once @@ -85,7 +85,7 @@ class TensorOperantsBase { """ -tensor_api_source_include = """// Generated by paddle/phi/api/yaml/generator/tensor_operants_gen.py +tensor_api_source_include = """// Generated by paddle/phi/api/generator/tensor_operants_gen.py #include "paddle/phi/api/include/tensor.h" @@ -220,7 +220,7 @@ class TensorOperantsBase { """ -operants_header_include = """// Generated by paddle/phi/api/yaml/generator/tensor_operants_gen.py +operants_header_include = """// Generated by paddle/phi/api/generator/tensor_operants_gen.py #pragma once @@ -278,7 +278,7 @@ class PhiTensorOperants : public TensorOperantsBase { """ -operants_source_include = """// Generated by paddle/phi/api/yaml/generator/tensor_operants_gen.py +operants_source_include = """// Generated by paddle/phi/api/generator/tensor_operants_gen.py #include "paddle/phi/api/include/tensor_operants.h" @@ -341,7 +341,7 @@ class PhiTensorOperants : public TensorOperantsBase { """ -operants_manager_header_include = """// Generated by paddle/phi/api/yaml/generator/tensor_operants_gen.py +operants_manager_header_include = """// Generated by paddle/phi/api/generator/tensor_operants_gen.py #pragma once @@ -438,7 +438,7 @@ class TEST_API OperantsManager { """ -operants_manager_source_include = """// Generated by paddle/phi/api/yaml/generator/tensor_operants_gen.py +operants_manager_source_include = """// Generated by paddle/phi/api/generator/tensor_operants_gen.py #include "paddle/phi/api/include/operants_manager.h" @@ -736,7 +736,7 @@ def main(): '--api_yaml_path', help='path to api yaml file', nargs='+', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( @@ -778,7 +778,7 @@ def main(): parser.add_argument( '--tensor_api_yaml_path', help='path to tensor_api yaml file', - default='paddle/phi/api/yaml/tensor_operants.yaml', + default='paddle/phi/api/lib/tensor_operants.yaml', ) options = parser.parse_args() diff --git a/paddle/phi/api/yaml/generator/wrapped_infermeta_gen.py b/paddle/phi/api/generator/wrapped_infermeta_gen.py similarity index 99% rename from paddle/phi/api/yaml/generator/wrapped_infermeta_gen.py rename to paddle/phi/api/generator/wrapped_infermeta_gen.py index d9dc4dfc1cc2c..a559a998bfbf3 100644 --- a/paddle/phi/api/yaml/generator/wrapped_infermeta_gen.py +++ b/paddle/phi/api/generator/wrapped_infermeta_gen.py @@ -181,7 +181,7 @@ def main(): '--api_yaml_path', help='path to api yaml file', nargs='+', - default=['paddle/phi/api/yaml/ops.yaml'], + default=['paddle/phi/ops/yaml/ops.yaml'], ) parser.add_argument( '--wrapped_infermeta_header_path', diff --git a/paddle/phi/api/lib/CMakeLists.txt b/paddle/phi/api/lib/CMakeLists.txt index b926e0879b270..eca5130058f7b 100644 --- a/paddle/phi/api/lib/CMakeLists.txt +++ b/paddle/phi/api/lib/CMakeLists.txt @@ -1,24 +1,24 @@ -set(api_gen_base ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/api_base.py) +set(api_gen_base ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/api_base.py) # forward api file -set(api_gen_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/api_gen.py) -set(api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/ops.yaml) +set(api_gen_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/api_gen.py) +set(api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/ops.yaml) set(legacy_api_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_ops.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml) set(api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/api.h) set(api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/api.cc) set(api_header_file_tmp ${api_header_file}.tmp) set(api_source_file_tmp ${api_source_file}.tmp) # dist forward api file set(dist_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/dist_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/dist_api_gen.py) # backward api file set(bw_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/backward_api_gen.py) -set(bw_api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/backward_api_gen.py) +set(bw_api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/backward.yaml) set(legacy_bw_api_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml) set(bw_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/backward_api.h) set(bw_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/backward_api.cc) @@ -26,11 +26,11 @@ set(bw_api_header_file_tmp ${bw_api_header_file}.tmp) set(bw_api_source_file_tmp ${bw_api_source_file}.tmp) # dist backward api file set(dist_bw_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/dist_bw_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/dist_bw_api_gen.py) # dygraph(intermediate) api file set(im_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/intermediate_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/intermediate_api_gen.py) set(dygraph_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/dygraph_api.h) set(dygraph_api_source_file @@ -39,7 +39,7 @@ set(dygraph_api_header_file_tmp ${dygraph_api_header_file}.tmp) set(dygraph_api_source_file_tmp ${dygraph_api_source_file}.tmp) # fused_op forward api file -set(fused_api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/fused_ops.yaml) +set(fused_api_yaml_file ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/fused_ops.yaml) set(fused_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/fused_api.h) set(fused_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/fused_api.cc) @@ -48,9 +48,9 @@ set(fused_api_source_file_tmp ${fused_api_source_file}.tmp) # fused_op backward api file set(fused_bw_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/backward_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/backward_api_gen.py) set(fused_bw_api_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/fused_backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/fused_backward.yaml) set(fused_bw_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/fused_backward_api.h) set(fused_bw_api_source_file @@ -60,9 +60,9 @@ set(fused_bw_api_source_file_tmp ${fused_bw_api_source_file}.tmp) # sparse api file set(sparse_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/sparse_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/sparse_api_gen.py) set(sparse_api_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_ops.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_ops.yaml) set(sparse_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/sparse_api.h) set(sparse_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/sparse_api.cc) @@ -71,9 +71,9 @@ set(sparse_api_source_file_tmp ${sparse_api_source_file}.tmp) # sparse bw api file set(sparse_bw_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/sparse_bw_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/sparse_bw_api_gen.py) set(sparse_bw_api_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/sparse_backward.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/sparse_backward.yaml) set(sparse_bw_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/backward/sparse_bw_api.h) set(sparse_bw_api_source_file @@ -83,9 +83,9 @@ set(sparse_bw_api_source_file_tmp ${sparse_bw_api_source_file}.tmp) # strings api file set(strings_api_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/strings_api_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/strings_api_gen.py) set(strings_api_yaml_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/strings_ops.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/ops/yaml/strings_ops.yaml) set(strings_api_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/strings_api.h) set(strings_api_source_file @@ -95,7 +95,7 @@ set(strings_api_source_file_tmp ${strings_api_source_file}.tmp) # wrapped infermeta file set(wrapped_infermeta_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/wrapped_infermeta_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/wrapped_infermeta_gen.py) set(wrapped_infermeta_header_file ${CMAKE_SOURCE_DIR}/paddle/phi/infermeta/generated.h) set(wrapped_infermeta_source_file @@ -103,9 +103,9 @@ set(wrapped_infermeta_source_file # tensor and tensor operants file set(tensor_api_yaml_path - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/tensor_operants.yaml) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/tensor_operants.yaml) set(tensor_gen_file - ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator/tensor_operants_gen.py) + ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator/tensor_operants_gen.py) set(operants_base_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/include/operants_base.h) set(tensor_api_source_file ${CMAKE_SOURCE_DIR}/paddle/phi/api/lib/tensor_api.cc) @@ -239,7 +239,7 @@ endif() # generate tensor and tensor operants file message("create or copy auto-generated tensor files") execute_process( - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/phi/api/yaml/generator + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/paddle/phi/api/generator COMMAND ${PYTHON_EXECUTABLE} ${tensor_gen_file} --api_yaml_path ${api_yaml_file} ${legacy_api_yaml_file} --operants_base_path ${operants_base_file_tmp} diff --git a/paddle/phi/api/yaml/tensor_operants.yaml b/paddle/phi/api/lib/tensor_operants.yaml similarity index 100% rename from paddle/phi/api/yaml/tensor_operants.yaml rename to paddle/phi/api/lib/tensor_operants.yaml diff --git a/paddle/phi/api/yaml/backward.yaml b/paddle/phi/ops/yaml/backward.yaml similarity index 100% rename from paddle/phi/api/yaml/backward.yaml rename to paddle/phi/ops/yaml/backward.yaml diff --git a/paddle/phi/api/yaml/fused_backward.yaml b/paddle/phi/ops/yaml/fused_backward.yaml similarity index 100% rename from paddle/phi/api/yaml/fused_backward.yaml rename to paddle/phi/ops/yaml/fused_backward.yaml diff --git a/paddle/phi/api/yaml/fused_ops.yaml b/paddle/phi/ops/yaml/fused_ops.yaml similarity index 100% rename from paddle/phi/api/yaml/fused_ops.yaml rename to paddle/phi/ops/yaml/fused_ops.yaml diff --git a/paddle/phi/api/yaml/legacy_backward.yaml b/paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml similarity index 100% rename from paddle/phi/api/yaml/legacy_backward.yaml rename to paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml diff --git a/paddle/phi/api/yaml/legacy_ops.yaml b/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml similarity index 100% rename from paddle/phi/api/yaml/legacy_ops.yaml rename to paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml diff --git a/paddle/fluid/pir/dialect/operator/ir/ops_onednn_extra.yaml b/paddle/phi/ops/yaml/inconsistent/onednn_ops_extra.yaml similarity index 100% rename from paddle/fluid/pir/dialect/operator/ir/ops_onednn_extra.yaml rename to paddle/phi/ops/yaml/inconsistent/onednn_ops_extra.yaml diff --git a/paddle/fluid/pir/dialect/operator/ir/onednn.yaml b/paddle/phi/ops/yaml/inconsistent/onednn_static.yaml similarity index 100% rename from paddle/fluid/pir/dialect/operator/ir/onednn.yaml rename to paddle/phi/ops/yaml/inconsistent/onednn_static.yaml diff --git a/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml b/paddle/phi/ops/yaml/inconsistent/static_backward.yaml similarity index 99% rename from paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml rename to paddle/phi/ops/yaml/inconsistent/static_backward.yaml index 7af521794c82f..03ce9213db440 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops_backward.yaml +++ b/paddle/phi/ops/yaml/inconsistent/static_backward.yaml @@ -1,7 +1,7 @@ # The operators included in this file are: # 1) Operators defined only in PIR, dynamic graphs do not exist; # 2) The definitions of static graphs and dynamic graphs are inconsistent, but the final definition plan has not yet been clarified. -# After the definition is clearly defined, migrate to paddle /fluid/pir/dialect/operator/ir/update_ops.yaml or paddle/phi/api/yaml/ops.yaml +# After the definition is clearly defined, migrate to paddle /fluid/pir/dialect/operator/ir/update_ops.yaml or paddle/phi/ops/yaml/ops.yaml - backward_op : add_double_grad forward : add_grad (Tensor x, Tensor y, Tensor grad_out, int axis = -1) -> Tensor(grad_x), Tensor(grad_y) diff --git a/paddle/fluid/pir/dialect/operator/ir/ops.yaml b/paddle/phi/ops/yaml/inconsistent/static_ops.yaml similarity index 99% rename from paddle/fluid/pir/dialect/operator/ir/ops.yaml rename to paddle/phi/ops/yaml/inconsistent/static_ops.yaml index b79ed19b2b670..0ba713d5314c6 100644 --- a/paddle/fluid/pir/dialect/operator/ir/ops.yaml +++ b/paddle/phi/ops/yaml/inconsistent/static_ops.yaml @@ -1,7 +1,7 @@ # The operators included in this file are: # 1) Operators defined only in PIR, dynamic graphs do not exist; # 2) The definitions of static graphs and dynamic graphs are inconsistent, but the final definition plan has not yet been clarified. -# After the definition is clearly defined, migrate to paddle/fluid/pir/dialect/operator/ir/update_ops.yaml or paddle/phi/api/yaml/ops.yaml +# After the definition is clearly defined, migrate to paddle/phi/ops/yaml/inconsistent/update_ops.yaml or paddle/phi/ops/yaml/ops.yaml - op : add args : (Tensor x, Tensor y) diff --git a/paddle/fluid/pir/dialect/operator/ir/update_ops.yaml b/paddle/phi/ops/yaml/inconsistent/update_ops.yaml similarity index 93% rename from paddle/fluid/pir/dialect/operator/ir/update_ops.yaml rename to paddle/phi/ops/yaml/inconsistent/update_ops.yaml index 10a5429d9a2d5..6110e5a8e1677 100644 --- a/paddle/fluid/pir/dialect/operator/ir/update_ops.yaml +++ b/paddle/phi/ops/yaml/inconsistent/update_ops.yaml @@ -1,7 +1,7 @@ # The operators contained in this file are: # Operators that are inconsistent with the dynamic graph definition currently, # but the final definition scheme of the static graph has been determined, after -# the dynamic graph is simultaneously upgraded, the operators in this file will be migrated to paddle/phi/api/yaml/ops.yaml. +# the dynamic graph is simultaneously upgraded, the operators in this file will be migrated to paddle/phi/ops/yaml/ops.yaml. - op : arange args : (Scalar start, Scalar end, Scalar step, DataType dtype=DataType::FLOAT64, Place place=CPUPlace()) diff --git a/paddle/phi/api/yaml/static_backward.yaml b/paddle/phi/ops/yaml/legacy/static_backward.yaml similarity index 100% rename from paddle/phi/api/yaml/static_backward.yaml rename to paddle/phi/ops/yaml/legacy/static_backward.yaml diff --git a/paddle/phi/api/yaml/static_ops.yaml b/paddle/phi/ops/yaml/legacy/static_ops.yaml similarity index 100% rename from paddle/phi/api/yaml/static_ops.yaml rename to paddle/phi/ops/yaml/legacy/static_ops.yaml diff --git a/paddle/phi/api/yaml/op_compat.yaml b/paddle/phi/ops/yaml/op_compat.yaml similarity index 100% rename from paddle/phi/api/yaml/op_compat.yaml rename to paddle/phi/ops/yaml/op_compat.yaml diff --git a/paddle/phi/api/yaml/op_version.yaml b/paddle/phi/ops/yaml/op_version.yaml similarity index 100% rename from paddle/phi/api/yaml/op_version.yaml rename to paddle/phi/ops/yaml/op_version.yaml diff --git a/paddle/phi/api/yaml/ops.yaml b/paddle/phi/ops/yaml/ops.yaml similarity index 100% rename from paddle/phi/api/yaml/ops.yaml rename to paddle/phi/ops/yaml/ops.yaml diff --git a/paddle/phi/api/yaml/sparse_backward.yaml b/paddle/phi/ops/yaml/sparse_backward.yaml similarity index 100% rename from paddle/phi/api/yaml/sparse_backward.yaml rename to paddle/phi/ops/yaml/sparse_backward.yaml diff --git a/paddle/phi/api/yaml/sparse_ops.yaml b/paddle/phi/ops/yaml/sparse_ops.yaml similarity index 100% rename from paddle/phi/api/yaml/sparse_ops.yaml rename to paddle/phi/ops/yaml/sparse_ops.yaml diff --git a/paddle/phi/api/yaml/strings_ops.yaml b/paddle/phi/ops/yaml/strings_ops.yaml similarity index 100% rename from paddle/phi/api/yaml/strings_ops.yaml rename to paddle/phi/ops/yaml/strings_ops.yaml diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index 934f0978b2dfb..85ed1ca7ce59b 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -67,20 +67,20 @@ set(FLUID_CORE_DEPS ${FLUID_CORE}) add_custom_target(copy_libpaddle ALL DEPENDS ${FLUID_CORE_DEPS}) -# Standard op(phi op) description is defined in ops.yaml and legacy_ops.yaml. +# Standard op(phi op) description is defined in ops.yaml and dygraph_ops.yaml. # When users define composite rules of some nonbasic op, as for definition of args, # they are supposed to refer to standard op description. However, there exists # some gap of description between current op and standard ones. So special dictionary # is needed to record such gap for execution of composite rules. # Todo: this custom_target will be moved to other place. -set(ops_yaml_path "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/ops.yaml") +set(ops_yaml_path "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/ops.yaml") set(ops_legacy_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/legacy_ops.yaml") + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml") set(ops_compat_yaml_path - "${PADDLE_SOURCE_DIR}/paddle/phi/api/yaml/op_compat.yaml") + "${PADDLE_SOURCE_DIR}/paddle/phi/ops/yaml/op_compat.yaml") set(phi_ops_map_path "${PADDLE_SOURCE_DIR}/python/paddle/incubate/autograd/phi_ops_map.py") diff --git a/python/paddle/incubate/autograd/composite_rules.py b/python/paddle/incubate/autograd/composite_rules.py index c96f81b527430..93164ba8d3ad3 100644 --- a/python/paddle/incubate/autograd/composite_rules.py +++ b/python/paddle/incubate/autograd/composite_rules.py @@ -15,7 +15,7 @@ # This file contains composite rules of nonbasic operations. There are some notes: # 1. When define composite rule of some op, you can only use primitive ops defined in primitives.py. # 2. The name and args of target op must be corresponding with standard description of op in -# ops.yaml or legacy_ops.yaml. +# ops.yaml or dygraph_ops.yaml. import functools import operator diff --git a/python/paddle/incubate/autograd/generate_op_map.py b/python/paddle/incubate/autograd/generate_op_map.py index b3fa25f2db25f..64ccf152ea813 100644 --- a/python/paddle/incubate/autograd/generate_op_map.py +++ b/python/paddle/incubate/autograd/generate_op_map.py @@ -28,7 +28,7 @@ def ParseArguments(): ) parser.add_argument('--ops_yaml_path', type=str, help="path to ops.yaml") parser.add_argument( - '--ops_legacy_yaml_path', type=str, help="path to legacy_ops.yaml" + '--ops_legacy_yaml_path', type=str, help="path to dygraph_ops.yaml" ) parser.add_argument( '--ops_compat_yaml_path', type=str, help="path to op_compat.yaml" diff --git a/test/legacy_test/test_registered_phi_kernels.py b/test/legacy_test/test_registered_phi_kernels.py index fc643a2cc0eb0..cc1a89ba87d43 100644 --- a/test/legacy_test/test_registered_phi_kernels.py +++ b/test/legacy_test/test_registered_phi_kernels.py @@ -64,12 +64,12 @@ def setUp(self): root_path = pathlib.Path(__file__).parents[3] ops_yaml_path = [ - 'paddle/phi/api/yaml/ops.yaml', - 'paddle/phi/api/yaml/legacy_ops.yaml', + 'paddle/phi/ops/yaml/ops.yaml', + 'paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml', ] bw_ops_yaml_path = [ - 'paddle/phi/api/yaml/backward.yaml', - 'paddle/phi/api/yaml/legacy_backward.yaml', + 'paddle/phi/ops/yaml/backward.yaml', + 'paddle/phi/ops/yaml/inconsistent/dygraph_backward.yaml', ] for each_ops_yaml in ops_yaml_path: diff --git a/tools/auto_parallel/target_path_lists.sh b/tools/auto_parallel/target_path_lists.sh index fb1c943ff3a79..033479e7d9a57 100644 --- a/tools/auto_parallel/target_path_lists.sh +++ b/tools/auto_parallel/target_path_lists.sh @@ -21,8 +21,8 @@ target_lists_for_semi_auto_ci=( "paddle/fluid/pybind/auto_parallel_py.h" "paddle/phi/infermeta/spmd_rules" "paddle/phi/core/distributed" - "paddle/phi/api/yaml/generator/dist_api_gen.py" - "paddle/phi/api/yaml/generator/dist_bw_api_gen.py" + "paddle/phi/api/generator/dist_api_gen.py" + "paddle/phi/api/generator/dist_bw_api_gen.py" "tools/auto_parallel/target_path_lists.sh" "test/auto_parallel" ) diff --git a/tools/check_api_yaml_same.py b/tools/check_api_yaml_same.py index 2c05fe862ddc6..b2554ba4c45f9 100644 --- a/tools/check_api_yaml_same.py +++ b/tools/check_api_yaml_same.py @@ -26,8 +26,10 @@ def read_yaml_ops(): ops_list = [] - yaml_path = root_path + "/paddle/phi/api/yaml/ops.yaml" - legacy_yaml_path = root_path + "/paddle/phi/api/yaml/legacy_ops.yaml" + yaml_path = root_path + "/paddle/phi/ops/yaml/ops.yaml" + legacy_yaml_path = ( + root_path + "/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml" + ) with open(yaml_path, 'r') as f: ops_list = yaml.load(f, Loader=yaml.FullLoader) @@ -87,8 +89,10 @@ def get_api_diff(dev_api_file, pr_api_file): def get_yaml_diff(branch): - ops_yaml_path = root_path + "/paddle/phi/api/yaml/ops.yaml" - legacy_yaml_path = root_path + "/paddle/phi/api/yaml/legacy_ops.yaml" + ops_yaml_path = root_path + "/paddle/phi/ops/yaml/ops.yaml" + legacy_yaml_path = ( + root_path + "/paddle/phi/ops/yaml/inconsistent/dygraph_ops.yaml" + ) git_cmd = ( "git diff -U0 upstream/" + branch diff --git a/tools/check_file_diff_approvals.sh b/tools/check_file_diff_approvals.sh index 3c705d6a46c55..d637c4f0c3b82 100644 --- a/tools/check_file_diff_approvals.sh +++ b/tools/check_file_diff_approvals.sh @@ -167,15 +167,15 @@ if [ "${HAS_CREATE_NEW_PASS}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then check_approval 1 yuanlehome zyfncg fi -HAS_MODIFIED_API_COMPAT_YAML=`git diff --name-only upstream/$BRANCH | grep "paddle/phi/api/yaml/op_compat.yaml" || true` +HAS_MODIFIED_API_COMPAT_YAML=`git diff --name-only upstream/$BRANCH | grep "paddle/phi/ops/yaml/op_compat.yaml" || true` if [ "${HAS_MODIFIED_API_COMPAT_YAML}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then - echo_line="You must be approved by chenwhql or zyfncg or heavyrain-lzy for paddle/phi/api/yaml/op_compat.yaml changes, which manages the extra params of Op and name mapping between Yaml and OpMaker. In order to ensure compatibility of framework, this file isn't allowed to be modified at will!\n" + echo_line="You must be approved by chenwhql or zyfncg or heavyrain-lzy for paddle/phi/ops/yaml/op_compat.yaml changes, which manages the extra params of Op and name mapping between Yaml and OpMaker. In order to ensure compatibility of framework, this file isn't allowed to be modified at will!\n" check_approval 1 chenwhql zyfncg heavyrain-lzy fi -HAS_MODIFIED_API_FW_BW_YAML=`git diff --name-only upstream/$BRANCH | grep -E "paddle/phi/api/yaml/ops.yaml|paddle/phi/api/yaml/backward.yaml" || true` +HAS_MODIFIED_API_FW_BW_YAML=`git diff --name-only upstream/$BRANCH | grep -E "paddle/phi/ops/yaml/ops.yaml|paddle/phi/ops/yaml/backward.yaml" || true` if [ "${HAS_MODIFIED_API_FW_BW_YAML}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then - echo_line="You must be approved by chenwhql or zyfncg or heavyrain-lzy for paddle/phi/api/yaml/ops.yaml or paddle/phi/api/yaml/backward.yaml changes, which manage the generated code for the C++ OP. You can only change them according to the specification at the begining of this two file.\n" + echo_line="You must be approved by chenwhql or zyfncg or heavyrain-lzy for paddle/phi/ops/yaml/ops.yaml or paddle/phi/ops/yaml/backward.yaml changes, which manage the generated code for the C++ OP. You can only change them according to the specification at the begining of this two file.\n" check_approval 1 chenwhql zyfncg heavyrain-lzy fi @@ -205,9 +205,9 @@ if [ "${HAS_MODIFIED_PIR_INCLUDE_DIR}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then check_approval 1 yuanlehome winter-wang zhangbo9674 fi -HAS_MODIFIED_API_GENE=`git diff --name-only upstream/$BRANCH | grep "paddle/phi/api/yaml/generator" || true` +HAS_MODIFIED_API_GENE=`git diff --name-only upstream/$BRANCH | grep "paddle/phi/api/generator" || true` if [ "${HAS_MODIFIED_API_GENE}" != "" ] && [ "${GIT_PR_ID}" != "" ]; then - echo_line="You must have one RD (zyfncg, chenwhql, YuanRisheng, phlrain, heavyrain-lzy) approval for file changes in paddle/phi/api/yaml/generator, which manages the generated code for C++ API in paddle/phi/api/lib/api.cc.\n" + echo_line="You must have one RD (zyfncg, chenwhql, YuanRisheng, phlrain, heavyrain-lzy) approval for file changes in paddle/phi/api/generator, which manages the generated code for C++ API in paddle/phi/api/lib/api.cc.\n" check_approval 1 zyfncg chenwhql YuanRisheng phlrain heavyrain-lzy fi From fb432fb2a77a029ddecd57448371bc3504b644d1 Mon Sep 17 00:00:00 2001 From: walkalone20 <73780235+walkalone20@users.noreply.github.com> Date: Tue, 21 May 2024 16:56:28 +0800 Subject: [PATCH 08/13] =?UTF-8?q?=E3=80=90Hackathon=206th=20Fundable=20Pro?= =?UTF-8?q?jects=202=20No.22=E3=80=91cppcoreguidelines-pro-type-member-ini?= =?UTF-8?q?t=5F7-part=20(#64374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * member-init-part-7 * minor changes * minor changes * minor changes * minor changes * format --- .../distributed/ps/table/graph/graph_weighted_sampler.cc | 3 +++ paddle/fluid/eager/auto_code_generator/eager_generator.cc | 1 + paddle/fluid/eager/grad_node_info.cc | 3 ++- .../framework/details/share_tensor_buffer_functor.cc | 1 + .../framework/details/threaded_ssa_graph_executor.cc | 7 ++++++- .../instruction/control_flow/select_input_instruction.cc | 5 ++++- paddle/fluid/framework/operator.cc | 4 +++- paddle/fluid/imperative/partial_grad_engine.cc | 3 +++ paddle/fluid/inference/analysis/ir_pass_manager.cc | 2 +- paddle/fluid/inference/tensorrt/test_engine.cc | 4 ++-- .../fluid/memory/allocation/cuda_virtual_mem_allocator.cc | 2 +- .../fluid/memory/allocation/naive_best_fit_allocator.cc | 3 ++- paddle/fluid/pir/dialect/operator/ir/op_dialect.cc | 2 ++ paddle/fluid/platform/denormal.cc | 3 ++- paddle/fluid/platform/device/gpu/gpu_info.cc | 4 ++-- paddle/phi/backends/gpu/gpu_context.cc | 8 +++++++- paddle/phi/core/distributed/nccl_comm_context.cc | 2 +- .../phi/kernels/cpu/weighted_sample_neighbors_kernel.cc | 2 +- 18 files changed, 44 insertions(+), 15 deletions(-) diff --git a/paddle/fluid/distributed/ps/table/graph/graph_weighted_sampler.cc b/paddle/fluid/distributed/ps/table/graph/graph_weighted_sampler.cc index 70942df5f24c4..86871154ca23f 100644 --- a/paddle/fluid/distributed/ps/table/graph/graph_weighted_sampler.cc +++ b/paddle/fluid/distributed/ps/table/graph/graph_weighted_sampler.cc @@ -62,6 +62,9 @@ WeightedSampler::WeightedSampler() { left = nullptr; right = nullptr; edges = nullptr; + weight = 0; + count = 0; + idx = 0; } WeightedSampler::~WeightedSampler() { diff --git a/paddle/fluid/eager/auto_code_generator/eager_generator.cc b/paddle/fluid/eager/auto_code_generator/eager_generator.cc index 52c2f9b9ef123..e2522a83feaae 100644 --- a/paddle/fluid/eager/auto_code_generator/eager_generator.cc +++ b/paddle/fluid/eager/auto_code_generator/eager_generator.cc @@ -266,6 +266,7 @@ class GradNodeGenerationInfo { }; public: + GradNodeGenerationInfo() : op_base_infos_() {} const std::string& GetFwdOpType() const { return fwd_op_type_; } void SetFwdOpType(const std::string& op_type) { fwd_op_type_ = op_type; } diff --git a/paddle/fluid/eager/grad_node_info.cc b/paddle/fluid/eager/grad_node_info.cc index 6ec5a17b9361d..9302304ea9cdc 100644 --- a/paddle/fluid/eager/grad_node_info.cc +++ b/paddle/fluid/eager/grad_node_info.cc @@ -62,7 +62,8 @@ static void CheckTensor(const paddle::Tensor& pre, const paddle::Tensor& post) { } } -GradNodeBase::GradNodeBase(size_t bwd_in_slot_num, size_t bwd_out_slot_num) { +GradNodeBase::GradNodeBase(size_t bwd_in_slot_num, size_t bwd_out_slot_num) + : bwd_out_meta_(), bwd_in_meta_(), gradient_hooks_() { VLOG(7) << "Construct GradNodeBase"; bwd_in_meta_.resize(bwd_in_slot_num); bwd_out_meta_.resize(bwd_out_slot_num); diff --git a/paddle/fluid/framework/details/share_tensor_buffer_functor.cc b/paddle/fluid/framework/details/share_tensor_buffer_functor.cc index 5faa762e2b2ce..6045770b5378c 100644 --- a/paddle/fluid/framework/details/share_tensor_buffer_functor.cc +++ b/paddle/fluid/framework/details/share_tensor_buffer_functor.cc @@ -51,6 +51,7 @@ ShareTensorBufferFunctor::ShareTensorBufferFunctor( op_type_(op_type), in_var_infos_(in_var_infos), out_var_names_(out_var_names), + in_out_vars_(), is_variant_scope_(is_variant_scope), share_dims_and_dtype_(share_dims_and_dtype) { PADDLE_ENFORCE_EQ(in_var_infos_.size(), diff --git a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc index 0397f87f6649e..6697a33e3e1d6 100644 --- a/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc +++ b/paddle/fluid/framework/details/threaded_ssa_graph_executor.cc @@ -34,10 +34,15 @@ ThreadedSSAGraphExecutor::ThreadedSSAGraphExecutor( local_scopes_(local_scopes), local_exec_scopes_(local_exec_scopes), places_(places), + fetch_ctxs_(), + op_deps_(nullptr), + op_deps_futures_(), strategy_(strategy), + run_op_futures_(), prepare_pool_(1), pool_(strategy.num_threads_ >= 2 ? new ::ThreadPool(strategy.num_threads_) - : nullptr) { + : nullptr), + traced_ops_() { platform::EmplaceDeviceContexts( &fetch_ctxs_, places, diff --git a/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc b/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc index 987edeb97eda0..f51bba6eb2468 100644 --- a/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc +++ b/paddle/fluid/framework/new_executor/instruction/control_flow/select_input_instruction.cc @@ -25,7 +25,10 @@ SelectInputInstruction::SelectInputInstruction( const platform::Place &place, ::pir::Operation *op, ValueExecutionInfo *value_exe_info) - : InstructionBase(id, place), op_(op) { + : InstructionBase(id, place), + op_(op), + type_(OpFuncType::kCpuSync), + inputs_() { VLOG(6) << "construct select_input instruction"; std::unordered_map> inputs; diff --git a/paddle/fluid/framework/operator.cc b/paddle/fluid/framework/operator.cc index d5dab65d18d15..ae4a5be013e97 100644 --- a/paddle/fluid/framework/operator.cc +++ b/paddle/fluid/framework/operator.cc @@ -1001,7 +1001,9 @@ OperatorBase::OperatorBase(const std::string& type, outputs_(outputs), attrs_(attrs), // NOTE(zjl): why op_info may be nullptr? - info_(OpInfoMap::Instance().GetNullable(type)) { + info_(OpInfoMap::Instance().GetNullable(type)), + output_hookfuncs_(), + input_hookfuncs_() { // In dygraph mode, all the OperatorBase will be constructed by function: // framework::OpRegistry::CreateOp(type, {}, {}, {}, false). // Inputs, outputs and attrs will be set to empty map diff --git a/paddle/fluid/imperative/partial_grad_engine.cc b/paddle/fluid/imperative/partial_grad_engine.cc index 5ae9e43752491..5d0e9d6e3bcb8 100644 --- a/paddle/fluid/imperative/partial_grad_engine.cc +++ b/paddle/fluid/imperative/partial_grad_engine.cc @@ -354,6 +354,8 @@ class GradientAccumulationInfo { bool sort_gradient, bool create_graph) : mapped_grad_var_(var.get()), + accumulator_(nullptr), + partial_grad_grads_(), sort_gradient_(sort_gradient), create_graph_(create_graph) {} @@ -468,6 +470,7 @@ class ReadyGradVarInfoMap { }; public: + ReadyGradVarInfoMap() : vars_(), target_vars_() {} void IncreaseRefCnt(const VariableWrapper *var) { ++(vars_[var].total_ref_cnt); } diff --git a/paddle/fluid/inference/analysis/ir_pass_manager.cc b/paddle/fluid/inference/analysis/ir_pass_manager.cc index 6598ede3a984b..abb6c491af3f1 100644 --- a/paddle/fluid/inference/analysis/ir_pass_manager.cc +++ b/paddle/fluid/inference/analysis/ir_pass_manager.cc @@ -36,7 +36,7 @@ namespace analysis { using string::PrettyLogEndl; using string::Style; -IRPassManager::IRPassManager(Argument *argument) { +IRPassManager::IRPassManager(Argument *argument) : passes_() { disable_logs_ = argument->disable_logs(); ARGUMENT_CHECK_FIELD(argument, ir_analysis_passes); diff --git a/paddle/fluid/inference/tensorrt/test_engine.cc b/paddle/fluid/inference/tensorrt/test_engine.cc index 8d64d0d089144..2f67fdef7f89a 100644 --- a/paddle/fluid/inference/tensorrt/test_engine.cc +++ b/paddle/fluid/inference/tensorrt/test_engine.cc @@ -69,8 +69,8 @@ class TensorRTEngineTest : public ::testing::Test { protected: phi::DenseTensor input_; phi::DenseTensor output_; - std::unique_ptr engine_; - phi::GPUContext *ctx_; + std::unique_ptr engine_ = nullptr; + phi::GPUContext *ctx_ = nullptr; }; TEST_F(TensorRTEngineTest, add_layer) { diff --git a/paddle/fluid/memory/allocation/cuda_virtual_mem_allocator.cc b/paddle/fluid/memory/allocation/cuda_virtual_mem_allocator.cc index 85c59a2f8d653..36140146a0d9d 100644 --- a/paddle/fluid/memory/allocation/cuda_virtual_mem_allocator.cc +++ b/paddle/fluid/memory/allocation/cuda_virtual_mem_allocator.cc @@ -35,7 +35,7 @@ namespace allocation { CUDAVirtualMemAllocator::CUDAVirtualMemAllocator( const platform::CUDAPlace& place) - : place_(place) { + : place_(place), virtual_mem_base_(0), prop_{} { CUmemAllocationProp prop = {}; // Setup the properties common for all the chunks diff --git a/paddle/fluid/memory/allocation/naive_best_fit_allocator.cc b/paddle/fluid/memory/allocation/naive_best_fit_allocator.cc index b53e951f516f0..0506e80738662 100644 --- a/paddle/fluid/memory/allocation/naive_best_fit_allocator.cc +++ b/paddle/fluid/memory/allocation/naive_best_fit_allocator.cc @@ -216,7 +216,8 @@ size_t Used(const platform::XPUPlace &place) { #if defined(PADDLE_WITH_CUDA) || defined(PADDLE_WITH_HIP) class GPUBuddyAllocatorList { private: - GPUBuddyAllocatorList() : devices_(platform::GetSelectedDevices()) { + GPUBuddyAllocatorList() + : devices_(platform::GetSelectedDevices()), init_flags_(), allocators_() { auto gpu_num = devices_.size(); allocators_.resize(gpu_num); init_flags_.reserve(gpu_num); diff --git a/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc b/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc index 8bda40b53772c..5b40e0344c282 100644 --- a/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc +++ b/paddle/fluid/pir/dialect/operator/ir/op_dialect.cc @@ -461,6 +461,8 @@ class AttributeManager { return instance; } + AttributeManager() : char_pointers_(), pointers_size_() {} + ~AttributeManager() { for (size_t i = 0; i < char_pointers_.size(); i++) { for (size_t j = 0; j < pointers_size_[i]; j++) { diff --git a/paddle/fluid/platform/denormal.cc b/paddle/fluid/platform/denormal.cc index eca106af3dd67..d6a0e749f93c8 100644 --- a/paddle/fluid/platform/denormal.cc +++ b/paddle/fluid/platform/denormal.cc @@ -70,7 +70,8 @@ static std::pair GetDenormalState() { return {false, false}; } -ScopedRestoreFlushDenormalState::ScopedRestoreFlushDenormalState() { +ScopedRestoreFlushDenormalState::ScopedRestoreFlushDenormalState() + : flush_zero_mode_(false), denormals_zero_mode_(false) { std::tie(flush_zero_mode_, denormals_zero_mode_) = GetDenormalState(); } diff --git a/paddle/fluid/platform/device/gpu/gpu_info.cc b/paddle/fluid/platform/device/gpu/gpu_info.cc index 73704b04cf90b..358d52d03d31b 100644 --- a/paddle/fluid/platform/device/gpu/gpu_info.cc +++ b/paddle/fluid/platform/device/gpu/gpu_info.cc @@ -504,11 +504,11 @@ class RecordedGpuMallocHelper { std::atomic cur_size_{0}; #if defined(PADDLE_WITH_CUDA) && (CUDA_VERSION >= 11020) - cudaMemPool_t memPool_; + cudaMemPool_t memPool_ = nullptr; static std::once_flag set_cudamempoolattr_once_flag_; #endif #if defined(PADDLE_WITH_HIP) - hipMemPool_t memPool_; + hipMemPool_t memPool_ = nullptr; static std::once_flag set_cudamempoolattr_once_flag_; #endif diff --git a/paddle/phi/backends/gpu/gpu_context.cc b/paddle/phi/backends/gpu/gpu_context.cc index fe952585f547d..26c1f7afbfbb3 100644 --- a/paddle/phi/backends/gpu/gpu_context.cc +++ b/paddle/phi/backends/gpu/gpu_context.cc @@ -63,7 +63,13 @@ namespace internal { class EigenGpuStreamDevice : public Eigen::StreamInterface { public: - EigenGpuStreamDevice() : scratch_(nullptr), semaphore_(nullptr) { + EigenGpuStreamDevice() + : stream_(nullptr), + allocator_(nullptr), + device_prop_(nullptr), + scratch_(nullptr), + semaphore_(nullptr), + allocations_() { Eigen::initializeDeviceProp(); } ~EigenGpuStreamDevice() override = default; diff --git a/paddle/phi/core/distributed/nccl_comm_context.cc b/paddle/phi/core/distributed/nccl_comm_context.cc index bfa9a494b327a..31740d95b7b24 100644 --- a/paddle/phi/core/distributed/nccl_comm_context.cc +++ b/paddle/phi/core/distributed/nccl_comm_context.cc @@ -34,7 +34,7 @@ NCCLCommContext::NCCLCommContext(int rank, int size, ncclUniqueId nccl_id, int nccl_comm_init_option) - : CommContext(rank, size) { + : CommContext(rank, size), nccl_version_(0), nccl_comm_(nullptr) { if (nccl_comm_init_option > 0 && phi::dynload::ncclCommInitRank2.IsValid()) { LOG(WARNING) << "Creating modified qp with ncclCommInitRank2."; NCCL_CHECK(phi::dynload::ncclCommInitRank2( diff --git a/paddle/phi/kernels/cpu/weighted_sample_neighbors_kernel.cc b/paddle/phi/kernels/cpu/weighted_sample_neighbors_kernel.cc index d59960a79377a..f6dc047b5be72 100644 --- a/paddle/phi/kernels/cpu/weighted_sample_neighbors_kernel.cc +++ b/paddle/phi/kernels/cpu/weighted_sample_neighbors_kernel.cc @@ -36,7 +36,7 @@ struct GraphWeightedNode { GraphWeightedNode(T node_id, float weight_key, T eid = 0) : node_id(node_id), weight_key(weight_key), eid(eid) {} - GraphWeightedNode(const GraphWeightedNode& other) { + GraphWeightedNode(const GraphWeightedNode& other) : weight_key(0) { if (this != &other) { this->node_id = other.node_id; this->weight_key = other.weight_key; From fba46752c14af1661ce4d3b5ee75f8530707c5c6 Mon Sep 17 00:00:00 2001 From: AyaseNana <49900969+NKNaN@users.noreply.github.com> Date: Tue, 21 May 2024 17:17:19 +0800 Subject: [PATCH 09/13] =?UTF-8?q?=E3=80=90Hackathon=206th=20No.11=E3=80=91?= =?UTF-8?q?=E4=B8=BA=20Paddle=20=E6=96=B0=E5=A2=9E=20bernoulli=5F=20=20API?= =?UTF-8?q?=20-=20part=20(#64252)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add bernoulli_ * update * update docs * fix typo * update code and test * add test case for backward * add test broadcast error and update docs --- python/paddle/__init__.py | 2 + python/paddle/tensor/__init__.py | 2 + python/paddle/tensor/random.py | 52 ++++++++++++ test/deprecated/legacy_test/test_inplace.py | 92 +++++++++++++++++++++ 4 files changed, 148 insertions(+) diff --git a/python/paddle/__init__.py b/python/paddle/__init__.py index a9e3345474f4c..c7e301779108a 100644 --- a/python/paddle/__init__.py +++ b/python/paddle/__init__.py @@ -516,6 +516,7 @@ ) from .tensor.random import ( bernoulli, + bernoulli_, binomial, check_shape, multinomial, @@ -808,6 +809,7 @@ 'expm1', 'expm1_', 'bernoulli', + 'bernoulli_', 'binomial', 'poisson', 'standard_gamma', diff --git a/python/paddle/tensor/__init__.py b/python/paddle/tensor/__init__.py index 53f409e488971..4de5e392a8493 100644 --- a/python/paddle/tensor/__init__.py +++ b/python/paddle/tensor/__init__.py @@ -402,6 +402,7 @@ vander, ) from .random import ( # noqa: F401 + bernoulli_, binomial, exponential_, multinomial, @@ -751,6 +752,7 @@ 'put_along_axis', 'select_scatter', 'put_along_axis_', + 'bernoulli_', 'exponential_', 'heaviside', 'index_add', diff --git a/python/paddle/tensor/random.py b/python/paddle/tensor/random.py index 50e835470c97b..93a82e1e97cb9 100644 --- a/python/paddle/tensor/random.py +++ b/python/paddle/tensor/random.py @@ -104,6 +104,58 @@ def bernoulli(x, name=None): return out +@dygraph_only +def bernoulli_(x, p=0.5, name=None): + """ + This is the inplace version of api ``bernoulli``, which returns a Tensor filled + with random values sampled from a bernoulli distribution. The output Tensor will + be inplaced with input ``x``. Please refer to :ref:`api_tensor_bernoulli`. + + Args: + x(Tensor): The input tensor to be filled with random values. + p (float|Tensor, optional): The success probability parameter of the output Tensor's bernoulli distribution. + If ``p`` is float, all elements of the output Tensor shared the same success probability. + If ``p`` is a Tensor, it has per-element success probabilities, and the shape should be broadcastable to ``x``. + Default is 0.5 + name(str, optional): The default value is None. Normally there is no + need for user to set this property. For more information, please + refer to :ref:`api_guide_Name`. + + Returns: + A Tensor filled with random values sampled from the bernoulli distribution with success probability ``p`` . + + Examples: + .. code-block:: python + + >>> import paddle + >>> x = paddle.randn([3, 4]) + >>> x.bernoulli_() + >>> # doctest: +SKIP('random check') + >>> print(x) + Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True, + [[1., 0., 1., 0.], + [0., 1., 1., 0.], + [0., 1., 1., 1.]]) + + >>> x = paddle.randn([3, 4]) + >>> p = paddle.randn([3, 1]) + >>> x.bernoulli_(p) + >>> # doctest: +SKIP('random check') + >>> print(x) + Tensor(shape=[3, 4], dtype=float32, place=Place(cpu), stop_gradient=True, + [[1., 0., 0., 1.], + [1., 0., 1., 0.], + [1., 0., 0., 0.]]) + + """ + x.uniform_(0.0, 1.0) + ones_mask = x > p + zeros_mask = x < p + x.masked_fill_(ones_mask, 1.0) + x.masked_fill_(zeros_mask, 0.0) + return x + + def binomial(count, prob, name=None): r""" Returns a tensor filled with random number from the Binomial Distribution, which supports Tensor shape diff --git a/test/deprecated/legacy_test/test_inplace.py b/test/deprecated/legacy_test/test_inplace.py index 7655afb82cc04..a3885b5bafb7a 100755 --- a/test/deprecated/legacy_test/test_inplace.py +++ b/test/deprecated/legacy_test/test_inplace.py @@ -1921,5 +1921,97 @@ def test_inplace_api(self): ) +class TestDygraphInplaceBernoulli(unittest.TestCase): + def setUp(self): + self.init_data() + self.set_np_compare_func() + + def init_data(self): + self.shape = (100, 1000) + self.input_var_numpy = np.random.random(self.shape) + self.dtype = "float32" + self.p = 0.5 + + def set_np_compare_func(self): + self.np_compare = np.array_equal + + def inplace_api_processing(self, var): + return paddle.bernoulli_(var, p=self.p) + + def inplace_class_method_processing(self, var): + return var.bernoulli_(self.p) + + def non_inplace_api_processing(self): + return paddle.bernoulli(paddle.full(self.shape, self.p)) + + def test_inplace_api(self): + var = paddle.to_tensor(self.input_var_numpy).astype(self.dtype) + non_inplace_var = self.non_inplace_api_processing() + inplace_var = self.inplace_api_processing(var) + self.assertTrue(id(var) == id(inplace_var)) + np.testing.assert_allclose( + non_inplace_var.numpy().mean(), + inplace_var.numpy().mean(), + atol=0.01, + ) + np.testing.assert_allclose( + non_inplace_var.numpy().var(), inplace_var.numpy().var(), atol=0.01 + ) + + def test_inplace_api_backward(self): + var_a = paddle.to_tensor(self.input_var_numpy).astype(self.dtype) + var_a.stop_gradient = False + var_b = var_a.clone() + expected_gradient = np.zeros(self.shape) + inplace_var = self.inplace_api_processing(var_b) + inplace_var.backward() + np.testing.assert_equal( + var_a.grad.numpy(), + expected_gradient, + ) + + def test_inplace_class_method(self): + var = paddle.to_tensor(self.input_var_numpy).astype(self.dtype) + non_inplace_var = self.non_inplace_api_processing() + inplace_var = self.inplace_class_method_processing(var) + self.assertTrue(id(var) == id(inplace_var)) + np.testing.assert_allclose( + non_inplace_var.numpy().mean(), + inplace_var.numpy().mean(), + atol=0.01, + ) + np.testing.assert_allclose( + non_inplace_var.numpy().var(), inplace_var.numpy().var(), atol=0.01 + ) + + def test_inplace_class_method_backward(self): + var_a = paddle.to_tensor(self.input_var_numpy).astype(self.dtype) + var_a.stop_gradient = False + var_b = var_a.clone() + expected_gradient = np.zeros(self.shape) + inplace_var = self.inplace_class_method_processing(var_b) + inplace_var.backward() + np.testing.assert_equal( + var_a.grad.numpy(), + expected_gradient, + ) + + +class TestDygraphInplaceBernoulli2(TestDygraphInplaceBernoulli): + def init_data(self): + self.shape = (100, 1000) + self.input_var_numpy = np.random.random(self.shape) + self.dtype = "float64" + self.p = 0.5 + + +class TestDygraphInplaceBernoulliError(unittest.TestCase): + def test_broadcast_error(self): + var = paddle.randn([3, 4]) + p = paddle.randn([5]) + with self.assertRaises(ValueError): + var.bernoulli_(p) + + if __name__ == '__main__': unittest.main() From 446897ec3306f0439ffd68ac5c4508c54052ad05 Mon Sep 17 00:00:00 2001 From: fanhaoxuee <129482555+ApricityXX@users.noreply.github.com> Date: Tue, 21 May 2024 17:28:29 +0800 Subject: [PATCH 10/13] =?UTF-8?q?=E3=80=90Hackathon=206th=20Fundable=20Pro?= =?UTF-8?q?jects=202=20No.47=E3=80=91=20performance-unnecessary-copy-initi?= =?UTF-8?q?alization=5F1=20-part=20(#64029)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auto_code_generator/eager_generator.cc | 2 +- paddle/fluid/framework/data_feed.cc | 8 +++--- .../memory_optimize_pass/memory_reuse_pass.cc | 8 +++--- .../new_executor/interpreter/static_build.cc | 2 +- paddle/fluid/jit/property.cc | 8 +++--- paddle/phi/infermeta/spmd_rules/gather.cc | 8 +++--- paddle/phi/infermeta/spmd_rules/matmul.cc | 6 ++--- paddle/phi/infermeta/spmd_rules/reduction.cc | 2 +- paddle/phi/infermeta/spmd_rules/split.cc | 4 +-- .../spmd_rules/spmd_rule_macro_define.h | 2 +- paddle/phi/infermeta/spmd_rules/tile.cc | 21 ++++++++-------- paddle/phi/infermeta/spmd_rules/unsqueeze.cc | 9 ++++--- paddle/phi/infermeta/spmd_rules/where.cc | 25 ++++++++++--------- paddle/phi/kernels/cpu/cum_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/cumprod_grad_kernel.cc | 2 +- .../phi/kernels/cpu/index_put_grad_kernel.cc | 2 +- paddle/phi/kernels/cpu/index_put_kernel.cc | 2 +- paddle/phi/kernels/funcs/math_function.cc | 2 +- .../phi/kernels/stride/squeeze_grad_kernel.cc | 2 +- .../kernels/stride/unsqueeze_grad_kernel.cc | 2 +- 20 files changed, 61 insertions(+), 58 deletions(-) diff --git a/paddle/fluid/eager/auto_code_generator/eager_generator.cc b/paddle/fluid/eager/auto_code_generator/eager_generator.cc index e2522a83feaae..08ca383878071 100644 --- a/paddle/fluid/eager/auto_code_generator/eager_generator.cc +++ b/paddle/fluid/eager/auto_code_generator/eager_generator.cc @@ -622,7 +622,7 @@ static bool BeSameAsInput(const std::string& output_name, static void PurifyForwardOpProto(const proto::OpProto& op_proto, ForwardGenerationInfo* fwd_info) { // Op Name - const std::string op_name = op_proto.type(); + const std::string& op_name = op_proto.type(); auto* in_vars = fwd_info->GetMutableInVars(); auto* out_vars = fwd_info->GetMutableOutVars(); diff --git a/paddle/fluid/framework/data_feed.cc b/paddle/fluid/framework/data_feed.cc index fd6f4efca9c6c..f8ee560b02090 100644 --- a/paddle/fluid/framework/data_feed.cc +++ b/paddle/fluid/framework/data_feed.cc @@ -635,7 +635,7 @@ void MultiSlotDataFeed::Init( true, platform::errors::PreconditionNotMet( "Multi_slot_desc has not been set in MultiSlotDataFeed.")); - paddle::framework::MultiSlotDesc multi_slot_desc = + const paddle::framework::MultiSlotDesc& multi_slot_desc = data_feed_desc.multi_slot_desc(); SetBatchSize(data_feed_desc.batch_size()); // temporarily set queue size = batch size * 100 @@ -1041,7 +1041,7 @@ void MultiSlotInMemoryDataFeed::Init( true, platform::errors::PreconditionNotMet( "Multi_slot_desc has not been set in MultiSlotInMemoryDataFeed.")); - paddle::framework::MultiSlotDesc multi_slot_desc = + const paddle::framework::MultiSlotDesc& multi_slot_desc = data_feed_desc.multi_slot_desc(); SetBatchSize(data_feed_desc.batch_size()); size_t all_slot_num = multi_slot_desc.slots_size(); @@ -1611,7 +1611,7 @@ void PrivateInstantDataFeed::Init(const DataFeedDesc& data_feed_desc) { true, platform::errors::PreconditionNotMet( "Multi_slot_desc has not been set in PrivateInstantDataFeed.")); - paddle::framework::MultiSlotDesc multi_slot_desc = + const paddle::framework::MultiSlotDesc& multi_slot_desc = data_feed_desc.multi_slot_desc(); SetBatchSize(data_feed_desc.batch_size()); size_t all_slot_num = multi_slot_desc.slots_size(); @@ -2029,7 +2029,7 @@ void SlotRecordInMemoryDataFeed::Init(const DataFeedDesc& data_feed_desc) { PADDLE_ENFORCE(data_feed_desc.has_multi_slot_desc(), platform::errors::PreconditionNotMet( "Multi_slot_desc has not been set in data_feed_desc")); - paddle::framework::MultiSlotDesc multi_slot_desc = + const paddle::framework::MultiSlotDesc& multi_slot_desc = data_feed_desc.multi_slot_desc(); SetBatchSize(data_feed_desc.batch_size()); size_t all_slot_num = multi_slot_desc.slots_size(); diff --git a/paddle/fluid/framework/ir/memory_optimize_pass/memory_reuse_pass.cc b/paddle/fluid/framework/ir/memory_optimize_pass/memory_reuse_pass.cc index e53687d095588..c7962ed7f30a9 100644 --- a/paddle/fluid/framework/ir/memory_optimize_pass/memory_reuse_pass.cc +++ b/paddle/fluid/framework/ir/memory_optimize_pass/memory_reuse_pass.cc @@ -95,7 +95,7 @@ std::unordered_set MemoryReusePass::FindNodesByName( } VarDesc *MemoryReusePass::GetVarDesc(const details::VarHandle &var) const { - const auto var_name = var.Name(); + const auto &var_name = var.Name(); size_t scope_idx = var.scope_idx(); auto iter = var_descs_[scope_idx].find(var_name); if (iter == var_descs_[scope_idx].end()) { @@ -156,14 +156,14 @@ void MemoryReusePass::CollectReusedVars() const { bool MemoryReusePass::IsInVarAlreadyReused( const details::VarHandle &in_var) const { - const auto var_name = in_var.Name(); + const auto &var_name = in_var.Name(); size_t scope_idx = in_var.scope_idx(); return reused_in_var_names_[scope_idx].count(var_name) > 0; } bool MemoryReusePass::IsOutVarAlreadyReused( const details::VarHandle &out_var) const { - const auto var_name = out_var.Name(); + const auto &var_name = out_var.Name(); size_t scope_idx = out_var.scope_idx(); return reused_out_var_names_[scope_idx].count(var_name) > 0; } @@ -314,7 +314,7 @@ bool MemoryReusePass::IsVarPairReusable( "Var(%s) have no GeneratedOp, or it's op is not ComputationOpHandle.", out_var.Name())); - const auto in_name = in_var.Name(); + const auto &in_name = in_var.Name(); if (in_name == out_var.Name()) { return false; } diff --git a/paddle/fluid/framework/new_executor/interpreter/static_build.cc b/paddle/fluid/framework/new_executor/interpreter/static_build.cc index d639d212b0aa9..dc5b5ddfced49 100644 --- a/paddle/fluid/framework/new_executor/interpreter/static_build.cc +++ b/paddle/fluid/framework/new_executor/interpreter/static_build.cc @@ -794,7 +794,7 @@ void FakeInitializeOutputsForFunctionKernel( const phi::KernelSignature& kernel_sig, const RuntimeContext& runtime_ctx, const platform::DeviceContext& dev_ctx) { - std::string op_type = op.Type(); + const std::string& op_type = op.Type(); auto output_names = kernel_sig.output_names; auto output_defs = phi_kernel.args_def().output_defs(); PADDLE_ENFORCE_EQ(output_names.size(), diff --git a/paddle/fluid/jit/property.cc b/paddle/fluid/jit/property.cc index 37c426bb5401b..d91aba11cfb55 100644 --- a/paddle/fluid/jit/property.cc +++ b/paddle/fluid/jit/property.cc @@ -209,8 +209,8 @@ std::vector Property::GetFloats(const std::string &name) { phi::errors::PreconditionNotMet( "JIT::Property GetFloats: idx=%d type is not floats.", i)); - auto items = e.floats(); - return std::vector(items.begin(), items.end()); + // auto items = e.floats(); + return std::vector(e.floats().begin(), e.floats().end()); } } @@ -368,8 +368,8 @@ std::vector Property::GetStrings(const std::string &name) { phi::errors::PreconditionNotMet( "JIT::Property GetStrings: idx=%d type is not strings.", i)); - auto items = e.strings(); - return std::vector(items.begin(), items.end()); + // auto items = e.strings(); + return std::vector(e.strings().begin(), e.strings().end()); } } diff --git a/paddle/phi/infermeta/spmd_rules/gather.cc b/paddle/phi/infermeta/spmd_rules/gather.cc index 014c5f358dd73..30cb413ba1ddf 100644 --- a/paddle/phi/infermeta/spmd_rules/gather.cc +++ b/paddle/phi/infermeta/spmd_rules/gather.cc @@ -37,8 +37,8 @@ SpmdInfo GatherInferSpmdBase(const DistMetaTensor& x, // index may be 0-d tensor, verify it specifically auto index_shape = common::vectorize(index.dims()); int index_ndim = index_shape.size(); - TensorDistAttr index_dist_attr_src = index.dist_attr(); - std::vector index_dims_mapping_src = + const TensorDistAttr& index_dist_attr_src = index.dist_attr(); + const std::vector& index_dims_mapping_src = index_dist_attr_src.dims_mapping(); if (index_ndim == 0) { PADDLE_ENFORCE_EQ(index_dims_mapping_src.size(), @@ -182,8 +182,8 @@ SpmdInfo GatherGradInferSpmd(const DistMetaTensor& x, EXTRACT_SHAPE_AND_DIST_ATTR(out_grad); auto index_shape = common::vectorize(index.dims()); int index_ndim = index_shape.size(); - TensorDistAttr index_dist_attr_src = index.dist_attr(); - std::vector index_dims_mapping_src = + const TensorDistAttr& index_dist_attr_src = index.dist_attr(); + const std::vector& index_dims_mapping_src = index_dist_attr_src.dims_mapping(); int axis_ = axis.to(); diff --git a/paddle/phi/infermeta/spmd_rules/matmul.cc b/paddle/phi/infermeta/spmd_rules/matmul.cc index 753dc7ab3f12a..c0f13176034d6 100644 --- a/paddle/phi/infermeta/spmd_rules/matmul.cc +++ b/paddle/phi/infermeta/spmd_rules/matmul.cc @@ -123,8 +123,8 @@ SpmdInfo MatmulInferSpmd(const DistMetaTensor& x, auto y_shape = common::vectorize(y.dims()); int x_ndim = static_cast(x_shape.size()); int y_ndim = static_cast(y_shape.size()); - auto x_dist_attr_src = x.dist_attr(); - auto y_dist_attr_src = y.dist_attr(); + const auto& x_dist_attr_src = x.dist_attr(); + const auto& y_dist_attr_src = y.dist_attr(); std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); std::vector y_dims_mapping = y_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( @@ -338,7 +338,7 @@ SpmdInfo MatmulGradInferSpmd(const DistMetaTensor& x, auto infer_y_dist_attr = get_attr(fwd_spmd_info.first[1]); auto is_dist_attr_equal = [&](const TensorDistAttr& dist_attr, const ArgDistAttr& arg_dist_attr) -> bool { - auto infer_dist_attr = get_attr(arg_dist_attr); + const auto& infer_dist_attr = get_attr(arg_dist_attr); return (dist_attr.process_mesh() != infer_dist_attr.process_mesh() || dist_attr.dims_mapping() != infer_dist_attr.dims_mapping() || dist_attr.partial_status() != infer_dist_attr.partial_status()); diff --git a/paddle/phi/infermeta/spmd_rules/reduction.cc b/paddle/phi/infermeta/spmd_rules/reduction.cc index 96e9230fb9182..20fbaa2bd3e3b 100644 --- a/paddle/phi/infermeta/spmd_rules/reduction.cc +++ b/paddle/phi/infermeta/spmd_rules/reduction.cc @@ -72,7 +72,7 @@ SpmdInfo ReductionInferSpmdBase(const DistMetaTensor& x, // Step0: Verify input args based on reduction logic auto x_shape = common::vectorize(x.dims()); int x_ndim = static_cast(x_shape.size()); - auto x_dist_attr_src = x.dist_attr(); + const auto& x_dist_attr_src = x.dist_attr(); std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, diff --git a/paddle/phi/infermeta/spmd_rules/split.cc b/paddle/phi/infermeta/spmd_rules/split.cc index c9b98c1abe88d..e1769392f7238 100644 --- a/paddle/phi/infermeta/spmd_rules/split.cc +++ b/paddle/phi/infermeta/spmd_rules/split.cc @@ -30,7 +30,7 @@ SpmdInfo SplitWithNumInferSpmd(const DistMetaTensor& x, int num, int axis) { // Step0: Verify input args based on split logic auto x_shape = common::vectorize(x.dims()); int x_ndim = static_cast(x_shape.size()); - auto x_dist_attr_src = x.dist_attr(); + const auto& x_dist_attr_src = x.dist_attr(); std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, @@ -108,7 +108,7 @@ SpmdInfo SplitWithNumInferSpmdReverse( int out_ndim = static_cast(common::vectorize(outs[0]->dims()).size()); auto x_shape = common::vectorize(x.dims()); int x_ndim = static_cast(x_shape.size()); - auto x_dist_attr = x.dist_attr(); + const auto& x_dist_attr = x.dist_attr(); std::vector x_dims_mapping = x_dist_attr.dims_mapping(); PADDLE_ENFORCE_EQ(nouts, num, diff --git a/paddle/phi/infermeta/spmd_rules/spmd_rule_macro_define.h b/paddle/phi/infermeta/spmd_rules/spmd_rule_macro_define.h index 43147db5b6194..0ee439eaf0e49 100644 --- a/paddle/phi/infermeta/spmd_rules/spmd_rule_macro_define.h +++ b/paddle/phi/infermeta/spmd_rules/spmd_rule_macro_define.h @@ -19,7 +19,7 @@ using phi::distributed::auto_parallel::str_join; #define EXTRACT_SHAPE_AND_DIST_ATTR(x) \ auto x##_shape = phi::vectorize(x.dims()); \ int x##_ndim = x##_shape.size(); \ - auto x##_dist_attr_src = x.dist_attr(); \ + const auto& x##_dist_attr_src = x.dist_attr(); \ const auto& x##_dims_mapping_src = x##_dist_attr_src.dims_mapping(); \ PADDLE_ENFORCE_EQ(x##_ndim, \ x##_dims_mapping_src.size(), \ diff --git a/paddle/phi/infermeta/spmd_rules/tile.cc b/paddle/phi/infermeta/spmd_rules/tile.cc index e6d98a1b28303..dea5e11e77fe7 100644 --- a/paddle/phi/infermeta/spmd_rules/tile.cc +++ b/paddle/phi/infermeta/spmd_rules/tile.cc @@ -27,8 +27,8 @@ SpmdInfo TileInferSpmd(const DistMetaTensor& x, const std::vector& repeat_times) { auto x_shape = common::vectorize(x.dims()); int x_ndim = x_shape.size(); - auto x_dist_attr_src = x.dist_attr(); - std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); + const auto& x_dist_attr_src = x.dist_attr(); + const std::vector& x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, x_dims_mapping.size(), @@ -91,8 +91,8 @@ SpmdInfo TileInferSpmdReverse(const DistMetaTensor& x, const std::vector& repeat_times) { auto x_shape = common::vectorize(x.dims()); int x_ndim = x_shape.size(); - auto x_dist_attr_src = x.dist_attr(); - std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); + const auto& x_dist_attr_src = x.dist_attr(); + const std::vector& x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, x_dims_mapping.size(), @@ -111,8 +111,9 @@ SpmdInfo TileInferSpmdReverse(const DistMetaTensor& x, auto out_shape = common::vectorize(out.dims()); int out_ndim = out_shape.size(); - auto out_dist_attr_src = out.dist_attr(); - std::vector out_dims_mapping = out_dist_attr_src.dims_mapping(); + const auto& out_dist_attr_src = out.dist_attr(); + const std::vector& out_dims_mapping = + out_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( out_ndim, out_dims_mapping.size(), @@ -171,8 +172,8 @@ SpmdInfo TileGradInferSpmd(const DistMetaTensor& x, IntArray repeat_times) { auto x_shape = common::vectorize(x.dims()); int x_ndim = x_shape.size(); - auto x_dist_attr_src = x.dist_attr(); - std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); + const auto& x_dist_attr_src = x.dist_attr(); + const std::vector& x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, x_dims_mapping.size(), @@ -191,8 +192,8 @@ SpmdInfo TileGradInferSpmd(const DistMetaTensor& x, auto out_grad_shape = common::vectorize(out_grad.dims()); int out_grad_ndim = out_grad_shape.size(); - auto out_grad_dist_attr_src = out_grad.dist_attr(); - std::vector out_grad_dims_mapping = + const auto& out_grad_dist_attr_src = out_grad.dist_attr(); + const std::vector& out_grad_dims_mapping = out_grad_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ(out_grad_ndim, out_grad_dims_mapping.size(), diff --git a/paddle/phi/infermeta/spmd_rules/unsqueeze.cc b/paddle/phi/infermeta/spmd_rules/unsqueeze.cc index f7e16d4bb33da..9aab6676bd383 100644 --- a/paddle/phi/infermeta/spmd_rules/unsqueeze.cc +++ b/paddle/phi/infermeta/spmd_rules/unsqueeze.cc @@ -94,8 +94,8 @@ SpmdInfo UnsqueezeInferSpmd(const DistMetaTensor& x, // Step0: Verify input args based on unsqueeze logic auto x_shape = common::vectorize(x.dims()); int x_ndim = static_cast(x_shape.size()); - auto x_dist_attr_src = x.dist_attr(); - std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); + const auto& x_dist_attr_src = x.dist_attr(); + const std::vector& x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, x_dims_mapping.size(), @@ -165,8 +165,9 @@ SpmdInfo UnsqueezeInferSpmdReverse(const DistMetaTensor& x, int x_ndim = static_cast(x_shape.size()); auto out_shape = common::vectorize(out.dims()); int out_ndim = static_cast(out_shape.size()); - auto out_dist_attr_src = out.dist_attr(); - std::vector out_dims_mapping = out_dist_attr_src.dims_mapping(); + const auto& out_dist_attr_src = out.dist_attr(); + const std::vector& out_dims_mapping = + out_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( out_ndim, out_dims_mapping.size(), diff --git a/paddle/phi/infermeta/spmd_rules/where.cc b/paddle/phi/infermeta/spmd_rules/where.cc index b176365bb2d7d..6499d3f37635f 100644 --- a/paddle/phi/infermeta/spmd_rules/where.cc +++ b/paddle/phi/infermeta/spmd_rules/where.cc @@ -28,7 +28,7 @@ SpmdInfo WhereInferSpmd(const DistMetaTensor& condition, const DistMetaTensor& y) { auto cond_shape = common::vectorize(condition.dims()); int cond_ndim = cond_shape.size(); - auto cond_dist_attr_src = condition.dist_attr(); + const auto& cond_dist_attr_src = condition.dist_attr(); std::vector cond_dims_mapping = cond_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( cond_ndim, @@ -43,7 +43,7 @@ SpmdInfo WhereInferSpmd(const DistMetaTensor& condition, auto x_shape = common::vectorize(x.dims()); int x_ndim = x_shape.size(); - auto x_dist_attr_src = x.dist_attr(); + const auto& x_dist_attr_src = x.dist_attr(); std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, @@ -65,7 +65,7 @@ SpmdInfo WhereInferSpmd(const DistMetaTensor& condition, auto y_shape = common::vectorize(y.dims()); int y_ndim = y_shape.size(); - auto y_dist_attr_src = y.dist_attr(); + const auto& y_dist_attr_src = y.dist_attr(); std::vector y_dims_mapping = y_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( y_ndim, @@ -136,7 +136,7 @@ SpmdInfo WhereInferSpmdReverse(const DistMetaTensor& condition, const DistMetaTensor& output) { auto cond_shape = common::vectorize(condition.dims()); int cond_ndim = cond_shape.size(); - auto cond_dist_attr_src = condition.dist_attr(); + const auto& cond_dist_attr_src = condition.dist_attr(); std::vector cond_dims_mapping = cond_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( cond_ndim, @@ -151,7 +151,7 @@ SpmdInfo WhereInferSpmdReverse(const DistMetaTensor& condition, auto x_shape = common::vectorize(x.dims()); int x_ndim = x_shape.size(); - auto x_dist_attr_src = x.dist_attr(); + const auto& x_dist_attr_src = x.dist_attr(); std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, @@ -172,7 +172,7 @@ SpmdInfo WhereInferSpmdReverse(const DistMetaTensor& condition, auto y_shape = common::vectorize(y.dims()); int y_ndim = y_shape.size(); - auto y_dist_attr_src = y.dist_attr(); + const auto& y_dist_attr_src = y.dist_attr(); std::vector y_dims_mapping = y_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( y_ndim, @@ -193,8 +193,9 @@ SpmdInfo WhereInferSpmdReverse(const DistMetaTensor& condition, auto out_shape = common::vectorize(output.dims()); int out_ndim = out_shape.size(); - auto out_dist_attr_src = output.dist_attr(); - std::vector out_dims_mapping = out_dist_attr_src.dims_mapping(); + const auto& out_dist_attr_src = output.dist_attr(); + const std::vector& out_dims_mapping = + out_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( out_ndim, out_dims_mapping.size(), @@ -250,7 +251,7 @@ SpmdInfo WhereGradInferSpmd(const DistMetaTensor& condition, const DistMetaTensor& out_grad) { auto cond_shape = common::vectorize(condition.dims()); int cond_ndim = cond_shape.size(); - auto cond_dist_attr_src = condition.dist_attr(); + const auto& cond_dist_attr_src = condition.dist_attr(); std::vector cond_dims_mapping = cond_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( cond_ndim, @@ -265,7 +266,7 @@ SpmdInfo WhereGradInferSpmd(const DistMetaTensor& condition, auto x_shape = common::vectorize(x.dims()); int x_ndim = x_shape.size(); - auto x_dist_attr_src = x.dist_attr(); + const auto& x_dist_attr_src = x.dist_attr(); std::vector x_dims_mapping = x_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( x_ndim, @@ -286,7 +287,7 @@ SpmdInfo WhereGradInferSpmd(const DistMetaTensor& condition, auto y_shape = common::vectorize(y.dims()); int y_ndim = y_shape.size(); - auto y_dist_attr_src = y.dist_attr(); + const auto& y_dist_attr_src = y.dist_attr(); std::vector y_dims_mapping = y_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( y_ndim, @@ -307,7 +308,7 @@ SpmdInfo WhereGradInferSpmd(const DistMetaTensor& condition, auto out_grad_shape = common::vectorize(out_grad.dims()); int out_grad_ndim = out_grad_shape.size(); - auto out_grad_dist_attr_src = out_grad.dist_attr(); + const auto& out_grad_dist_attr_src = out_grad.dist_attr(); std::vector out_grad_dims_mapping = out_grad_dist_attr_src.dims_mapping(); PADDLE_ENFORCE_EQ( diff --git a/paddle/phi/kernels/cpu/cum_grad_kernel.cc b/paddle/phi/kernels/cpu/cum_grad_kernel.cc index 212b9839e2894..7dbce190299ab 100644 --- a/paddle/phi/kernels/cpu/cum_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/cum_grad_kernel.cc @@ -30,7 +30,7 @@ void CumsumGradKernel(const Context& dev_ctx, bool exclusive, bool reverse, DenseTensor* x_grad) { - auto x_dims = x.dims(); + const auto& x_dims = x.dims(); // If the attribute of flatten is `True`, the cumsum kernel is compose of the // operation of flatten and cumsum, need to flatten the tensor of input // gradient, and last step need to unflatten the tensor diff --git a/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc b/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc index 62c0a3e75de90..b56f0ffaec038 100644 --- a/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/cumprod_grad_kernel.cc @@ -35,7 +35,7 @@ void CumprodGradKernel(const Context& dev_ctx, bool exclusive, bool reverse, DenseTensor* d_x) { - DDim shape = x.dims(); + const DDim& shape = x.dims(); auto* d_out_data = d_out.data(); auto* x_data = x.data(); diff --git a/paddle/phi/kernels/cpu/index_put_grad_kernel.cc b/paddle/phi/kernels/cpu/index_put_grad_kernel.cc index 8a100af33f018..0da623dfc571e 100644 --- a/paddle/phi/kernels/cpu/index_put_grad_kernel.cc +++ b/paddle/phi/kernels/cpu/index_put_grad_kernel.cc @@ -98,7 +98,7 @@ void LaunchIndexPutGradKernel(const Context& dev_ctx, } } - auto out_grad_dims = out_grad.dims(); + const auto& out_grad_dims = out_grad.dims(); const int64_t numel = indices[0]->numel(); auto out_grad_stride = common::stride(out_grad_dims); diff --git a/paddle/phi/kernels/cpu/index_put_kernel.cc b/paddle/phi/kernels/cpu/index_put_kernel.cc index 7880dd3040fcc..06fe2ff76d42d 100644 --- a/paddle/phi/kernels/cpu/index_put_kernel.cc +++ b/paddle/phi/kernels/cpu/index_put_kernel.cc @@ -76,7 +76,7 @@ void LaunchIndexPutKernel(const Context& dev_ctx, phi::Copy(dev_ctx, x, dev_ctx.GetPlace(), false, out); } - auto x_dims = x.dims(); + const auto& x_dims = x.dims(); const int64_t numel = indices[0]->numel(); auto x_stride = common::stride(x_dims); diff --git a/paddle/phi/kernels/funcs/math_function.cc b/paddle/phi/kernels/funcs/math_function.cc index 99167a2c1c2b8..817ee7bd9dbd1 100644 --- a/paddle/phi/kernels/funcs/math_function.cc +++ b/paddle/phi/kernels/funcs/math_function.cc @@ -273,7 +273,7 @@ struct RowwiseAdd { const phi::DenseTensor& vector, phi::DenseTensor* output) { auto in_dims = input.dims(); - auto out_dims = output->dims(); + const auto& out_dims = output->dims(); auto size = input.numel() / in_dims[0]; PADDLE_ENFORCE_EQ( vector.numel(), diff --git a/paddle/phi/kernels/stride/squeeze_grad_kernel.cc b/paddle/phi/kernels/stride/squeeze_grad_kernel.cc index bfb5dd508998b..6ddec850e68b0 100644 --- a/paddle/phi/kernels/stride/squeeze_grad_kernel.cc +++ b/paddle/phi/kernels/stride/squeeze_grad_kernel.cc @@ -24,7 +24,7 @@ void SqueezeGradStridedKernel(const Context& dev_ctx, const DenseTensor& dout, const IntArray& axes UNUSED, DenseTensor* dx) { - auto xshape_dims = xshape.dims(); + const auto& xshape_dims = xshape.dims(); auto x_dims = common::slice_ddim(xshape_dims, 1, xshape_dims.size()); ReshapeStridedKernel( dev_ctx, dout, IntArray(common::vectorize(x_dims)), dx, nullptr); diff --git a/paddle/phi/kernels/stride/unsqueeze_grad_kernel.cc b/paddle/phi/kernels/stride/unsqueeze_grad_kernel.cc index d25e96115b7fc..d825094bb192d 100644 --- a/paddle/phi/kernels/stride/unsqueeze_grad_kernel.cc +++ b/paddle/phi/kernels/stride/unsqueeze_grad_kernel.cc @@ -23,7 +23,7 @@ void UnsqueezeGradStridedKernel(const Context& dev_ctx, const DenseTensor& x_shape, const DenseTensor& dout, DenseTensor* dx) { - auto xshape_dims = x_shape.dims(); + const auto& xshape_dims = x_shape.dims(); auto x_dims = common::slice_ddim(xshape_dims, 1, xshape_dims.size()); ReshapeStridedKernel( dev_ctx, dout, IntArray(common::vectorize(x_dims)), dx, nullptr); From 2144b082724458d885d60eba1145fafeaf56c4fb Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Tue, 21 May 2024 18:02:32 +0800 Subject: [PATCH 11/13] fix pir api 7 (#64455) --- test/deprecated/legacy_test/CMakeLists.txt | 6 ++--- .../legacy_test/test_complex_variable.py | 26 +++++++++++++------ ...rsgd.py => test_downpoursgd_deprecated.py} | 1 + test/legacy_test/CMakeLists.txt | 11 +++++--- .../legacy_test/test_lod_reset_op.py | 0 tools/parallel_UT_rule.py | 4 +-- tools/static_mode_white_list.py | 2 +- 7 files changed, 33 insertions(+), 17 deletions(-) rename test/deprecated/legacy_test/{test_downpoursgd.py => test_downpoursgd_deprecated.py} (99%) rename test/{deprecated => }/legacy_test/test_lod_reset_op.py (100%) diff --git a/test/deprecated/legacy_test/CMakeLists.txt b/test/deprecated/legacy_test/CMakeLists.txt index 7ff456d1feb47..b166888f11984 100644 --- a/test/deprecated/legacy_test/CMakeLists.txt +++ b/test/deprecated/legacy_test/CMakeLists.txt @@ -99,7 +99,7 @@ if(WIN32) list(REMOVE_ITEM TEST_OPS test_multiprocess_reader_exception) list(REMOVE_ITEM TEST_OPS test_trainer_desc) list(REMOVE_ITEM TEST_OPS test_checkpoint_notify_op) - list(REMOVE_ITEM TEST_OPS test_downpoursgd) + list(REMOVE_ITEM TEST_OPS test_downpoursgd_deprecated) list(REMOVE_ITEM TEST_OPS test_fleet) list(REMOVE_ITEM TEST_OPS test_fleet_nocvm_1) list(REMOVE_ITEM TEST_OPS test_fleet_rolemaker) @@ -453,8 +453,8 @@ endif() # Some ops need to check results when gc is enabled # Currently, only ops that register NoNeedBufferVarsInference need to do this test -set(TEST_OPS_WITH_GC test_affine_channel_op test_gather_nd_op test_lod_reset_op - test_scatter_op test_slice_op) +set(TEST_OPS_WITH_GC test_affine_channel_op test_gather_nd_op test_scatter_op + test_slice_op) foreach(TEST_OP ${TEST_OPS_WITH_GC}) list(REMOVE_ITEM TEST_OPS ${TEST_OP}) diff --git a/test/deprecated/legacy_test/test_complex_variable.py b/test/deprecated/legacy_test/test_complex_variable.py index 9509176a7b944..2d78fa2b19330 100644 --- a/test/deprecated/legacy_test/test_complex_variable.py +++ b/test/deprecated/legacy_test/test_complex_variable.py @@ -46,14 +46,24 @@ def test_attrs(self): self.compare() def test_convert_np_dtype_to_dtype(self): - self.assertEqual( - convert_np_dtype_to_dtype_(np.complex64), - core.VarDesc.VarType.COMPLEX64, - ) - self.assertEqual( - convert_np_dtype_to_dtype_(np.complex64), - core.VarDesc.VarType.COMPLEX64, - ) + if paddle.framework.use_pir_api(): + self.assertEqual( + convert_np_dtype_to_dtype_(np.complex64), + core.DataType.COMPLEX64, + ) + self.assertEqual( + convert_np_dtype_to_dtype_(np.complex64), + core.DataType.COMPLEX64, + ) + else: + self.assertEqual( + convert_np_dtype_to_dtype_(np.complex64), + core.VarDesc.VarType.COMPLEX64, + ) + self.assertEqual( + convert_np_dtype_to_dtype_(np.complex64), + core.VarDesc.VarType.COMPLEX64, + ) def test_convert_dtype(self): self.assertEqual( diff --git a/test/deprecated/legacy_test/test_downpoursgd.py b/test/deprecated/legacy_test/test_downpoursgd_deprecated.py similarity index 99% rename from test/deprecated/legacy_test/test_downpoursgd.py rename to test/deprecated/legacy_test/test_downpoursgd_deprecated.py index 60ccacce6e895..43e5cbed0ab72 100644 --- a/test/deprecated/legacy_test/test_downpoursgd.py +++ b/test/deprecated/legacy_test/test_downpoursgd_deprecated.py @@ -224,4 +224,5 @@ def test_downpour_opt_work(self): if __name__ == "__main__": + paddle.enable_static() unittest.main() diff --git a/test/legacy_test/CMakeLists.txt b/test/legacy_test/CMakeLists.txt index 26338ef937d8c..b31afec78034d 100644 --- a/test/legacy_test/CMakeLists.txt +++ b/test/legacy_test/CMakeLists.txt @@ -113,7 +113,7 @@ endif() if(WIN32) list(REMOVE_ITEM TEST_OPS test_trainer_desc) list(REMOVE_ITEM TEST_OPS test_checkpoint_notify_op) - list(REMOVE_ITEM TEST_OPS test_downpoursgd) + list(REMOVE_ITEM TEST_OPS test_downpoursgd_deprecated) list(REMOVE_ITEM TEST_OPS test_fleet) list(REMOVE_ITEM TEST_OPS test_fleet_nocvm_1) list(REMOVE_ITEM TEST_OPS test_fleet_rolemaker) @@ -484,8 +484,13 @@ endif() # Some ops need to check results when gc is enabled # Currently, only ops that register NoNeedBufferVarsInference need to do this test set(TEST_OPS_WITH_GC - test_concat_op test_elementwise_add_op test_lookup_table_op - test_elementwise_sub_op test_gather_op test_mean_op) + test_concat_op + test_elementwise_add_op + test_lookup_table_op + test_elementwise_sub_op + test_gather_op + test_mean_op + test_lod_reset_op) foreach(TEST_OP ${TEST_OPS_WITH_GC}) list(REMOVE_ITEM TEST_OPS ${TEST_OP}) diff --git a/test/deprecated/legacy_test/test_lod_reset_op.py b/test/legacy_test/test_lod_reset_op.py similarity index 100% rename from test/deprecated/legacy_test/test_lod_reset_op.py rename to test/legacy_test/test_lod_reset_op.py diff --git a/tools/parallel_UT_rule.py b/tools/parallel_UT_rule.py index e6908e9df955a..646a40b30dc0c 100755 --- a/tools/parallel_UT_rule.py +++ b/tools/parallel_UT_rule.py @@ -243,7 +243,7 @@ 'mmap_allocator_test', 'test_reshape_transpose_matmul_mkldnn_fuse_pass', 'test_communicator_async', - 'test_downpoursgd', + 'test_downpoursgd_deprecated', 'variable_test', 'test_quantization_mkldnn_pass', 'test_quantize_mkldnn_op', @@ -1836,7 +1836,7 @@ 'test_dyn_rnn', 'test_dygraph_mode_of_unittest', 'test_dpsgd_op', - 'test_downpoursgd', + 'test_downpoursgd_deprecated', 'test_download', 'test_distributions', 'test_distributed_reader', diff --git a/tools/static_mode_white_list.py b/tools/static_mode_white_list.py index a6dbad6038a2d..8bfb9caef11c2 100755 --- a/tools/static_mode_white_list.py +++ b/tools/static_mode_white_list.py @@ -144,7 +144,7 @@ 'test_distributed_strategy', 'test_distributions', 'test_dot_op', - 'test_downpoursgd', + 'test_downpoursgd_deprecated', 'test_dpsgd_op', 'test_dropout_op', 'test_dygraph_multi_forward', From 4e68eb2d0a1106b6b7e0282e6248fa3fa7f80fd9 Mon Sep 17 00:00:00 2001 From: ming1753 <61511741+ming1753@users.noreply.github.com> Date: Tue, 21 May 2024 18:33:34 +0800 Subject: [PATCH 12/13] sprse conv delete message (#64482) --- .../kernels/sparse/gpu/conv_kernel_impl.cuh | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/paddle/phi/kernels/sparse/gpu/conv_kernel_impl.cuh b/paddle/phi/kernels/sparse/gpu/conv_kernel_impl.cuh index 08ef66710498a..775c23def14b0 100644 --- a/paddle/phi/kernels/sparse/gpu/conv_kernel_impl.cuh +++ b/paddle/phi/kernels/sparse/gpu/conv_kernel_impl.cuh @@ -136,8 +136,6 @@ __global__ void __launch_bounds__(64) conv_forward_cuda_setting1_mode0_f16f16f32 "{%0, %1, %2, %3}, [%4];" : "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[0]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[1]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[2]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[3]) : "r"(addr)); -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } @@ -154,8 +152,6 @@ __global__ void __launch_bounds__(64) conv_forward_cuda_setting1_mode0_f16f16f32 "{%0, %1, %2, %3}, [%4];" : "=r"(((unsigned *)(B_shared_warp + 0))[0]), "=r"(((unsigned *)(B_shared_warp + 0))[1]), "=r"(((unsigned *)(B_shared_warp + 0))[2]), "=r"(((unsigned *)(B_shared_warp + 0))[3]) : "r"(addr)); -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } for (int i0_0_3 = 0; i0_0_3 < 4; ++i0_0_3) @@ -208,8 +204,6 @@ __global__ void __launch_bounds__(64) conv_forward_cuda_setting1_mode0_f16f16f32 : "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[0]), "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[1]), "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[2]), "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[3]) : "r"(((unsigned *)(A_shared_warp + ((i0_0_3 * 8) + 4)))[0]), "r"(((unsigned *)(A_shared_warp + ((i0_0_3 * 8) + 4)))[1]), "r"(((unsigned *)(B_shared_warp + 6))[0]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[0]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[1]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[2]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[3])); } -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } @@ -309,8 +303,6 @@ __global__ void __launch_bounds__(64) conv_forward_cuda_setting2_mode0_f16f16f32 "{%0, %1, %2, %3}, [%4];" : "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[0]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[1]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[2]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[3]) : "r"(addr)); -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } @@ -327,8 +319,6 @@ __global__ void __launch_bounds__(64) conv_forward_cuda_setting2_mode0_f16f16f32 "{%0, %1, %2, %3}, [%4];" : "=r"(((unsigned *)(B_shared_warp + 0))[0]), "=r"(((unsigned *)(B_shared_warp + 0))[1]), "=r"(((unsigned *)(B_shared_warp + 0))[2]), "=r"(((unsigned *)(B_shared_warp + 0))[3]) : "r"(addr)); -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } for (int i0_0_3 = 0; i0_0_3 < 4; ++i0_0_3) @@ -379,8 +369,6 @@ __global__ void __launch_bounds__(64) conv_forward_cuda_setting2_mode0_f16f16f32 : "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[0]), "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[1]), "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[2]), "=f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[3]) : "r"(((unsigned *)(A_shared_warp + ((i0_0_3 * 8) + 4)))[0]), "r"(((unsigned *)(A_shared_warp + ((i0_0_3 * 8) + 4)))[1]), "r"(((unsigned *)(B_shared_warp + 6))[0]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[0]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[1]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[2]), "f"(((float *)(C_warp + ((i0_0_3 * 8) + 4)))[3])); } -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } @@ -481,8 +469,6 @@ __global__ void __launch_bounds__(128) conv_forward_cuda_setting3_mode0_f16f16f3 "{%0, %1, %2, %3}, [%4];" : "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[0]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[1]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[2]), "=r"(((unsigned *)(A_shared_warp + (ax0_0 * 8)))[3]) : "r"(addr)); -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } @@ -500,8 +486,6 @@ __global__ void __launch_bounds__(128) conv_forward_cuda_setting3_mode0_f16f16f3 "{%0, %1, %2, %3}, [%4];" : "=r"(((unsigned *)(B_shared_warp + (ax1_0 * 8)))[0]), "=r"(((unsigned *)(B_shared_warp + (ax1_0 * 8)))[1]), "=r"(((unsigned *)(B_shared_warp + (ax1_0 * 8)))[2]), "=r"(((unsigned *)(B_shared_warp + (ax1_0 * 8)))[3]) : "r"(addr)); -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } @@ -554,8 +538,6 @@ __global__ void __launch_bounds__(128) conv_forward_cuda_setting3_mode0_f16f16f3 : "=f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[0]), "=f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[1]), "=f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[2]), "=f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[3]) : "r"(((unsigned *)(A_shared_warp + ((i0_0_3 * 8) + 4)))[0]), "r"(((unsigned *)(A_shared_warp + ((i0_0_3 * 8) + 4)))[1]), "r"(((unsigned *)(B_shared_warp + ((i1_0_4 * 8) + 6)))[0]), "f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[0]), "f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[1]), "f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[2]), "f"(((float *)(C_warp + (((i0_0_3 * 16) + (i1_0_4 * 8)) + 4)))[3])); } -#else - #pragma message("FP16 kernels will not be compiled for SM75-.") #endif } } From 15888d179a30ea7cccf4a43bc67e97b302159994 Mon Sep 17 00:00:00 2001 From: Zero Rains Date: Tue, 21 May 2024 18:48:14 +0800 Subject: [PATCH 13/13] [Prim][PIR] binary_cross_entropy_with_logits forward decomp (#61613) * sigmoid_cross_entropy_with_logits forward decomp * mean_all forward decomp * add the test case for binary_cross_entropy_with_logits * creat a new test file * modify the assert method * modify the test * fix code style * add prim in check grad for test and handle the optional tensor * fix conflict * do not modify the third_party package * fix merge bug * modfiy the test data and change the file name * roback * fix bug * support mean_all for dynamic shape * modify the type --- .../decomp_interface_gen_op_list.py | 4 + paddle/fluid/primitive/composite/composite.h | 67 +++++++++++++++ ...st_sigmoid_cross_entropy_with_logits_op.py | 46 ++++++---- ...est_binary_cross_entropy_with_logits_op.py | 85 +++++++++++++++++++ .../test_prim_sub_graph_dynamic_shape.py | 17 ++++ 5 files changed, 204 insertions(+), 15 deletions(-) create mode 100644 test/legacy_test/test_binary_cross_entropy_with_logits_op.py diff --git a/paddle/fluid/pir/dialect/op_generator/decomp_interface_gen_op_list.py b/paddle/fluid/pir/dialect/op_generator/decomp_interface_gen_op_list.py index ddedd045f2bfd..4d7c302c096e5 100644 --- a/paddle/fluid/pir/dialect/op_generator/decomp_interface_gen_op_list.py +++ b/paddle/fluid/pir/dialect/op_generator/decomp_interface_gen_op_list.py @@ -42,6 +42,7 @@ "leaky_relu", "log_softmax", "mean", + "mean_all", "meshgrid", "one_hot", "p_norm", @@ -49,6 +50,7 @@ "reciprocal", "relu", "relu6", + "sigmoid_cross_entropy_with_logits", "silu", "swiglu", "softmax", @@ -83,12 +85,14 @@ "leaky_relu", "log_softmax", "mean", + "mean_all", "meshgrid", "p_norm", "pow", "reciprocal", "relu", "relu6", + "sigmoid_cross_entropy_with_logits", "silu", "swiglu", "softmax", diff --git a/paddle/fluid/primitive/composite/composite.h b/paddle/fluid/primitive/composite/composite.h index de764ababbc5b..8c108711f34f5 100644 --- a/paddle/fluid/primitive/composite/composite.h +++ b/paddle/fluid/primitive/composite/composite.h @@ -1180,6 +1180,73 @@ Tensor square_decomp(const Tensor& x) { } } +template +Tensor sigmoid_cross_entropy_with_logits_decomp( + const Tensor& x, + const Tensor& label, + const paddle::optional& pos_weight, + bool normalize, + int ignore_index) { + auto dims = x.shape(); + const Tensor zero = full(dims, 0, x.type()); + const Tensor one = full(dims, 1, x.type()); + Tensor pos_weight_tensor; + if (pos_weight) { + pos_weight_tensor = pos_weight.get(); + } else { + pos_weight_tensor = one; + } + auto term1 = where(x > zero, x, zero); + auto term2 = x * label; + auto term3 = log(1 + exp(-abs(x))); + const Tensor tmp_out = term1 - term2 + term3 * pos_weight_tensor; + const Tensor ignore_index_tensor = full(dims, ignore_index, label.type()); + auto out = where(label == ignore_index_tensor, zero, tmp_out); + if (normalize) { + // Follow the implementation in + // paddle/phi/kernels/cpu/sigmoid_cross_entropy_with_logits_kernel.cc + const Tensor eps1 = full(dims, 1e-6, x.type()); + auto diff = label - ignore_index_tensor; + const Tensor tmp_norm = sum(where(abs(diff) > eps1, one, zero)); + // Follow the implementation in + // paddle/phi/kernels/cpu/sigmoid_cross_entropy_with_logits_kernel.cc + const Tensor eps2 = full(empty_shape, 1e-5, x.type()); + auto norm = where(tmp_norm > eps2, tmp_norm, eps2); + out = out / norm; + } + return out; +} + +template +Tensor mean_all_decomp(const Tensor& x) { + auto org_dtype = x.dtype(); + auto x_cast = x; + auto x_shape = x.shape(); + bool need_cast = is_half_dtype(org_dtype); + if (need_cast) { + x_cast = cast(x, DataType::FLOAT32); + } + + Tensor ans; + if (has_dynamic_shape(x_shape)) { + Tensor x_shape_tensor = shape(x_cast); + Tensor value = get_slice(x_shape_tensor, 0); + for (size_t i = 1; i < x_shape.size(); i++) { + value = value * get_slice(x_shape_tensor, i); + } + value = reshape(value, {}); + ans = sum(x_cast) / cast(value, x_cast.dtype()); + } else { + ans = sum(x_cast) / x_cast.numel(); + } + + if (need_cast) { + return cast(ans, org_dtype); + } else { + return ans; + } +} + template Tensor embedding_decomp(const Tensor& x, const Tensor& weight, diff --git a/test/deprecated/legacy_test/test_sigmoid_cross_entropy_with_logits_op.py b/test/deprecated/legacy_test/test_sigmoid_cross_entropy_with_logits_op.py index fcfba56f473fc..5aeef1bd39592 100644 --- a/test/deprecated/legacy_test/test_sigmoid_cross_entropy_with_logits_op.py +++ b/test/deprecated/legacy_test/test_sigmoid_cross_entropy_with_logits_op.py @@ -38,6 +38,8 @@ class TestSigmoidCrossEntropyWithLogitsOp1(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = 64 num_classes = 20 self.inputs = { @@ -60,10 +62,10 @@ def setUp(self): self.outputs = {'Out': -term1 - term2} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithLogitsOp2(OpTest): @@ -72,6 +74,8 @@ class TestSigmoidCrossEntropyWithLogitsOp2(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = 64 num_classes = 20 ignore_index = -1 @@ -99,10 +103,10 @@ def setUp(self): self.outputs = {'Out': out} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithLogitsOp3(OpTest): @@ -111,6 +115,8 @@ class TestSigmoidCrossEntropyWithLogitsOp3(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = 64 num_classes = 20 self.inputs = { @@ -133,10 +139,10 @@ def setUp(self): self.outputs = {'Out': -term1 - term2} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithLogitsOp4(OpTest): @@ -145,6 +151,8 @@ class TestSigmoidCrossEntropyWithLogitsOp4(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = 64 num_classes = 20 @@ -171,7 +179,7 @@ def setUp(self): self.outputs = {'Out': term1 - term2 + term3} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): self.check_grad(['X'], 'Out', max_relative_error=0.0005, check_pir=True) @@ -181,6 +189,8 @@ class TestSigmoidCrossEntropyWithNorm(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = 64 num_classes = 20 ignore_index = -1 @@ -207,10 +217,10 @@ def setUp(self): self.outputs = {'Out': out} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithLogitsOp5(OpTest): @@ -219,6 +229,8 @@ class TestSigmoidCrossEntropyWithLogitsOp5(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = [10, 10] num_classes = 20 self.inputs = { @@ -241,16 +253,18 @@ def setUp(self): self.outputs = {'Out': -term1 - term2} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithNorm2(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = [10, 10] num_classes = 20 ignore_index = -1 @@ -277,10 +291,10 @@ def setUp(self): self.outputs = {'Out': out} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithLogitsOp6(OpTest): @@ -289,6 +303,8 @@ class TestSigmoidCrossEntropyWithLogitsOp6(OpTest): def setUp(self): self.op_type = "sigmoid_cross_entropy_with_logits" self.python_api = loss_wrapper + self.prim_op_type = "comp" + self.public_python_api = loss_wrapper batch_size = [10, 10] num_classes = 20 self.inputs = { @@ -311,10 +327,10 @@ def setUp(self): self.outputs = {'Out': -term1 - term2} def test_check_output(self): - self.check_output(check_pir=True) + self.check_output(check_pir=True, check_prim_pir=True) def test_check_grad(self): - self.check_grad(['X'], 'Out', check_pir=True) + self.check_grad(['X'], 'Out', check_pir=True, check_prim_pir=True) class TestSigmoidCrossEntropyWithLogitsOpError(unittest.TestCase): diff --git a/test/legacy_test/test_binary_cross_entropy_with_logits_op.py b/test/legacy_test/test_binary_cross_entropy_with_logits_op.py new file mode 100644 index 0000000000000..2fce79faa466d --- /dev/null +++ b/test/legacy_test/test_binary_cross_entropy_with_logits_op.py @@ -0,0 +1,85 @@ +# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import unittest + +import numpy as np + +import paddle + + +class TestBinaryCrossEntropyWithLogits(unittest.TestCase): + def setUp(self): + np.random.seed(2023) + self.x = np.random.randn(300, 1000).astype("float32") + self.y = np.random.randint(0, 2, (300, 1000)).astype("float32") + self.logits = paddle.to_tensor(self.x) + self.labels = paddle.to_tensor(self.y) + self.weight = paddle.to_tensor( + np.random.randn(300, 1000).astype("float32") + ) + self.reduction = ["none", "mean", "sum"] + self.pos_weight = paddle.to_tensor( + np.random.randn(1000).astype("float32") + ) + + def test_binary_cross_entropy_with_logits(self): + for reduction in self.reduction: + dynamic_result = ( + paddle.nn.functional.binary_cross_entropy_with_logits( + self.logits, + self.labels, + weight=self.weight, + reduction=reduction, + pos_weight=self.pos_weight, + ) + ) + paddle.core._set_prim_all_enabled(True) + static_result = paddle.jit.to_static( + paddle.nn.functional.binary_cross_entropy_with_logits, + full_graph=True, + )( + self.logits, + self.labels, + weight=self.weight, + reduction=reduction, + pos_weight=self.pos_weight, + ) + paddle.core._set_prim_all_enabled(False) + np.testing.assert_allclose( + dynamic_result.numpy(), static_result.numpy(), rtol=1e-4 + ) + + +class TestBinaryCrossEntropyWithLogits1(TestBinaryCrossEntropyWithLogits): + def setUp(self): + super().setUp() + self.weight = None + + +class TestBinaryCrossEntropyWithLogits2(TestBinaryCrossEntropyWithLogits): + def setUp(self): + super().setUp() + self.pos_weight = None + + +class TestBinaryCrossEntropyWithLogits3(TestBinaryCrossEntropyWithLogits): + def setUp(self): + super().setUp() + self.weight = None + self.pos_weight = None + + +if __name__ == "__main__": + unittest.main() diff --git a/test/prim/pir_prim/test_prim_sub_graph_dynamic_shape.py b/test/prim/pir_prim/test_prim_sub_graph_dynamic_shape.py index 246d1e37de831..9002101f5af98 100644 --- a/test/prim/pir_prim/test_prim_sub_graph_dynamic_shape.py +++ b/test/prim/pir_prim/test_prim_sub_graph_dynamic_shape.py @@ -94,6 +94,10 @@ def dropout_net1(x): return paddle.nn.functional.dropout(x, 0.5) +def mean_all_net1(x): + return paddle._C_ops.mean_all(x) + + group_norm1 = paddle.nn.GroupNorm(num_channels=128, num_groups=32) @@ -530,5 +534,18 @@ def setUp(self): self.tol = 1e-6 +class TestPrimMeanAll(TestPrimBase): + def setUp(self): + np.random.seed(2023) + paddle.seed(2023) + self.shape_x = [300, 4096] + self.dtype_x = "float32" + self.init_x_shape = [None, 4096] + self.x = np.random.random(self.shape_x).astype(self.dtype_x) + self.net = mean_all_net1 + self.necessary_ops = "pd_op.mean_all" + self.enable_cinn = False + + if __name__ == "__main__": unittest.main()