From d290693333fb85a0acdc18a61f948164ceb03c22 Mon Sep 17 00:00:00 2001 From: MRXLT Date: Sun, 19 Jan 2020 14:42:29 +0800 Subject: [PATCH] optimize general server config --- .../proto/general_model_config.proto | 6 ++-- core/predictor/framework/resource.cpp | 11 +++----- .../demo-serving/conf/general_model.prototxt | 28 ++++++------------- examples/demo-serving/op/general_model_op.cpp | 10 ------- 4 files changed, 15 insertions(+), 40 deletions(-) diff --git a/core/configure/proto/general_model_config.proto b/core/configure/proto/general_model_config.proto index 310ad9e2..22f31047 100644 --- a/core/configure/proto/general_model_config.proto +++ b/core/configure/proto/general_model_config.proto @@ -15,17 +15,15 @@ syntax = "proto2"; package baidu.paddle_serving.configure; -message Shape { repeated int32 shape = 1; }; - message FeedVar { required string name = 1; required bool is_lod_tensor = 2; required int32 feed_type = 3; - required Shape feed_shape = 4; + repeated int32 shape = 4; } message FetchVar { required string name = 1; - required Shape fetch_shape = 2; + repeated int32 shape = 2; } message GeneralModelConfig { repeated FeedVar feed_var = 1; diff --git a/core/predictor/framework/resource.cpp b/core/predictor/framework/resource.cpp index 0fa5e035..e24f3e88 100644 --- a/core/predictor/framework/resource.cpp +++ b/core/predictor/framework/resource.cpp @@ -23,7 +23,6 @@ namespace predictor { using configure::ResourceConf; using configure::GeneralModelConfig; -using configure::Shape; using rec::mcube::CubeAPI; // __thread bool p_thread_initialized = false; @@ -198,9 +197,8 @@ int Resource::general_model_initialize(const std::string& path, } else { _config->_capacity[i] = 1; _config->_is_lod_feed[i] = false; - for (int j = 0; j < model_config.feed_var(i).feed_shape().shape_size(); - ++j) { - int32_t dim = model_config.feed_var(i).feed_shape().shape(j); + for (int j = 0; j < model_config.feed_var(i).shape_size(); ++j) { + int32_t dim = model_config.feed_var(i).shape(j); _config->_feed_shape[i].push_back(dim); _config->_capacity[i] *= dim; } @@ -212,9 +210,8 @@ int Resource::general_model_initialize(const std::string& path, _config->_fetch_shape.resize(fetch_var_num); for (int i = 0; i < fetch_var_num; ++i) { _config->_fetch_name[i] = model_config.fetch_var(i).name(); - for (int j = 0; j < model_config.fetch_var(i).fetch_shape().shape_size(); - ++j) { - int dim = model_config.fetch_var(i).fetch_shape().shape(j); + for (int j = 0; j < model_config.fetch_var(i).shape_size(); ++j) { + int dim = model_config.fetch_var(i).shape(j); _config->_fetch_shape[i].push_back(dim); } } diff --git a/examples/demo-serving/conf/general_model.prototxt b/examples/demo-serving/conf/general_model.prototxt index efb09137..984526e6 100644 --- a/examples/demo-serving/conf/general_model.prototxt +++ b/examples/demo-serving/conf/general_model.prototxt @@ -1,34 +1,24 @@ feed_var { name: "words" - is_lod_tensor: false + is_lod_tensor: true feed_type: 0 - feed_shape { - shape: -1 - } + shape: -1 } feed_var { name: "label" is_lod_tensor: false feed_type: 0 - feed_shape { - shape: 1 - } + shape: 1 } fetch_var { - name: "mean_0.tmp_0" - fetch_shape { - shape: 1 - } + name: "cost" + shape: 1 } fetch_var { - name: "accuracy_0.tmp_0" - fetch_shape { - shape: 1 - } + name: "acc" + shape: 1 } fetch_var { - name: "fc_1.tmp_2" - fetch_shape { - shape: 1 - } + name: "prediction" + shape: 2 } diff --git a/examples/demo-serving/op/general_model_op.cpp b/examples/demo-serving/op/general_model_op.cpp index 1b6c3695..3e4896b3 100644 --- a/examples/demo-serving/op/general_model_op.cpp +++ b/examples/demo-serving/op/general_model_op.cpp @@ -48,16 +48,6 @@ int GeneralModelOp::inference() { std::vector elem_size; std::vector capacity; - // config - LOG(INFO) << "start to call load general model_conf op"; - baidu::paddle_serving::predictor::Resource &resource = - baidu::paddle_serving::predictor::Resource::instance(); - LOG(INFO) << "get resource pointer done."; - std::shared_ptr model_config = - resource.get_general_model_config(); - LOG(INFO) << "get general model config pointer done."; - resource.print_general_model_config(model_config); - // infer if (batch_size > 0) { int var_num = req->insts(0).tensor_array_size(); -- GitLab