From 85dbcefd103ab87dc3bd6b505ca0e0a65e9bd57a Mon Sep 17 00:00:00 2001 From: wanghuancoder Date: Wed, 6 Sep 2023 11:06:41 +0800 Subject: [PATCH] [NewIR] add_n and combine support selected rows (#56754) * add_n and combine support selected rows --- .../fluid/ir/dialect/op_generator/op_gen.py | 2 +- .../dialect/paddle_dialect/ir/pd_dialect.cc | 5 +- .../dialect/paddle_dialect/ir/pd_manual_op.cc | 270 +++++++++++++++++- .../dialect/paddle_dialect/ir/pd_manual_op.h | 44 +++ .../ir/phi_kernel_adaptor/phi_kernel_util.h | 28 +- .../ir/transforms/pd_op_to_kernel_pass.cc | 138 +++++++-- .../ir_adaptor/translator/op_translator.cc | 4 +- test/dygraph_to_static/test_simnet.py | 2 + test/dygraph_to_static/test_simnet_v2.py | 2 + 9 files changed, 454 insertions(+), 41 deletions(-) diff --git a/paddle/fluid/ir/dialect/op_generator/op_gen.py b/paddle/fluid/ir/dialect/op_generator/op_gen.py index 5d51a731c54..1c19874dd9b 100644 --- a/paddle/fluid/ir/dialect/op_generator/op_gen.py +++ b/paddle/fluid/ir/dialect/op_generator/op_gen.py @@ -172,7 +172,7 @@ scalar_type_maps = { 'bool': 'ir::BoolAttribute', } -_NO_NEED_GEN_OPS = {'add_n', 'split_grad'} +_NO_NEED_GEN_OPS = {'add_n', 'add_n_', 'add_n_with_kernel', 'split_grad'} def to_phi_and_fluid_op_name(op_item): diff --git a/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_dialect.cc b/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_dialect.cc index 19b8b133559..9d24dcd2778 100644 --- a/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_dialect.cc +++ b/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_dialect.cc @@ -48,7 +48,10 @@ void PaddleDialect::initialize() { #define GET_OP_LIST #include "paddle/fluid/ir/dialect/paddle_dialect/ir/pd_op.h" // NOLINT >(); - RegisterOps(); + RegisterOps(); RegisterInterfaces(); } diff --git a/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.cc b/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.cc index 33469fef8fa..d50faedfd56 100644 --- a/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.cc +++ b/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.cc @@ -57,13 +57,18 @@ void AddNOp::Verify() { "The size %d of inputs must be equal to 1.", input_size)); if (auto vec_type = (*this)->operand(0).type().dyn_cast()) { for (size_t i = 0; i < vec_type.size(); ++i) { - PADDLE_ENFORCE(vec_type[i].isa(), + PADDLE_ENFORCE(vec_type[i].isa() || + vec_type[i].isa(), phi::errors::PreconditionNotMet( "Type validation failed for the 0th input.")); } } else { PADDLE_ENFORCE( - (*this)->operand(0).type().isa(), + (*this)->operand(0).type().isa() || + (*this) + ->operand(0) + .type() + .isa(), phi::errors::PreconditionNotMet( "Type validation failed for the 0th input.")); } @@ -81,7 +86,8 @@ void AddNOp::Verify() { phi::errors::PreconditionNotMet( "The size %d of outputs must be equal to 1.", output_size)); PADDLE_ENFORCE( - (*this)->result(0).type().isa(), + (*this)->result(0).type().isa() || + (*this)->result(0).type().isa(), phi::errors::PreconditionNotMet( "Type validation failed for the 0th output.")); } @@ -146,6 +152,262 @@ void AddNOp::InferMeta(phi::InferMetaContext *infer_meta) { fn(infer_meta); } +OpInfoTuple AddN_Op::GetOpInfo() { + std::vector inputs = { + paddle::dialect::OpInputInfo( + "inputs", + "ir::VectorType", + false, + false, + false)}; + std::vector attributes = {}; + std::vector outputs = { + paddle::dialect::OpOutputInfo( + "out", "paddle::dialect::DenseTensorType", false, false)}; + paddle::dialect::OpRunTimeInfo run_time_info = paddle::dialect::OpRunTimeInfo( + "AddNInferMeta", {"inputs"}, {"add_n"}, {"inputs"}, {}, {}, {}, {}); + return std::make_tuple(inputs, attributes, outputs, run_time_info, "add_n_"); +} + +void AddN_Op::Build(ir::Builder &builder, + ir::OperationArgument &argument, + ir::OpResult inputs_) { + VLOG(4) << "Builder construction inputs"; + std::vector argument_inputs = {inputs_}; + argument.AddOperands(argument_inputs.begin(), argument_inputs.end()); + + VLOG(4) << "Builder construction attributes"; + + VLOG(4) << "Builder construction outputs"; + ir::VectorType inputs = inputs_.type().dyn_cast(); + (void)inputs; + std::vector vec_dense_inputs; + for (size_t i = 0; i < static_cast(inputs.size()); i++) { + vec_dense_inputs.push_back(phi::DenseTensor( + std::make_unique( + paddle::platform::CPUPlace()) + .get(), + phi::DenseTensorMeta( + paddle::dialect::TransToPhiDataType( + inputs[i].dyn_cast().dtype()), + inputs[i].dyn_cast().dims(), + inputs[i] + .dyn_cast() + .data_layout(), + inputs[i].dyn_cast().lod(), + inputs[i].dyn_cast().offset()))); + } + std::vector vec_meta_inputs; + for (size_t i = 0; i < vec_dense_inputs.size(); i++) { + vec_meta_inputs.push_back(phi::MetaTensor(&vec_dense_inputs[i])); + } + + std::vector meta_inputs; + for (size_t i = 0; i < static_cast(vec_meta_inputs.size()); i++) { + meta_inputs.push_back(&vec_meta_inputs[i]); + } + phi::DenseTensor dense_out; + phi::MetaTensor meta_out(&dense_out); + + phi::AddNInferMeta(meta_inputs, &meta_out); + + std::vector argument_outputs; + ir::Type out_dense_tensor_type = paddle::dialect::DenseTensorType::get( + ir::IrContext::Instance(), + paddle::dialect::TransToIrDataType(dense_out.dtype()), + dense_out.dims(), + dense_out.layout(), + dense_out.lod(), + dense_out.offset()); + argument_outputs.push_back(out_dense_tensor_type); + argument.AddOutputs(argument_outputs.begin(), argument_outputs.end()); +} + +void AddN_Op::Verify() { + VLOG(4) << "Start Verifying inputs, outputs and attributes for: AddN_Op."; + VLOG(4) << "Verifying inputs:"; + { + auto input_size = num_operands(); + PADDLE_ENFORCE_EQ( + input_size, + 1u, + phi::errors::PreconditionNotMet( + "The size %d of inputs must be equal to 1.", input_size)); + if (auto vec_type = + (*this)->operand_source(0).type().dyn_cast()) { + for (size_t i = 0; i < vec_type.size(); ++i) { + PADDLE_ENFORCE(vec_type[i].isa() || + vec_type[i].isa(), + phi::errors::PreconditionNotMet( + "Type validation failed for the 0th input.")); + } + } else { + PADDLE_ENFORCE((*this)->operand_source(0) + .type() + .isa() || + (*this) + ->operand_source(0) + .type() + .isa(), + phi::errors::PreconditionNotMet( + "Type validation failed for the 0th input.")); + } + } + VLOG(4) << "Verifying attributes:"; + { + // Attributes num is 0, not need to check attributes type. + } + VLOG(4) << "Verifying outputs:"; + { + auto output_size = num_results(); + PADDLE_ENFORCE_EQ( + output_size, + 1u, + phi::errors::PreconditionNotMet( + "The size %d of outputs must be equal to 1.", output_size)); + PADDLE_ENFORCE( + (*this)->result(0).type().isa() || + (*this)->result(0).type().isa(), + phi::errors::PreconditionNotMet( + "Type validation failed for the 0th output.")); + } + VLOG(4) << "End Verifying for: AddN_Op."; +} + +void AddN_Op::InferMeta(phi::InferMetaContext *infer_meta) { + auto fn = PD_INFER_META(phi::AddNInferMeta); + fn(infer_meta); +} + +OpInfoTuple AddNWithKernelOp::GetOpInfo() { + std::vector inputs = { + paddle::dialect::OpInputInfo( + "inputs", + "ir::VectorType", + false, + false, + false)}; + std::vector attributes = {}; + std::vector outputs = { + paddle::dialect::OpOutputInfo( + "out", "paddle::dialect::DenseTensorType", false, false)}; + paddle::dialect::OpRunTimeInfo run_time_info = paddle::dialect::OpRunTimeInfo( + "AddNInferMeta", {"inputs"}, {"add_n"}, {"inputs"}, {}, {}, {}, {}); + return std::make_tuple( + inputs, attributes, outputs, run_time_info, "add_n_with_kernel"); +} + +void AddNWithKernelOp::Build(ir::Builder &builder, + ir::OperationArgument &argument, + ir::OpResult inputs_) { + VLOG(4) << "Builder construction inputs"; + std::vector argument_inputs = {inputs_}; + argument.AddOperands(argument_inputs.begin(), argument_inputs.end()); + + VLOG(4) << "Builder construction attributes"; + + VLOG(4) << "Builder construction outputs"; + ir::VectorType inputs = inputs_.type().dyn_cast(); + (void)inputs; + std::vector vec_dense_inputs; + for (size_t i = 0; i < static_cast(inputs.size()); i++) { + vec_dense_inputs.push_back(phi::DenseTensor( + std::make_unique( + paddle::platform::CPUPlace()) + .get(), + phi::DenseTensorMeta( + paddle::dialect::TransToPhiDataType( + inputs[i].dyn_cast().dtype()), + inputs[i].dyn_cast().dims(), + inputs[i] + .dyn_cast() + .data_layout(), + inputs[i].dyn_cast().lod(), + inputs[i].dyn_cast().offset()))); + } + std::vector vec_meta_inputs; + for (size_t i = 0; i < vec_dense_inputs.size(); i++) { + vec_meta_inputs.push_back(phi::MetaTensor(&vec_dense_inputs[i])); + } + + std::vector meta_inputs; + for (size_t i = 0; i < static_cast(vec_meta_inputs.size()); i++) { + meta_inputs.push_back(&vec_meta_inputs[i]); + } + phi::DenseTensor dense_out; + phi::MetaTensor meta_out(&dense_out); + + phi::AddNInferMeta(meta_inputs, &meta_out); + + std::vector argument_outputs; + ir::Type out_dense_tensor_type = paddle::dialect::DenseTensorType::get( + ir::IrContext::Instance(), + paddle::dialect::TransToIrDataType(dense_out.dtype()), + dense_out.dims(), + dense_out.layout(), + dense_out.lod(), + dense_out.offset()); + argument_outputs.push_back(out_dense_tensor_type); + argument.AddOutputs(argument_outputs.begin(), argument_outputs.end()); +} + +void AddNWithKernelOp::Verify() { + VLOG(4) << "Start Verifying inputs, outputs and attributes for: " + "AddNWithKernelOp."; + VLOG(4) << "Verifying inputs:"; + { + auto input_size = num_operands(); + PADDLE_ENFORCE_EQ( + input_size, + 1u, + phi::errors::PreconditionNotMet( + "The size %d of inputs must be equal to 1.", input_size)); + if (auto vec_type = + (*this)->operand_source(0).type().dyn_cast()) { + for (size_t i = 0; i < vec_type.size(); ++i) { + PADDLE_ENFORCE(vec_type[i].isa() || + vec_type[i].isa(), + phi::errors::PreconditionNotMet( + "Type validation failed for the 0th input.")); + } + } else { + PADDLE_ENFORCE((*this)->operand_source(0) + .type() + .isa() || + (*this) + ->operand_source(0) + .type() + .isa(), + phi::errors::PreconditionNotMet( + "Type validation failed for the 0th input.")); + } + } + VLOG(4) << "Verifying attributes:"; + { + // Attributes num is 0, not need to check attributes type. + } + VLOG(4) << "Verifying outputs:"; + { + auto output_size = num_results(); + PADDLE_ENFORCE_EQ( + output_size, + 1u, + phi::errors::PreconditionNotMet( + "The size %d of outputs must be equal to 1.", output_size)); + PADDLE_ENFORCE( + (*this)->result(0).type().isa() || + (*this)->result(0).type().isa(), + phi::errors::PreconditionNotMet( + "Type validation failed for the 0th output.")); + } + VLOG(4) << "End Verifying for: AddNWithKernelOp."; +} + +void AddNWithKernelOp::InferMeta(phi::InferMetaContext *infer_meta) { + auto fn = PD_INFER_META(phi::AddNInferMeta); + fn(infer_meta); +} + const char *SplitGradOp::attributes_name[1] = {"axis"}; OpInfoTuple SplitGradOp::GetOpInfo() { @@ -364,3 +626,5 @@ void SplitGradOp::InferMeta(phi::InferMetaContext *infer_meta) { IR_DEFINE_EXPLICIT_TYPE_ID(paddle::dialect::AddNOp) IR_DEFINE_EXPLICIT_TYPE_ID(paddle::dialect::SplitGradOp) +IR_DEFINE_EXPLICIT_TYPE_ID(paddle::dialect::AddN_Op) +IR_DEFINE_EXPLICIT_TYPE_ID(paddle::dialect::AddNWithKernelOp) diff --git a/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.h b/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.h index b0ff45d9baa..8f0dbd86d1d 100644 --- a/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.h +++ b/paddle/fluid/ir/dialect/paddle_dialect/ir/pd_manual_op.h @@ -24,6 +24,7 @@ paddle::dialect::AddNOp, paddle::dialect::SplitGradOp #include "paddle/fluid/framework/infershape_utils.h" #include "paddle/fluid/ir/dialect/paddle_dialect/interface/infermeta.h" #include "paddle/fluid/ir/dialect/paddle_dialect/interface/op_yaml_info.h" +#include "paddle/fluid/ir/dialect/paddle_dialect/trait/inplace.h" #include "paddle/fluid/ir/dialect/paddle_dialect/utils/op_yaml_info_util.h" #include "paddle/fluid/ir/dialect/paddle_dialect/utils/utils.h" #include "paddle/ir/core/builder.h" @@ -51,6 +52,47 @@ class AddNOp : public ir::Op { static void InferMeta(phi::InferMetaContext *infer_meta); }; +class AddN_Op : public ir::Op { + public: + using Op::Op; + static const char *name() { return "pd.add_n_"; } + static constexpr const char **attributes_name = nullptr; + static constexpr uint32_t attributes_num = 0; + static OpInfoTuple GetOpInfo(); + static void Build(ir::Builder &builder, // NOLINT + ir::OperationArgument &argument, // NOLINT + ir::OpResult inputs_); + + void Verify(); + ir::Value inputs() { return operand_source(0); } + ir::OpResult out() { return result(0); } + + static void InferMeta(phi::InferMetaContext *infer_meta); +}; + +class AddNWithKernelOp : public ir::Op { + public: + using Op::Op; + static const char *name() { return "pd.add_n_with_kernel"; } + static constexpr const char **attributes_name = nullptr; + static constexpr uint32_t attributes_num = 0; + static OpInfoTuple GetOpInfo(); + static void Build(ir::Builder &builder, // NOLINT + ir::OperationArgument &argument, // NOLINT + ir::OpResult inputs_); + + void Verify(); + ir::Value inputs() { return operand_source(0); } + ir::OpResult out() { return result(0); } + + static void InferMeta(phi::InferMetaContext *infer_meta); +}; + class SplitGradOp : public ir::Op { public: using Op::Op; @@ -79,5 +121,7 @@ class SplitGradOp : public ir::Op { IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::AddNOp) IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::SplitGradOp) +IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::AddN_Op) +IR_DECLARE_EXPLICIT_TYPE_ID(paddle::dialect::AddNWithKernelOp) #endif diff --git a/paddle/fluid/ir/phi_kernel_adaptor/phi_kernel_util.h b/paddle/fluid/ir/phi_kernel_adaptor/phi_kernel_util.h index 1958a9444bc..b1916d5418f 100644 --- a/paddle/fluid/ir/phi_kernel_adaptor/phi_kernel_util.h +++ b/paddle/fluid/ir/phi_kernel_adaptor/phi_kernel_util.h @@ -118,8 +118,18 @@ void BuildPhiContext(ir::Operation* op, InListType inputs; auto& variable_array = var->Get(); for (size_t i = 0; i < variable_array.size(); ++i) { - inputs.emplace_back(InType(const_cast( - &(variable_array[i]->Get())))); + if (variable_array[i]->IsType()) { + inputs.emplace_back(InType(const_cast( + &(variable_array[i]->Get())))); + } else if (variable_array[i]->IsType()) { + inputs.emplace_back(InType(const_cast( + &(variable_array[i]->Get())))); + } else { + PADDLE_THROW(phi::errors::Unimplemented( + "Only support Vector and vector now, " + "not support vector<%d>.", + variable_array[i]->Type())); + } } ctx->EmplaceBackInputs(inputs); } else { @@ -315,8 +325,18 @@ void BuildPhiContext(ir::Operation* op, auto& variable_array = inner_scope->FindVar(name_map.at(out_ptr)) ->Get(); for (size_t i = 0; i < variable_array.size(); ++i) { - outputs.emplace_back(OutType(const_cast( - &(variable_array[i]->Get())))); + if (variable_array[i]->IsType()) { + outputs.emplace_back(OutType(const_cast( + &(variable_array[i]->Get())))); + } else if (variable_array[i]->IsType()) { + outputs.emplace_back(OutType(const_cast( + &(variable_array[i]->Get())))); + } else { + PADDLE_THROW(phi::errors::Unimplemented( + "Only support Vector and vector now, " + "not support vector<%d>.", + variable_array[i]->Type())); + } } ctx->EmplaceBackOutputs(outputs); } else { diff --git a/paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc b/paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc index 84f18baa55a..d75c7cc4779 100644 --- a/paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc +++ b/paddle/fluid/ir/transforms/pd_op_to_kernel_pass.cc @@ -149,34 +149,67 @@ bool SkipFeedOp(ir::Operation* op, const std::set& feed_names) { op->attributes().at("name").dyn_cast().AsString()); } -std::vector GetFakeTensorList(ir::Value new_input_tmp) { - std::vector vec_res; +std::vector> GetFakeTensorList( + ir::Value new_input_tmp) { + std::vector> vec_res; auto input_type = new_input_tmp.type(); - std::vector types; - if (input_type.isa()) { - types.push_back(input_type.dyn_cast()); - } else if (input_type.isa()) { - auto vec_inner_types = input_type.dyn_cast().data(); - for (size_t i = 0; i < vec_inner_types.size(); ++i) { - types.push_back( - vec_inner_types[0].dyn_cast()); - } - } - for (auto& type : types) { - auto ptr = new phi::Allocation(nullptr, 0, type.place()); + auto build_fake_dense_tensor = + [](const dialect::AllocatedDenseTensorType& type) { + auto ptr = new phi::Allocation(nullptr, 0, type.place()); + + std::shared_ptr holder(ptr); + + auto dtype = TransToPhiDataType(type.dtype()); - std::shared_ptr holder(ptr); + phi::DenseTensorMeta meta( + dtype, type.dims(), type.data_layout(), type.lod(), type.offset()); - auto dtype = TransToPhiDataType(type.dtype()); + return std::make_shared(holder, meta); + }; - phi::DenseTensorMeta meta( - dtype, type.dims(), type.data_layout(), type.lod(), type.offset()); + auto build_fake_selected_rows = + [](const dialect::AllocatedSelectedRowsType& type) { + auto ptr = new phi::Allocation(nullptr, 0, type.place()); - phi::DenseTensor fake_tensor(holder, meta); + std::shared_ptr holder(ptr); - vec_res.push_back(fake_tensor); + auto dtype = TransToPhiDataType(type.dtype()); + + phi::DenseTensorMeta meta( + dtype, type.dims(), type.data_layout(), type.lod(), type.offset()); + + std::vector rows; + int64_t height = 0; + rows.clear(); + + auto sr = std::make_shared(rows, height); + + phi::DenseTensor dense_tensor(holder, meta); + *(sr->mutable_value()) = dense_tensor; + + return sr; + }; + + if (input_type.isa()) { + vec_res.push_back(build_fake_dense_tensor( + input_type.dyn_cast())); + } else if (input_type.isa()) { + vec_res.push_back(build_fake_selected_rows( + input_type.dyn_cast())); + } else if (input_type.isa()) { + auto vec_inner_types = input_type.dyn_cast().data(); + for (size_t i = 0; i < vec_inner_types.size(); ++i) { + if (vec_inner_types[0].isa()) { + vec_res.push_back(build_fake_dense_tensor( + vec_inner_types[0].dyn_cast())); + } else if (vec_inner_types[0].isa()) { + vec_res.push_back(build_fake_selected_rows( + vec_inner_types[0].dyn_cast())); + } + } } + return vec_res; } @@ -514,7 +547,7 @@ phi::KernelKey GetKernelKey( auto fake_tensors = GetFakeTensorList(new_input_tmp); for (auto& fake_tensor : fake_tensors) { - kernel_key_parser.AssignKernelKeySet(fake_tensor); + kernel_key_parser.AssignKernelKeySet(*fake_tensor); } // Because we can't make sure the place when build data op @@ -617,6 +650,12 @@ std::unique_ptr PdOpLowerToKernelPass(ir::Program* prog, new_in.type() .dyn_cast() .place()); + } else if (new_in.type() + .isa()) { + out_places.push_back( + new_in.type() + .dyn_cast() + .place()); } else { PADDLE_THROW(phi::errors::Unimplemented( "only support dense tensor type for now")); @@ -759,6 +798,14 @@ std::unique_ptr PdOpLowerToKernelPass(ir::Program* prog, if (op_info_parser != nullptr) { kernel_fn_str = op_info_parser->OpRuntimeInfo().kernel_func[0]; } + + if (op_item->name() == "pd.add_n_" || + op_item->name() == "pd.add_n_with_kernel") { + if (op_item->result(0).type().isa()) { + kernel_fn_str = "add_n_sr"; + } + } + auto kernel_key = GetKernelKey(op_item, place, map_value_pair, op_info_parser.get()); VLOG(6) << "kernel type " << kernel_key; @@ -929,9 +976,22 @@ std::unique_ptr PdOpLowerToKernelPass(ir::Program* prog, for (size_t j = 0; j < pre_define_op->num_operands(); ++j) { auto in_i = map_value_pair.at(pre_define_op->operand_source(j)); auto in_i_type = in_i.type(); - auto place = - in_i_type.dyn_cast() - .place(); + phi::Place place; + if (in_i_type.isa()) { + place = + in_i_type.dyn_cast() + .place(); + } else if (in_i_type + .isa()) { + place = + in_i_type.dyn_cast() + .place(); + } else { + PADDLE_THROW(phi::errors::Unimplemented( + "builtin.combine Input type only support " + "VectorType and " + "VectorType")); + } // get input args def type auto args_def = kernel.args_def(); @@ -949,12 +1009,30 @@ std::unique_ptr PdOpLowerToKernelPass(ir::Program* prog, // build memcopy op auto out_place = phi::TransToPhiPlace(kernel.InputAt(i).backend); - auto out_type = dialect::AllocatedDenseTensorType::get( - ctx, - out_place, - pre_define_op->operand_source(j) - .type() - .dyn_cast()); + + ir::Type out_type; + if (in_i_type.isa()) { + out_type = dialect::AllocatedDenseTensorType::get( + ctx, + out_place, + pre_define_op->operand_source(j) + .type() + .dyn_cast()); + } else if (in_i_type + .isa()) { + out_type = dialect::AllocatedSelectedRowsType::get( + ctx, + out_place, + pre_define_op->operand_source(j) + .type() + .dyn_cast()); + } else { + PADDLE_THROW(phi::errors::Unimplemented( + "builtin.combine Input type only support " + "VectorType and " + "VectorType")); + } + in_i = AddPlaceTransferOp(in_i, out_type, place, diff --git a/paddle/fluid/ir_adaptor/translator/op_translator.cc b/paddle/fluid/ir_adaptor/translator/op_translator.cc index 38d833fc312..e22fa5f3b37 100644 --- a/paddle/fluid/ir_adaptor/translator/op_translator.cc +++ b/paddle/fluid/ir_adaptor/translator/op_translator.cc @@ -1112,8 +1112,8 @@ struct AddNOpTranscriber : public OpTranscriber { } const auto& op_info = ctx->GetRegisteredOpInfo(target_op_name); if (!op_info) { - IR_THROW( - "Op assign_value should have corresponding OpInfo pd.assign_value_"); + IR_THROW("Op assign_value should have corresponding OpInfo %s", + target_op_name); } return op_info; diff --git a/test/dygraph_to_static/test_simnet.py b/test/dygraph_to_static/test_simnet.py index 2c69cf2072c..09ea063f9ad 100644 --- a/test/dygraph_to_static/test_simnet.py +++ b/test/dygraph_to_static/test_simnet.py @@ -17,6 +17,7 @@ import random import unittest import numpy as np +from dygraph_to_static_util import test_and_compare_with_new_ir from simnet_dygraph_model import BOW, HingeLoss import paddle @@ -176,6 +177,7 @@ def train(conf_dict, to_static): class TestSimnet(unittest.TestCase): + @test_and_compare_with_new_ir(True) def test_dygraph_static_same_loss(self): if fluid.is_compiled_with_cuda(): fluid.set_flags({"FLAGS_cudnn_deterministic": True}) diff --git a/test/dygraph_to_static/test_simnet_v2.py b/test/dygraph_to_static/test_simnet_v2.py index a49cc23af11..316464ab791 100644 --- a/test/dygraph_to_static/test_simnet_v2.py +++ b/test/dygraph_to_static/test_simnet_v2.py @@ -17,6 +17,7 @@ import random import unittest import numpy as np +from dygraph_to_static_util import test_and_compare_with_new_ir from simnet_dygraph_model_v2 import BOW, HingeLoss import paddle @@ -176,6 +177,7 @@ def train(conf_dict, to_static): class TestSimnet(unittest.TestCase): + @test_and_compare_with_new_ir(True) def test_dygraph_static_same_loss(self): if paddle.is_compiled_with_cuda(): paddle.fluid.set_flags({"FLAGS_cudnn_deterministic": True}) -- GitLab