diff --git a/core/configure/proto/multi_lang_general_model_service.proto b/core/configure/proto/multi_lang_general_model_service.proto index c23f4dbb243e8d23b8e4bfef419649b262f0dcd3..18fbcf760647e1694e738c0832fe45f4f7d9934f 100644 --- a/core/configure/proto/multi_lang_general_model_service.proto +++ b/core/configure/proto/multi_lang_general_model_service.proto @@ -14,6 +14,8 @@ syntax = "proto2"; +package baidu.paddle_serving.multi_lang; + option java_multiple_files = true; option java_package = "io.paddle.serving.grpc"; option java_outer_classname = "ServingProto"; diff --git a/core/configure/proto/server_configure.proto b/core/configure/proto/server_configure.proto index 8956022685090c94be2037445c646e9fbffd1a5c..de32637b2a523df1a8d8cd2e28dcf29e79ff96dc 100644 --- a/core/configure/proto/server_configure.proto +++ b/core/configure/proto/server_configure.proto @@ -58,6 +58,8 @@ message ResourceConf { optional string cube_config_path = 5; optional string cube_config_file = 6; optional int32 cube_quant_bits = 7; // set 0 if no quant. + optional string auth_product_name = 8; + optional string auth_container_id = 9; }; // DAG node depency info diff --git a/core/cube/cube-api/include/meta.h b/core/cube/cube-api/include/meta.h index 69bbb8ccc12e423d286183ed5dd87e90bf2e59de..ec872a38d8b0294f7b06e8557848f6e8ca79aa2b 100644 --- a/core/cube/cube-api/include/meta.h +++ b/core/cube/cube-api/include/meta.h @@ -22,7 +22,8 @@ #ifdef BCLOUD #include "baidu/rpc/channel.h" #include "baidu/rpc/parallel_channel.h" -#include "rapidjson/document.h" +#include "rapidjson_1.0/document.h" +#include "rapidjson_1.0/rapidjson.h" #else #include "brpc/channel.h" #include "brpc/parallel_channel.h" diff --git a/core/general-client/src/general_model.cpp b/core/general-client/src/general_model.cpp index 6804a9e80d4140d02a5d46c7f3358f2403ee4fbb..a3160830a71c1244af209671da3f96d559c47f02 100644 --- a/core/general-client/src/general_model.cpp +++ b/core/general-client/src/general_model.cpp @@ -39,7 +39,9 @@ using configure::GeneralModelConfig; void PredictorClient::init_gflags(std::vector argv) { std::call_once(gflags_init_flag, [&]() { +#ifndef BCLOUD FLAGS_logtostderr = true; +#endif argv.insert(argv.begin(), "dummy"); int argc = argv.size(); char **arr = new char *[argv.size()]; diff --git a/core/general-server/op/general_copy_op.h b/core/general-server/op/general_copy_op.h index 89627ffb9e4d15bbcbfa6c7fc3a608ada03dad6e..9b4caadc6a82f1f1a601ab66394b3f629af703ff 100644 --- a/core/general-server/op/general_copy_op.h +++ b/core/general-server/op/general_copy_op.h @@ -13,20 +13,12 @@ // limitations under the License. #pragma once -#include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include +#include #include "core/general-server/general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" #include "core/predictor/framework/resource.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_dist_kv_infer_op.h b/core/general-server/op/general_dist_kv_infer_op.h index 2dee5bca6f9e12dbb8b36a6c39aa0a8e77763d23..56d19ee366feaf000d7b24f4017b39155b7e65c1 100644 --- a/core/general-server/op/general_dist_kv_infer_op.h +++ b/core/general-server/op/general_dist_kv_infer_op.h @@ -15,17 +15,9 @@ #pragma once #include #include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include "core/general-server/general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_dist_kv_quant_infer_op.h b/core/general-server/op/general_dist_kv_quant_infer_op.h index e153311a2a2e2df1bd12720e2ce6cbe9ddb31ec0..0f99e2072374bc4bc0b76a1ca876a152f98488b6 100644 --- a/core/general-server/op/general_dist_kv_quant_infer_op.h +++ b/core/general-server/op/general_dist_kv_quant_infer_op.h @@ -15,17 +15,9 @@ #pragma once #include #include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include "core/general-server/general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_infer_helper.h b/core/general-server/op/general_infer_helper.h index 9b5a023b8f5df49c6fb5404f11d7e4c7b2979176..40320348349a43aa79ce0d599f3aebeb764dc10e 100644 --- a/core/general-server/op/general_infer_helper.h +++ b/core/general-server/op/general_infer_helper.h @@ -15,17 +15,9 @@ #pragma once #include +#include #include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else #include "paddle_inference_api.h" // NOLINT -#endif -#include namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_infer_op.cpp b/core/general-server/op/general_infer_op.cpp index 1fe9e738c001163b9d14beea25f8c311b861510a..b9478542c71e04b0f3f80b277da7d8d41f636d3d 100644 --- a/core/general-server/op/general_infer_op.cpp +++ b/core/general-server/op/general_infer_op.cpp @@ -60,10 +60,11 @@ int GeneralInferOp::inference() { const TensorVector *in = &input_blob->tensor_vector; TensorVector *out = &output_blob->tensor_vector; - int batch_size = input_blob->GetBatchSize(); + + int batch_size = input_blob->_batch_size; VLOG(2) << "(logid=" << log_id << ") input batch size: " << batch_size; - output_blob->SetBatchSize(batch_size); + output_blob->_batch_size = batch_size; VLOG(2) << "(logid=" << log_id << ") infer batch size: " << batch_size; diff --git a/core/general-server/op/general_infer_op.h b/core/general-server/op/general_infer_op.h index ff0b210ad7c6824a7e8a61e9ac504a65eafa4c58..b41784185ff445c540774b8b24ef897caf6fbf96 100644 --- a/core/general-server/op/general_infer_op.h +++ b/core/general-server/op/general_infer_op.h @@ -15,17 +15,9 @@ #pragma once #include #include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include "core/general-server/general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_reader_op.cpp b/core/general-server/op/general_reader_op.cpp index 8a4aa1a11edd27a4c035cf707e335ac70647365b..14fd617e058ccc392a673678d03145ec1f6fd6d2 100644 --- a/core/general-server/op/general_reader_op.cpp +++ b/core/general-server/op/general_reader_op.cpp @@ -102,6 +102,7 @@ int GeneralReaderOp::inference() { baidu::paddle_serving::predictor::Resource::instance(); VLOG(2) << "(logid=" << log_id << ") get resource pointer done."; + std::shared_ptr model_config = resource.get_general_model_config(); @@ -265,6 +266,7 @@ int GeneralReaderOp::inference() { timeline.Pause(); int64_t end = timeline.TimeStampUS(); res->p_size = 0; + res->_batch_size = batch_size; AddBlobInfo(res, start); AddBlobInfo(res, end); diff --git a/core/general-server/op/general_reader_op.h b/core/general-server/op/general_reader_op.h index c45d6ad5139a7a9a267f1c6556028a99295500de..cb9693982ff659214dd21ff09f189f86b6b3a339 100644 --- a/core/general-server/op/general_reader_op.h +++ b/core/general-server/op/general_reader_op.h @@ -13,21 +13,13 @@ // limitations under the License. #pragma once -#include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include +#include #include "core/general-server/general_model_service.pb.h" #include "core/general-server/load_general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" #include "core/predictor/framework/resource.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_response_op.h b/core/general-server/op/general_response_op.h index 4b0f6ed17b5a66dbda7bccef25cec03bf044e6c5..0f72b8f98df336dd515560129a8cfd27650738bb 100644 --- a/core/general-server/op/general_response_op.h +++ b/core/general-server/op/general_response_op.h @@ -15,16 +15,8 @@ #pragma once #include #include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include "core/general-server/general_model_service.pb.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_text_reader_op.h b/core/general-server/op/general_text_reader_op.h index ca134256fce4aaa003f4b07033d4c471ebdb59b7..af822993dc37fae23c1fa584d640cbfe8d9950c8 100644 --- a/core/general-server/op/general_text_reader_op.h +++ b/core/general-server/op/general_text_reader_op.h @@ -13,21 +13,13 @@ // limitations under the License. #pragma once -#include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include +#include #include "core/general-server/general_model_service.pb.h" #include "core/general-server/load_general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" #include "core/predictor/framework/resource.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/general-server/op/general_text_response_op.h b/core/general-server/op/general_text_response_op.h index 52f7bbf0f7d76122bad14cf513302f70c35aa1d8..334d98476e67f745635f7d66d7b8682de62da355 100644 --- a/core/general-server/op/general_text_response_op.h +++ b/core/general-server/op/general_text_response_op.h @@ -15,17 +15,9 @@ #pragma once #include #include -#ifdef BCLOUD -#ifdef WITH_GPU -#include "paddle/paddle_inference_api.h" -#else -#include "paddle/fluid/inference/api/paddle_inference_api.h" -#endif -#else -#include "paddle_inference_api.h" // NOLINT -#endif #include "core/general-server/general_model_service.pb.h" #include "core/general-server/op/general_infer_helper.h" +#include "paddle_inference_api.h" // NOLINT namespace baidu { namespace paddle_serving { diff --git a/core/predictor/common/inner_common.h b/core/predictor/common/inner_common.h index 96b8a8027070da559e239cdc5f6057d534ff3412..f6847146ba14b2b9fc1b07485c748e6e8300d7bd 100644 --- a/core/predictor/common/inner_common.h +++ b/core/predictor/common/inner_common.h @@ -50,7 +50,7 @@ #include "butil/time.h" #endif -#include "glog/raw_logging.h" +#define ERROR_STRING_LEN 10240 #include "core/configure/general_model_config.pb.h" #include "core/configure/include/configure_parser.h" diff --git a/core/predictor/framework/factory.h b/core/predictor/framework/factory.h index 8d5fc9a1c40b047351f38a1136728ee179a191ed..fde95eaa1565c8d0f4fca7f846c7c8a49b383163 100644 --- a/core/predictor/framework/factory.h +++ b/core/predictor/framework/factory.h @@ -17,7 +17,7 @@ #include #include #include "core/predictor/common/inner_common.h" -#include "glog/raw_logging.h" + namespace baidu { namespace paddle_serving { namespace predictor { @@ -28,7 +28,12 @@ namespace predictor { FactoryDerive* factory = new (std::nothrow) FactoryDerive(); \ if (factory == NULL || \ FactoryPool::instance().register_factory(tag, factory) != 0) { \ - RAW_LOG_FATAL("Failed regist factory: %s in macro!", #D); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s in macro!", \ + #D); \ + RAW_LOG(FATAL, err_str); \ return -1; \ } \ return 0; \ @@ -54,7 +59,13 @@ namespace predictor { if (factory == NULL || \ ::baidu::paddle_serving::predictor::FactoryPool::instance() \ .register_factory(#D, factory) != 0) { \ - RAW_LOG_FATAL("Failed regist factory: %s->%s in macro!", #D, #B); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s->%s in macro!", \ + #D, \ + #B); \ + RAW_LOG(FATAL, err_str); \ return; \ } \ return; \ @@ -66,15 +77,26 @@ namespace predictor { ::baidu::paddle_serving::predictor::FactoryDerive* factory = new ( \ ::std::nothrow)::baidu::paddle_serving::predictor::FactoryDerive(); \ + char err_str[ERROR_STRING_LEN]; \ if (factory == NULL || \ ::baidu::paddle_serving::predictor::FactoryPool::instance() \ .register_factory(N, factory) != 0) { \ - RAW_LOG_FATAL( \ - "Failed regist factory: %s->%s, tag: %s in macro!", #D, #B, N); \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s->%s, tag: %s in macro!", \ + #D, \ + #B, \ + N); \ + RAW_LOG(FATAL, err_str); \ return; \ } \ - RAW_LOG_WARNING( \ - "Succ regist factory: %s->%s, tag: %s in macro!", #D, #B, N); \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Succ regist factory: %s->%s, tag: %s in macro!", \ + #D, \ + #B, \ + N); \ + RAW_LOG(WARNING, err_str); \ return; \ } @@ -102,24 +124,35 @@ class FactoryPool { } int register_factory(const std::string& tag, FactoryBase* factory) { + char err_str[ERROR_STRING_LEN]; typename std::map*>::iterator it = _pool.find(tag); if (it != _pool.end()) { - RAW_LOG_FATAL("Insert duplicate with tag: %s", tag.c_str()); + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Insert duplicate with tag: %s", + tag.c_str()); + RAW_LOG(FATAL, err_str); return -1; } std::pair*>::iterator, bool> r = _pool.insert(std::make_pair(tag, factory)); if (!r.second) { - RAW_LOG_FATAL("Failed insert new factory with: %s", tag.c_str()); + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Failed insert new factory with: %s", + tag.c_str()); + RAW_LOG(FATAL, err_str); return -1; } - RAW_LOG_INFO("Succ insert one factory, tag: %s, base type %s", - tag.c_str(), - typeid(B).name()); - + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Succ insert one factory, tag: %s, base type %s", + tag.c_str(), + typeid(B).name()); + RAW_LOG(INFO, err_str); return 0; } @@ -127,9 +160,13 @@ class FactoryPool { typename std::map*>::iterator it = _pool.find(tag); if (it == _pool.end() || it->second == NULL) { - RAW_LOG_FATAL("Not found factory pool, tag: %s, pool size %u", - tag.c_str(), - _pool.size()); + char err_str[ERROR_STRING_LEN]; + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Not found factory pool, tag: %s, pool size %u", + tag.c_str(), + _pool.size()); + RAW_LOG(FATAL, err_str); return NULL; } diff --git a/core/predictor/framework/infer.h b/core/predictor/framework/infer.h index 51cfb95a8d56d4261b9dab99df5216c5e6c79733..1cff7647e2dbbcc8df4d144f81488fde35aeb798 100644 --- a/core/predictor/framework/infer.h +++ b/core/predictor/framework/infer.h @@ -603,6 +603,7 @@ class VersionedInferEngine : public InferEngine { LOG(ERROR) << "Failed generate engine with type:" << engine_type; return -1; } +#ifndef BCLOUD VLOG(2) << "FLAGS_logtostderr " << FLAGS_logtostderr; int tmp = FLAGS_logtostderr; if (engine->proc_initialize(conf, version) != 0) { @@ -611,6 +612,12 @@ class VersionedInferEngine : public InferEngine { } VLOG(2) << "FLAGS_logtostderr " << FLAGS_logtostderr; FLAGS_logtostderr = tmp; +#else + if (engine->proc_initialize(conf, version) != 0) { + LOG(ERROR) << "Failed initialize engine, type:" << engine_type; + return -1; + } +#endif auto r = _versions.insert(std::make_pair(engine->version(), engine)); if (!r.second) { LOG(ERROR) << "Failed insert item: " << engine->version() diff --git a/core/predictor/framework/op_repository.h b/core/predictor/framework/op_repository.h index d27e68c1dbcd98e7393aac6e8b0f001e7300a2bc..bf3b2327cd4a1f0af83c98a5bfe529c37ceb403e 100644 --- a/core/predictor/framework/op_repository.h +++ b/core/predictor/framework/op_repository.h @@ -62,7 +62,10 @@ class OpRepository { template void regist_op(std::string op_type) { _repository[op_type] = &OpFactory::instance(); - RAW_LOG_INFO("Succ regist op: %s", op_type.c_str()); + char err_str[ERROR_STRING_LEN]; + snprintf( + err_str, ERROR_STRING_LEN - 1, "Succ regist op: %s", op_type.c_str()); + RAW_LOG(INFO, err_str); } Op* get_op(std::string op_type); diff --git a/core/predictor/framework/resource.cpp b/core/predictor/framework/resource.cpp index ca219519e2dcf20bc961d991e3f2eb0ad060f38f..cdb21097fdf40ca6060d99088ed5649a08507720 100644 --- a/core/predictor/framework/resource.cpp +++ b/core/predictor/framework/resource.cpp @@ -17,6 +17,9 @@ #include #include "core/predictor/common/inner_common.h" #include "core/predictor/framework/kv_manager.h" +#ifdef BCLOUD +#include "aipe_sec_client.h" // NOLINT +#endif namespace baidu { namespace paddle_serving { namespace predictor { @@ -109,6 +112,42 @@ int Resource::initialize(const std::string& path, const std::string& file) { } LOG(WARNING) << "Successfully proc initialized mempool wrapper"; +#ifdef WITH_AUTH + std::string product_name_str = resource_conf.auth_product_name(); + std::string container_id_str = resource_conf.auth_container_id(); + + char* product_name = new char[product_name_str.size() + 1]; + snprintf(product_name, + product_name_str.size() + 1, + "%s", + product_name_str.c_str()); + char* container_id = new char[container_id_str.size() + 1]; + snprintf(container_id, + container_id_str.size() + 1, + "%s", + container_id_str.c_str()); + + aipe_auth_request request; + request.product_name = product_name; + request.container_id = container_id; + request.request_ts = (int64_t)time(NULL); + + LOG(INFO) << "\nEasypack info" + << "\nproduct name: " << request.product_name + << "\ncontainer_id: " << request.container_id + << "\nrequest time stamp: " << request.request_ts; + + aipe_auth_response response; + response = check_auth(request); + + if (response.result == 0) { + LOG(INFO) << "Authentication succeed."; + } else { + LOG(ERROR) << "Authentication failed. Error code: " << response.result; + return -1; + } +#endif + if (FLAGS_enable_model_toolkit) { int err = 0; std::string model_toolkit_path = resource_conf.model_toolkit_path(); diff --git a/core/predictor/framework/service_manager.h b/core/predictor/framework/service_manager.h index fa5e872625739ce233d7dd5efe11e1a0fa61d49d..b6b301dd3dc88dc064e0b17739fa059f3366f023 100644 --- a/core/predictor/framework/service_manager.h +++ b/core/predictor/framework/service_manager.h @@ -23,17 +23,24 @@ namespace predictor { #define REGIST_FORMAT_SERVICE(svr_name, svr) \ do { \ + char err_str[ERROR_STRING_LEN]; \ int ret = \ ::baidu::paddle_serving::predictor::FormatServiceManager::instance() \ .regist_service(svr_name, svr); \ if (ret != 0) { \ - RAW_LOG_ERROR("Failed regist service[%s][%s]", \ - svr_name.c_str(), \ - typeid(svr).name()); \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist service[%s][%s]", \ + svr_name.c_str(), \ + typeid(svr).name()); \ + RAW_LOG(ERROR, err_str); \ } else { \ - RAW_LOG_INFO("Success regist service[%s][%s]", \ - svr_name.c_str(), \ - typeid(svr).name()); \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Success regist service[%s][%s]", \ + svr_name.c_str(), \ + typeid(svr).name()); \ + RAW_LOG(INFO, err_str); \ } \ } while (0) @@ -42,31 +49,46 @@ class FormatServiceManager { typedef google::protobuf::Service Service; int regist_service(const std::string& svr_name, Service* svr) { + char err_str[ERROR_STRING_LEN]; if (_service_map.find(svr_name) != _service_map.end()) { - RAW_LOG_ERROR("Service[%s][%s] already exist!", - svr_name.c_str(), - typeid(svr).name()); + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Service[%s][%s] already exist!", + svr_name.c_str(), + typeid(svr).name()); + RAW_LOG(ERROR, err_str); return -1; } std::pair::iterator, bool> ret; ret = _service_map.insert(std::make_pair(svr_name, svr)); if (ret.second == false) { - RAW_LOG_ERROR("Service[%s][%s] insert failed!", - svr_name.c_str(), - typeid(svr).name()); + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Service[%s][%s] insert failed!", + svr_name.c_str(), + typeid(svr).name()); + RAW_LOG(ERROR, err_str); return -1; } - RAW_LOG_INFO("Service[%s] insert successfully!", svr_name.c_str()); + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Service[%s] insert successfully!", + svr_name.c_str()); + RAW_LOG(INFO, err_str); return 0; } Service* get_service(const std::string& svr_name) { + char err_str[ERROR_STRING_LEN]; boost::unordered_map::iterator res; if ((res = _service_map.find(svr_name)) == _service_map.end()) { - RAW_LOG_WARNING("Service[%s] not found in service manager!", - svr_name.c_str()); + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Service[%s] not found in service manager!", + svr_name.c_str()); + RAW_LOG(WARNING, err_str); return NULL; } return (*res).second; diff --git a/core/predictor/src/pdserving.cpp b/core/predictor/src/pdserving.cpp index 157d52cee1adaea0524ebde01f75a90a6b2adc2f..59ec59d9012c94c322eee2ab3f357218deeedbb4 100644 --- a/core/predictor/src/pdserving.cpp +++ b/core/predictor/src/pdserving.cpp @@ -202,8 +202,6 @@ int main(int argc, char** argv) { } VLOG(2) << "Succ call pthread worker start function"; -#ifndef BCLOUD - if (Resource::instance().general_model_initialize(FLAGS_resource_path, FLAGS_resource_file) != 0) { LOG(ERROR) << "Failed to initialize general model conf: " @@ -213,6 +211,7 @@ int main(int argc, char** argv) { VLOG(2) << "Succ initialize general model"; +#ifndef BCLOUD // FATAL messages are output to stderr FLAGS_stderrthreshold = 3; #endif diff --git a/core/sdk-cpp/include/abtest.h b/core/sdk-cpp/include/abtest.h index 4833325416cfd6418bf33444001917d887f08cc0..a4275fcf52413bb85bcca1fcb470ea2360fdf174 100644 --- a/core/sdk-cpp/include/abtest.h +++ b/core/sdk-cpp/include/abtest.h @@ -50,9 +50,9 @@ class WeightedRandomRender : public EndpointRouterBase { Factory* factory = new (std::nothrow) Factory(); if (factory == NULL) { - RAW_LOG_ERROR( - "Failed regist factory: WeightedRandomRender->EndpointRouterBase in " - "macro!"); + RAW_LOG(ERROR, + "Failed regist factory: WeightedRandomRender->EndpointRouterBase \ + in macro!"); return -1; } @@ -62,9 +62,9 @@ class WeightedRandomRender : public EndpointRouterBase { // together. if (FactoryPool::instance().register_factory( "WeightedRandomRender", factory) != 0) { - RAW_LOG_INFO( - "Factory has been registed: " - "WeightedRandomRender->EndpointRouterBase."); + RAW_LOG(INFO, + "Factory has been registed: \ + WeightedRandomRender->EndpointRouterBase."); } return 0; diff --git a/core/sdk-cpp/include/factory.h b/core/sdk-cpp/include/factory.h index 4a3d988afcd981dd92eca5f65c3f254d5f2255d5..89c8aae3ef6bd7b296a8a953f2db88786b501352 100644 --- a/core/sdk-cpp/include/factory.h +++ b/core/sdk-cpp/include/factory.h @@ -18,7 +18,6 @@ #include #include "core/sdk-cpp/include/common.h" #include "core/sdk-cpp/include/stub_impl.h" -#include "glog/raw_logging.h" namespace baidu { namespace paddle_serving { @@ -28,12 +27,20 @@ namespace sdk_cpp { namespace brpc = baidu::rpc; #endif +#define ERROR_STRING_LEN 10240 + #define INLINE_REGIST_OBJECT(D, B, E) \ do { \ Factory* factory = new (std::nothrow) Factory(); \ if (factory == NULL || \ FactoryPool::instance().register_factory(#D, factory) != 0) { \ - RAW_LOG_ERROR("Failed regist factory: %s->%s in macro!", #D, #B); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s->%s in macro!", \ + #D, \ + #B); \ + RAW_LOG(ERROR, err_str); \ return E; \ } \ } while (0) @@ -43,7 +50,12 @@ namespace brpc = baidu::rpc; Factory* factory = new (std::nothrow) Factory(); \ if (factory == NULL || \ FactoryPool::instance().register_factory(tag, factory) != 0) { \ - RAW_LOG_ERROR("Failed regist factory: %s in macro!", #D); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s in macro!", \ + #D); \ + RAW_LOG(ERROR, err_str); \ return -1; \ } \ return 0; \ @@ -66,7 +78,13 @@ namespace brpc = baidu::rpc; if (factory == NULL || \ ::baidu::paddle_serving::sdk_cpp::FactoryPool::instance() \ .register_factory(#D, factory) != 0) { \ - RAW_LOG_ERROR("Failed regist factory: %s->%s in macro!", #D, #B); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s->%s in macro!", \ + #D, \ + #B); \ + RAW_LOG(ERROR, err_str); \ return; \ } \ return; \ @@ -80,8 +98,14 @@ namespace brpc = baidu::rpc; if (factory == NULL || \ ::baidu::paddle_serving::sdk_cpp::FactoryPool::instance() \ .register_factory(T, factory) != 0) { \ - RAW_LOG_ERROR( \ - "Failed regist factory: %s->%s, tag %s in macro!", #D, #B, T); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s->%s, tag %s in macro!", \ + #D, \ + #B, \ + T); \ + RAW_LOG(ERROR, err_str); \ return; \ } \ return; \ @@ -108,8 +132,13 @@ namespace brpc = baidu::rpc; ::baidu::paddle_serving::sdk_cpp::FactoryPool< \ ::baidu::paddle_serving::sdk_cpp::Stub>::instance() \ .register_factory(T, factory) != 0) { \ - RAW_LOG_ERROR( \ - "Failed regist factory: %s->Stub, tag: %s in macro!", #D, T); \ + char err_str[ERROR_STRING_LEN]; \ + snprintf(err_str, \ + ERROR_STRING_LEN - 1, \ + "Failed regist factory: %s->Stub, tag: %s in macro!", \ + #D, \ + T); \ + RAW_LOG(ERROR, err_str); \ return; \ } \ return; \ @@ -146,14 +175,24 @@ class FactoryPool { typename std::map*>::iterator it = _pool.find(tag); if (it != _pool.end()) { - RAW_LOG_ERROR("Insert duplicate with tag: %s", tag.c_str()); + char err_str[ERROR_STRING_LEN]; + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Insert duplicate with tag: %s", + tag.c_str()); + RAW_LOG(ERROR, err_str); return -1; } std::pair*>::iterator, bool> r = _pool.insert(std::make_pair(tag, factory)); if (!r.second) { - RAW_LOG_ERROR("Failed insert new factory with: %s", tag.c_str()); + char err_str[ERROR_STRING_LEN]; + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Failed insert new factory with: %s", + tag.c_str()); + RAW_LOG(ERROR, err_str); return -1; } @@ -164,9 +203,13 @@ class FactoryPool { typename std::map*>::iterator it = _pool.find(tag); if (it == _pool.end() || it->second == NULL) { - RAW_LOG_ERROR("Not found factory pool, tag: %s, pool size: %u", - tag.c_str(), - _pool.size()); + char err_str[ERROR_STRING_LEN]; + snprintf(err_str, + ERROR_STRING_LEN - 1, + "Not found factory pool, tag: %s, pool size: %u", + tag.c_str(), + _pool.size()); + RAW_LOG(ERROR, err_str); return NULL; } diff --git a/doc/COMPILE.md b/doc/COMPILE.md index 1836f4fe089f13e2eb2c9485f40d50ec668e4671..63a4d67c40af77e616e018d1a6dbc289615b4971 100644 --- a/doc/COMPILE.md +++ b/doc/COMPILE.md @@ -4,26 +4,25 @@ ## Compilation environment requirements -| module | version | -| :--------------------------: | :----------------------------------------------------------: | -| OS | CentOS 7 | -| gcc | 4.8.5 and later | -| gcc-c++ | 4.8.5 and later | -| git | 3.82 and later | -| cmake | 3.2.0 and later | -| Python | 2.7.2 and later / 3.6 and later | -| Go | 1.9.2 and later | -| git | 2.17.1 and later | -| glibc-static | 2.17 | -| openssl-devel | 1.0.2k | -| bzip2-devel | 1.0.6 and later | -| python-devel / python3-devel | 2.7.5 and later / 3.6.8 and later | -| sqlite-devel | 3.7.17 and later | -| patchelf | 0.9 and later | -| libXext | 1.3.3 | -| libSM | 1.2.2 | -| libXrender | 0.9.10 | -| python-whl | numpy>=1.12, <=1.16.4
wheel>=0.34.0, <0.35.0
setuptools>=44.1.0
opencv-python==4.2.0.32
google>=2.0.3
protobuf>=3.12.2
grpcio-tools>=1.28.1
grpcio>=1.28.1
func-timeout>=4.3.5
pyyaml>=1.3.0
sentencepiece==0.1.92
flask>=1.1.2
ujson>=2.0.3 | +| module | version | +| :--------------------------: | :-------------------------------: | +| OS | CentOS 7 | +| gcc | 4.8.5 and later | +| gcc-c++ | 4.8.5 and later | +| git | 3.82 and later | +| cmake | 3.2.0 and later | +| Python | 2.7.2 and later / 3.6 and later | +| Go | 1.9.2 and later | +| git | 2.17.1 and later | +| glibc-static | 2.17 | +| openssl-devel | 1.0.2k | +| bzip2-devel | 1.0.6 and later | +| python-devel / python3-devel | 2.7.5 and later / 3.6.8 and later | +| sqlite-devel | 3.7.17 and later | +| patchelf | 0.9 and later | +| libXext | 1.3.3 | +| libSM | 1.2.2 | +| libXrender | 0.9.10 | It is recommended to use Docker for compilation. We have prepared the Paddle Serving compilation environment for you, see [this document](DOCKER_IMAGES.md). @@ -114,7 +113,7 @@ make ## Install wheel package -Regardless of the client, server or App part, after compiling, install the whl package under `python/dist/`. +Regardless of the client, server or App part, after compiling, install the whl package in `python/dist/` in the temporary directory(`server-build-cpu`, `server-build-gpu`, `client-build`,`app-build`) of the compilation process. @@ -124,6 +123,12 @@ When running the python server, it will check the `SERVING_BIN` environment vari +## Verify + +Please use the example under `python/examples` to verify. + + + ## CMake Option Description | Compile Options | Description | Default | diff --git a/doc/COMPILE_CN.md b/doc/COMPILE_CN.md index 1235653e69161ba8f71d3f8098a1860dca4d357d..29b0645cc4ea90c56cd5d691f4766a3e3ad39ba1 100644 --- a/doc/COMPILE_CN.md +++ b/doc/COMPILE_CN.md @@ -4,26 +4,25 @@ ## 编译环境设置 -| 组件 | 版本要求 | -| :--------------------------: | :----------------------------------------------------------: | -| OS | CentOS 7 | -| gcc | 4.8.5 and later | -| gcc-c++ | 4.8.5 and later | -| git | 3.82 and later | -| cmake | 3.2.0 and later | -| Python | 2.7.2 and later / 3.6 and later | -| Go | 1.9.2 and later | -| git | 2.17.1 and later | -| glibc-static | 2.17 | -| openssl-devel | 1.0.2k | -| bzip2-devel | 1.0.6 and later | -| python-devel / python3-devel | 2.7.5 and later / 3.6.8 and later | -| sqlite-devel | 3.7.17 and later | -| patchelf | 0.9 | -| libXext | 1.3.3 | -| libSM | 1.2.2 | -| libXrender | 0.9.10 | -| python-whl | numpy>=1.12, <=1.16.4
wheel>=0.34.0, <0.35.0
setuptools>=44.1.0
opencv-python==4.2.0.32
google>=2.0.3
protobuf>=3.12.2
grpcio-tools>=1.28.1
grpcio>=1.28.1
func-timeout>=4.3.5
pyyaml>=1.3.0
sentencepiece==0.1.92
flask>=1.1.2
ujson>=2.0.3 | +| 组件 | 版本要求 | +| :--------------------------: | :-------------------------------: | +| OS | CentOS 7 | +| gcc | 4.8.5 and later | +| gcc-c++ | 4.8.5 and later | +| git | 3.82 and later | +| cmake | 3.2.0 and later | +| Python | 2.7.2 and later / 3.6 and later | +| Go | 1.9.2 and later | +| git | 2.17.1 and later | +| glibc-static | 2.17 | +| openssl-devel | 1.0.2k | +| bzip2-devel | 1.0.6 and later | +| python-devel / python3-devel | 2.7.5 and later / 3.6.8 and later | +| sqlite-devel | 3.7.17 and later | +| patchelf | 0.9 | +| libXext | 1.3.3 | +| libSM | 1.2.2 | +| libXrender | 0.9.10 | 推荐使用Docker编译,我们已经为您准备好了Paddle Serving编译环境,详见[该文档](DOCKER_IMAGES_CN.md)。 @@ -114,7 +113,7 @@ make ## 安装wheel包 -无论是Client端,Server端还是App部分,编译完成后,安装`python/dist/`下的whl包即可。 +无论是Client端,Server端还是App部分,编译完成后,安装编译过程临时目录(`server-build-cpu`、`server-build-gpu`、`client-build`、`app-build`)下的`python/dist/` 中的whl包即可。 @@ -124,6 +123,12 @@ make +## 如何验证 + +请使用 `python/examples` 下的例子进行验证。 + + + ## CMake选项说明 | 编译选项 | 说明 | 默认 | diff --git a/java/src/main/proto/multi_lang_general_model_service.proto b/java/src/main/proto/multi_lang_general_model_service.proto index c23f4dbb243e8d23b8e4bfef419649b262f0dcd3..18fbcf760647e1694e738c0832fe45f4f7d9934f 100644 --- a/java/src/main/proto/multi_lang_general_model_service.proto +++ b/java/src/main/proto/multi_lang_general_model_service.proto @@ -14,6 +14,8 @@ syntax = "proto2"; +package baidu.paddle_serving.multi_lang; + option java_multiple_files = true; option java_package = "io.paddle.serving.grpc"; option java_outer_classname = "ServingProto"; diff --git a/paddle_inference/inferencer-fluid-cpu/include/fluid_cpu_engine.h b/paddle_inference/inferencer-fluid-cpu/include/fluid_cpu_engine.h index a4d8dda71a7977185106bb1552cb8f39ef6bc50e..f65711e04cf601e40f693b045adbaba0cf7ada71 100644 --- a/paddle_inference/inferencer-fluid-cpu/include/fluid_cpu_engine.h +++ b/paddle_inference/inferencer-fluid-cpu/include/fluid_cpu_engine.h @@ -23,6 +23,7 @@ #include "core/configure/inferencer_configure.pb.h" #include "core/predictor/framework/infer.h" #include "paddle_inference_api.h" // NOLINT +//#include "predictor/framework/infer.h" namespace baidu { namespace paddle_serving { diff --git a/python/paddle_serving_server/__init__.py b/python/paddle_serving_server/__init__.py index 1fea9ab187a8c41cd4264a10138d6c13a09897f5..675dcb138bd6c4b70ccb68f5d1ae8e721ef6704e 100644 --- a/python/paddle_serving_server/__init__.py +++ b/python/paddle_serving_server/__init__.py @@ -103,8 +103,8 @@ class OpSeqMaker(object): elif len(node.dependencies) == 1: if node.dependencies[0].name != self.workflow.nodes[-1].name: raise Exception( - 'You must add op in order in OpSeqMaker. The previous op is {}, but the current op is followed by {}.'. - format(node.dependencies[0].name, self.workflow.nodes[ + 'You must add op in order in OpSeqMaker. The previous op is {}, but the current op is followed by {}.' + .format(node.dependencies[0].name, self.workflow.nodes[ -1].name)) self.workflow.nodes.extend([node]) @@ -157,6 +157,8 @@ class Server(object): self.cur_path = os.getcwd() self.use_local_bin = False self.mkl_flag = False + self.product_name = None + self.container_id = None self.model_config_paths = None # for multi-model in a workflow def set_max_concurrency(self, concurrency): @@ -191,6 +193,16 @@ class Server(object): def set_ir_optimize(self, flag=False): self.ir_optimization = flag + def set_product_name(self, product_name=None): + if product_name == None: + raise ValueError("product_name can't be None.") + self.product_name = product_name + + def set_container_id(self, container_id): + if container_id == None: + raise ValueError("container_id can't be None.") + self.container_id = container_id + def check_local_bin(self): if "SERVING_BIN" in os.environ: self.use_local_bin = True @@ -254,6 +266,10 @@ class Server(object): self.resource_conf.model_toolkit_file = self.model_toolkit_fn self.resource_conf.general_model_path = workdir self.resource_conf.general_model_file = self.general_model_config_fn + if self.product_name != None: + self.resource_conf.auth_product_name = self.product_name + if self.container_id != None: + self.resource_conf.auth_container_id = self.container_id def _write_pb_str(self, filepath, pb_obj): with open(filepath, "w") as fout: @@ -351,8 +367,8 @@ class Server(object): if os.path.exists(tar_name): os.remove(tar_name) raise SystemExit( - 'Download failed, please check your network or permission of {}.'. - format(self.module_path)) + 'Download failed, please check your network or permission of {}.' + .format(self.module_path)) else: try: print('Decompressing files ..') @@ -363,8 +379,8 @@ class Server(object): if os.path.exists(exe_path): os.remove(exe_path) raise SystemExit( - 'Decompressing failed, please check your permission of {} or disk space left.'. - format(self.module_path)) + 'Decompressing failed, please check your permission of {} or disk space left.' + .format(self.module_path)) finally: os.remove(tar_name) #release lock @@ -541,7 +557,6 @@ class MultiLangServerServiceServicer(multi_lang_general_model_service_pb2_grpc. results, tag = ret resp.tag = tag resp.err_code = 0 - if not self.is_multi_model_: results = {'general_infer_0': results} for model_name, model_result in results.items(): diff --git a/python/paddle_serving_server/serve.py b/python/paddle_serving_server/serve.py index 704cf0304adf1ac647c244063c2b23049f92b221..d282ac076e377806e9a3b320b880ffed6300b971 100644 --- a/python/paddle_serving_server/serve.py +++ b/python/paddle_serving_server/serve.py @@ -58,6 +58,16 @@ def parse_args(): # pylint: disable=doc-string-missing default=False, action="store_true", help="Use Multi-language-service") + parser.add_argument( + "--product_name", + type=str, + default=None, + help="product_name for authentication") + parser.add_argument( + "--container_id", + type=str, + default=None, + help="container_id for authentication") return parser.parse_args() @@ -101,6 +111,10 @@ def start_standard_model(): # pylint: disable=doc-string-missing server.use_mkl(use_mkl) server.set_max_body_size(max_body_size) server.set_port(port) + if args.product_name != None: + server.set_product_name(args.product_name) + if args.container_id != None: + server.set_container_id(args.container_id) server.load_model_config(model) server.prepare_server(workdir=workdir, port=port, device=device) diff --git a/python/paddle_serving_server_gpu/__init__.py b/python/paddle_serving_server_gpu/__init__.py index 7ab27dc0cb71041506d715d1ab4ca58c25d2c6d9..7a5c26889f6e3bf33339dfd6034e282a2a5752b8 100644 --- a/python/paddle_serving_server_gpu/__init__.py +++ b/python/paddle_serving_server_gpu/__init__.py @@ -73,6 +73,16 @@ def serve_args(): default=False, action="store_true", help="Use Multi-language-service") + parser.add_argument( + "--product_name", + type=str, + default=None, + help="product_name for authentication") + parser.add_argument( + "--container_id", + type=str, + default=None, + help="container_id for authentication") return parser.parse_args() @@ -141,8 +151,8 @@ class OpSeqMaker(object): elif len(node.dependencies) == 1: if node.dependencies[0].name != self.workflow.nodes[-1].name: raise Exception( - 'You must add op in order in OpSeqMaker. The previous op is {}, but the current op is followed by {}.'. - format(node.dependencies[0].name, self.workflow.nodes[ + 'You must add op in order in OpSeqMaker. The previous op is {}, but the current op is followed by {}.' + .format(node.dependencies[0].name, self.workflow.nodes[ -1].name)) self.workflow.nodes.extend([node]) @@ -196,6 +206,8 @@ class Server(object): self.use_local_bin = False self.gpuid = 0 self.model_config_paths = None # for multi-model in a workflow + self.product_name = None + self.container_id = None def set_max_concurrency(self, concurrency): self.max_concurrency = concurrency @@ -229,6 +241,16 @@ class Server(object): def set_ir_optimize(self, flag=False): self.ir_optimization = flag + def set_product_name(self, product_name=None): + if product_name == None: + raise ValueError("product_name can't be None.") + self.product_name = product_name + + def set_container_id(self, container_id): + if container_id == None: + raise ValueError("container_id can't be None.") + self.container_id = container_id + def check_local_bin(self): if "SERVING_BIN" in os.environ: self.use_local_bin = True @@ -302,6 +324,10 @@ class Server(object): self.resource_conf.model_toolkit_file = self.model_toolkit_fn self.resource_conf.general_model_path = workdir self.resource_conf.general_model_file = self.general_model_config_fn + if self.product_name != None: + self.resource_conf.auth_product_name = self.product_name + if self.container_id != None: + self.resource_conf.auth_container_id = self.container_id def _write_pb_str(self, filepath, pb_obj): with open(filepath, "w") as fout: @@ -393,8 +419,8 @@ class Server(object): if os.path.exists(tar_name): os.remove(tar_name) raise SystemExit( - 'Download failed, please check your network or permission of {}.'. - format(self.module_path)) + 'Download failed, please check your network or permission of {}.' + .format(self.module_path)) else: try: print('Decompressing files ..') @@ -405,8 +431,8 @@ class Server(object): if os.path.exists(exe_path): os.remove(exe_path) raise SystemExit( - 'Decompressing failed, please check your permission of {} or disk space left.'. - format(self.module_path)) + 'Decompressing failed, please check your permission of {} or disk space left.' + .format(self.module_path)) finally: os.remove(tar_name) #release lock diff --git a/python/paddle_serving_server_gpu/serve.py b/python/paddle_serving_server_gpu/serve.py index 3b0941a97560f11a52808fc7e152419e2cec0ba0..9755b188aa2ddee57c9875610b1bee6ac2b8eb2d 100644 --- a/python/paddle_serving_server_gpu/serve.py +++ b/python/paddle_serving_server_gpu/serve.py @@ -65,6 +65,11 @@ def start_gpu_card_model(index, gpuid, args): # pylint: disable=doc-string-miss server.set_ir_optimize(ir_optim) server.set_max_body_size(max_body_size) + if args.product_name != None: + server.set_product_name(args.product_name) + if args.container_id != None: + server.set_container_id(args.container_id) + server.load_model_config(model) server.prepare_server(workdir=workdir, port=port, device=device) if gpuid >= 0: @@ -83,8 +88,8 @@ def start_multi_card(args): # pylint: disable=doc-string-missing for ids in gpus: if int(ids) >= len(env_gpus): print( - " Max index of gpu_ids out of range, the number of CUDA_VISIBLE_DEVICES is {}.". - format(len(env_gpus))) + " Max index of gpu_ids out of range, the number of CUDA_VISIBLE_DEVICES is {}." + .format(len(env_gpus))) exit(-1) else: env_gpus = [] diff --git a/python/requirements.txt b/python/requirements.txt index 23b5289d5109fcb119f143eef4deb65198555d6a..6771d1adea85c0fd7ac32c26fcfd7dfe3f2cbdd4 100644 --- a/python/requirements.txt +++ b/python/requirements.txt @@ -1,4 +1,5 @@ numpy>=1.12, <=1.16.4 ; python_version<"3.5" +shapely==1.7.0 wheel>=0.34.0, <0.35.0 setuptools>=44.1.0 opencv-python==4.2.0.32 diff --git a/python/setup.py.app.in b/python/setup.py.app.in index 2b7ae9303aa95eace7b0eab99d787ca43af48e00..523b9e5c493e881d1ac3d6553bdb57a91f084acb 100644 --- a/python/setup.py.app.in +++ b/python/setup.py.app.in @@ -43,7 +43,7 @@ if '${PACK}' == 'ON': REQUIRED_PACKAGES = [ 'six >= 1.10.0', 'sentencepiece', 'opencv-python<=4.2.0.32', 'pillow', - 'shapely', 'pyclipper' + 'shapely<=1.6.1', 'pyclipper' ] packages=['paddle_serving_app',