From 628f085687e9850f4724c46d3c190e403bdf0966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E6=99=93=E4=BC=9F?= <39303645+Shixiaowei02@users.noreply.github.com> Date: Mon, 1 Mar 2021 19:02:25 +0800 Subject: [PATCH] [Cherry-pick] inference modification for custom operator (#31283) (#31300) --- paddle/fluid/framework/custom_operator.cc | 4 ---- paddle/fluid/inference/api/analysis_predictor.cc | 7 +++++++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index cbc7d3fec23..66e28bb83ce 100644 --- a/paddle/fluid/framework/custom_operator.cc +++ b/paddle/fluid/framework/custom_operator.cc @@ -667,10 +667,6 @@ void RegisterOperatorWithMetaInfo( void RegisterOperatorWithMetaInfoMap( const paddle::OpMetaInfoMap& op_meta_info_map) { auto& meta_info_map = op_meta_info_map.GetMap(); - - PADDLE_ENFORCE_EQ(meta_info_map.empty(), false, - platform::errors::PreconditionNotMet( - "No custom operator that needs to be registered.")); VLOG(1) << "Custom Operator: size of op meta info map - " << meta_info_map.size(); // pair: {op_type, OpMetaInfo} diff --git a/paddle/fluid/inference/api/analysis_predictor.cc b/paddle/fluid/inference/api/analysis_predictor.cc index c62e5683491..33cca31e062 100644 --- a/paddle/fluid/inference/api/analysis_predictor.cc +++ b/paddle/fluid/inference/api/analysis_predictor.cc @@ -21,6 +21,7 @@ #include #include #include +#include "paddle/fluid/extension/include/ext_op_meta_info.h" #include "paddle/fluid/framework/feed_fetch_method.h" #include "paddle/fluid/framework/feed_fetch_type.h" #include "paddle/fluid/framework/ir/fuse_pass_base.h" @@ -612,6 +613,12 @@ std::unique_ptr CreatePaddlePredictor< platform::errors::InvalidArgument( "Note: Each config can only be used for one predictor.")); + // Register custom operators compiled by the user. + // This function can only be executed once per process. + static std::once_flag custom_operators_registered; + std::call_once(custom_operators_registered, + []() { paddle::RegisterAllCustomOperator(); }); + if (config.use_gpu()) { static std::once_flag gflags_initialized; static bool process_level_allocator_enabled; -- GitLab