diff --git a/paddle/fluid/framework/custom_operator.cc b/paddle/fluid/framework/custom_operator.cc index cbc7d3fec23eddc73ee5e91082759ef16e840858..66e28bb83ce3e42d0b7358bf462cb98e70617fe4 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 c62e5683491268b8b960741d32fb3e4cb89898c5..33cca31e0628e9e6d8b6c4938c5417106def1c47 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;