├── .bazelrc ├── .github ├── issue_template.md └── workflows │ ├── build.yaml │ └── test.yaml ├── .gitignore ├── .gitmodules ├── AUTHORS ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── README_cn.md ├── RELEASE.md ├── WORKSPACE ├── tensorflow_serving ├── BUILD ├── apis │ ├── BUILD │ ├── classification.proto │ ├── classifier.h │ ├── get_model_metadata.proto │ ├── get_model_status.proto │ ├── inference.proto │ ├── input.proto │ ├── internal │ │ ├── BUILD │ │ └── serialized_input.proto │ ├── model.proto │ ├── model_management.proto │ ├── model_service.proto │ ├── model_service_pb2.py │ ├── model_service_pb2_grpc.py │ ├── predict.proto │ ├── prediction_log.proto │ ├── prediction_service.proto │ ├── prediction_service_pb2.py │ ├── prediction_service_pb2_grpc.py │ ├── regression.proto │ ├── regressor.h │ └── session_service.proto ├── batching │ ├── BUILD │ ├── README.md │ ├── batch_scheduler_retrier.h │ ├── batch_scheduler_retrier_test.cc │ ├── batching_session.cc │ ├── batching_session.h │ ├── batching_session_test.cc │ ├── batching_util.cc │ ├── batching_util.h │ ├── batching_util_test.cc │ ├── streaming_batch_scheduler.cc │ ├── streaming_batch_scheduler.h │ ├── streaming_batch_scheduler_test.cc │ ├── test_util │ │ ├── BUILD │ │ ├── matrix_half_plus_two_saved_model.py │ │ ├── puppet_batch_scheduler.h │ │ └── puppet_batch_scheduler_test.cc │ └── testdata │ │ ├── BUILD │ │ └── matrix_half_plus_two │ │ └── 1 │ │ └── saved_model.pb ├── config │ ├── BUILD │ ├── log_collector_config.proto │ ├── logging_config.proto │ ├── model_server_config.proto │ ├── monitoring_config.proto │ ├── platform_config.proto │ └── ssl_config.proto ├── core │ ├── BUILD │ ├── README.md │ ├── aspired_version_policy.cc │ ├── aspired_version_policy.h │ ├── aspired_version_policy_test.cc │ ├── aspired_versions_manager.cc │ ├── aspired_versions_manager.h │ ├── aspired_versions_manager_benchmark.cc │ ├── aspired_versions_manager_builder.cc │ ├── aspired_versions_manager_builder.h │ ├── aspired_versions_manager_builder_test.cc │ ├── aspired_versions_manager_test.cc │ ├── availability_preserving_policy.cc │ ├── availability_preserving_policy.h │ ├── availability_preserving_policy_test.cc │ ├── basic_manager.cc │ ├── basic_manager.h │ ├── basic_manager_test.cc │ ├── caching_manager.cc │ ├── caching_manager.h │ ├── caching_manager_test.cc │ ├── dynamic_source_router.h │ ├── dynamic_source_router_test.cc │ ├── load_servables_fast.cc │ ├── load_servables_fast.h │ ├── loader.h │ ├── loader_harness.cc │ ├── loader_harness.h │ ├── loader_harness_test.cc │ ├── log_collector.cc │ ├── log_collector.h │ ├── log_collector_test.cc │ ├── logging.proto │ ├── manager.h │ ├── manager_test.cc │ ├── manager_wrapper.cc │ ├── manager_wrapper.h │ ├── request_logger.cc │ ├── request_logger.h │ ├── request_logger_test.cc │ ├── resource_preserving_policy.cc │ ├── resource_preserving_policy.h │ ├── resource_preserving_policy_test.cc │ ├── servable_data.h │ ├── servable_data_test.cc │ ├── servable_handle.h │ ├── servable_id.h │ ├── servable_id_test.cc │ ├── servable_state.h │ ├── servable_state_monitor.cc │ ├── servable_state_monitor.h │ ├── servable_state_monitor_test.cc │ ├── server_request_logger.cc │ ├── server_request_logger.h │ ├── server_request_logger_test.cc │ ├── simple_loader.h │ ├── simple_loader_test.cc │ ├── source.h │ ├── source_adapter.h │ ├── source_adapter_test.cc │ ├── source_router.h │ ├── source_router_test.cc │ ├── static_manager.cc │ ├── static_manager.h │ ├── static_manager_test.cc │ ├── static_source_router.h │ ├── static_source_router_test.cc │ ├── storage_path.h │ ├── storage_path_test.cc │ ├── target.h │ └── test_util │ │ ├── BUILD │ │ ├── availability_test_util.cc │ │ ├── availability_test_util.h │ │ ├── fake_loader.cc │ │ ├── fake_loader.h │ │ ├── fake_loader_source_adapter.cc │ │ ├── fake_loader_source_adapter.h │ │ ├── fake_loader_source_adapter.proto │ │ ├── fake_log_collector.h │ │ ├── fake_storage_path_source_adapter.cc │ │ ├── fake_storage_path_source_adapter.h │ │ ├── manager_test_util.cc │ │ ├── manager_test_util.h │ │ ├── mock_loader.h │ │ ├── mock_log_collector.h │ │ ├── mock_request_logger.h │ │ ├── mock_server_request_logger.h │ │ ├── mock_session.h │ │ ├── mock_storage_path_target.h │ │ ├── servable_handle_test_util.h │ │ ├── session_test_util.cc │ │ ├── session_test_util.h │ │ └── test_main.cc ├── docs │ ├── cn │ │ ├── building.md │ │ ├── building_with_docker.md │ │ ├── export_model.md │ │ ├── serving_basic.md │ │ └── serving_config.md │ └── en │ │ ├── building.md │ │ ├── building_with_docker.md │ │ ├── export_model.md │ │ ├── serving_basic.md │ │ └── serving_config.md ├── example │ ├── BUILD │ ├── alphafm_client.cc │ ├── alphafm_softmax_client.cc │ ├── mnist_client.py │ ├── mnist_input_data.py │ ├── mnist_saved_model.py │ ├── resnet_client.cc │ ├── resnet_client.py │ ├── resnet_client_grpc.py │ ├── resnet_k8s.yaml │ ├── resnet_warmup.py │ ├── xgboost_client.cc │ └── xgboost_client.py ├── g3doc │ ├── _toc.yaml │ ├── api_rest.md │ ├── architecture.md │ ├── building_with_docker.md │ ├── custom_op.md │ ├── custom_servable.md │ ├── custom_source.md │ ├── docker.md │ ├── images │ │ ├── serving_architecture.svg │ │ └── tf_diagram.svg │ ├── saved_model_warmup.md │ ├── serving_advanced.md │ ├── serving_basic.md │ ├── serving_config.md │ ├── serving_kubernetes.md │ ├── setup.md │ ├── signature_defs.md │ └── tutorials │ │ ├── README.md │ │ └── Serving_REST_simple.ipynb ├── model_servers │ ├── BUILD │ ├── get_model_status_impl.cc │ ├── get_model_status_impl.h │ ├── get_model_status_impl_test.cc │ ├── grpc_status_util.cc │ ├── grpc_status_util.h │ ├── http_rest_api_handler.cc │ ├── http_rest_api_handler.h │ ├── http_rest_api_handler_test.cc │ ├── http_server.cc │ ├── http_server.h │ ├── main.cc │ ├── model_platform_types.h │ ├── model_service_impl.cc │ ├── model_service_impl.h │ ├── platform_config_util.cc │ ├── platform_config_util.h │ ├── prediction_service_impl.cc │ ├── prediction_service_impl.h │ ├── server.cc │ ├── server.h │ ├── server_core.cc │ ├── server_core.h │ ├── server_core_test.cc │ ├── tensorflow_model_server_beta_grpc_test.py │ ├── tensorflow_model_server_test.py │ ├── tensorflow_model_server_test_client.py │ ├── test_util │ │ ├── BUILD │ │ ├── mock_server_core.h │ │ ├── server_core_test_util.cc │ │ ├── server_core_test_util.h │ │ ├── storage_path_error_injecting_source_adapter.cc │ │ ├── storage_path_error_injecting_source_adapter.h │ │ ├── storage_path_error_injecting_source_adapter.proto │ │ └── tensorflow_model_server_test_base.py │ ├── version.cc │ └── version.h ├── oss_or_google.bzl ├── repo.bzl ├── resources │ ├── BUILD │ ├── resource_tracker.cc │ ├── resource_tracker.h │ ├── resource_tracker_test.cc │ ├── resource_util.cc │ ├── resource_util.h │ ├── resource_util_test.cc │ ├── resource_values.cc │ ├── resource_values.h │ └── resources.proto ├── servables │ ├── alphafm │ │ ├── BUILD │ │ ├── alphafm_bundle.cc │ │ ├── alphafm_bundle.h │ │ ├── alphafm_bundle_test.cc │ │ ├── alphafm_model.cc │ │ ├── alphafm_model.h │ │ ├── alphafm_model_test.cc │ │ ├── alphafm_source_adapter.cc │ │ ├── alphafm_source_adapter.h │ │ ├── alphafm_source_adapter.proto │ │ ├── alphafm_source_adapter_test.cc │ │ ├── feature_mapping.cc │ │ ├── feature_mapping.h │ │ ├── feature_mapping_test.cc │ │ ├── predict_impl.cc │ │ ├── predict_impl.h │ │ ├── predict_impl_test.cc │ │ └── testdata │ │ │ ├── BUILD │ │ │ ├── agaricus.txt.test │ │ │ ├── agaricus.txt.train │ │ │ ├── export_test_model.py │ │ │ ├── model_config.txt │ │ │ ├── platform_config.txt │ │ │ └── test_model │ │ │ └── 1 │ │ │ ├── deploy.fm │ │ │ ├── deploy.leaf_mapping │ │ │ └── deploy.model │ ├── alphafm_softmax │ │ ├── BUILD │ │ ├── alphafm_softmax_bundle.cc │ │ ├── alphafm_softmax_bundle.h │ │ ├── alphafm_softmax_bundle_test.cc │ │ ├── alphafm_softmax_model.cc │ │ ├── alphafm_softmax_model.h │ │ ├── alphafm_softmax_model_test.cc │ │ ├── alphafm_softmax_source_adapter.cc │ │ ├── alphafm_softmax_source_adapter.h │ │ ├── alphafm_softmax_source_adapter.proto │ │ ├── alphafm_softmax_source_adapter_test.cc │ │ ├── predict_impl.cc │ │ ├── predict_impl.h │ │ ├── predict_impl_test.cc │ │ └── testdata │ │ │ ├── BUILD │ │ │ ├── model_config.txt │ │ │ ├── platform_config.txt │ │ │ └── test_model │ │ │ └── 1 │ │ │ ├── deploy.fm │ │ │ ├── deploy.leaf_mapping │ │ │ └── deploy.model │ ├── hashmap │ │ ├── BUILD │ │ ├── hashmap_source_adapter.cc │ │ ├── hashmap_source_adapter.h │ │ ├── hashmap_source_adapter.proto │ │ └── hashmap_source_adapter_test.cc │ ├── tensorflow │ │ ├── BUILD │ │ ├── bundle_factory_test.h │ │ ├── bundle_factory_test_util.cc │ │ ├── bundle_factory_test_util.h │ │ ├── bundle_factory_util.cc │ │ ├── bundle_factory_util.h │ │ ├── bundle_factory_util_test.cc │ │ ├── classification_service.cc │ │ ├── classification_service.h │ │ ├── classification_service_test.cc │ │ ├── classifier.cc │ │ ├── classifier.h │ │ ├── classifier_test.cc │ │ ├── curried_session.cc │ │ ├── curried_session.h │ │ ├── curried_session_test.cc │ │ ├── get_model_metadata_impl.cc │ │ ├── get_model_metadata_impl.h │ │ ├── get_model_metadata_impl_test.cc │ │ ├── multi_inference.cc │ │ ├── multi_inference.h │ │ ├── multi_inference_helper.cc │ │ ├── multi_inference_helper.h │ │ ├── multi_inference_helper_test.cc │ │ ├── multi_inference_test.cc │ │ ├── oss │ │ │ ├── BUILD │ │ │ ├── session_bundle_factory_test.cc │ │ │ └── session_bundle_source_adapter_test.cc │ │ ├── predict_impl.cc │ │ ├── predict_impl.h │ │ ├── predict_impl_test.cc │ │ ├── predict_util.cc │ │ ├── predict_util.h │ │ ├── predict_util_test.cc │ │ ├── regression_service.cc │ │ ├── regression_service.h │ │ ├── regression_service_test.cc │ │ ├── regressor.cc │ │ ├── regressor.h │ │ ├── regressor_test.cc │ │ ├── saved_model_bundle_factory.cc │ │ ├── saved_model_bundle_factory.h │ │ ├── saved_model_bundle_factory_test.cc │ │ ├── saved_model_bundle_source_adapter.cc │ │ ├── saved_model_bundle_source_adapter.h │ │ ├── saved_model_bundle_source_adapter.proto │ │ ├── saved_model_bundle_source_adapter_test.cc │ │ ├── saved_model_warmup.cc │ │ ├── saved_model_warmup.h │ │ ├── saved_model_warmup_test.cc │ │ ├── serving_session.cc │ │ ├── serving_session.h │ │ ├── session_bundle_config.proto │ │ ├── session_bundle_factory.cc │ │ ├── session_bundle_factory.h │ │ ├── session_bundle_source_adapter.cc │ │ ├── session_bundle_source_adapter.h │ │ ├── session_bundle_source_adapter.proto │ │ ├── simple_servers.cc │ │ ├── simple_servers.h │ │ ├── simple_servers_test.cc │ │ ├── testdata │ │ │ ├── BUILD │ │ │ ├── bad_half_plus_two │ │ │ │ └── 00000123 │ │ │ │ │ ├── checkpoint │ │ │ │ │ ├── export │ │ │ │ │ └── export.meta │ │ │ ├── bad_model_config.txt │ │ │ ├── batching_config.txt │ │ │ ├── export_bad_half_plus_two.py │ │ │ ├── export_counter.py │ │ │ ├── export_half_plus_two.py │ │ │ ├── good_model_config.txt │ │ │ ├── half_plus_two │ │ │ │ └── 00000123 │ │ │ │ │ ├── export.data-00000-of-00001 │ │ │ │ │ ├── export.index │ │ │ │ │ └── export.meta │ │ │ ├── half_plus_two_2_versions │ │ │ │ ├── 00000123 │ │ │ │ │ ├── export.data-00000-of-00001 │ │ │ │ │ ├── export.index │ │ │ │ │ └── export.meta │ │ │ │ └── 00000124 │ │ │ │ │ ├── export.data-00000-of-00001 │ │ │ │ │ ├── export.index │ │ │ │ │ └── export.meta │ │ │ ├── half_plus_two_model_metadata.json │ │ │ ├── monitoring_config.txt │ │ │ ├── saved_model_counter │ │ │ │ └── 00000123 │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ └── variables.index │ │ │ ├── saved_model_half_plus_three │ │ │ │ └── 00000123 │ │ │ │ │ ├── assets │ │ │ │ │ └── foo.txt │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ └── variables.index │ │ │ ├── saved_model_half_plus_two.py │ │ │ ├── saved_model_half_plus_two_2_versions │ │ │ │ ├── 00000123 │ │ │ │ │ ├── assets │ │ │ │ │ │ └── foo.txt │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ │ └── variables.index │ │ │ │ └── 00000124 │ │ │ │ │ ├── assets │ │ │ │ │ └── foo.txt │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ └── variables.index │ │ │ ├── saved_model_half_plus_two_2_versions_metadata.json │ │ │ ├── saved_model_half_plus_two_cpu │ │ │ │ └── 00000123 │ │ │ │ │ ├── assets │ │ │ │ │ └── foo.txt │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ └── variables.index │ │ │ ├── saved_model_half_plus_two_gpu │ │ │ │ └── 00000123 │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ └── variables.index │ │ │ ├── saved_model_half_plus_two_gpu_trt │ │ │ │ └── 00000123 │ │ │ │ │ └── saved_model.pb │ │ │ ├── saved_model_half_plus_two_mkl │ │ │ │ └── 00000123 │ │ │ │ │ ├── assets │ │ │ │ │ └── foo.txt │ │ │ │ │ ├── saved_model.pb │ │ │ │ │ └── variables │ │ │ │ │ ├── variables.data-00000-of-00001 │ │ │ │ │ └── variables.index │ │ │ └── saved_model_half_plus_two_tflite │ │ │ │ └── 00000123 │ │ │ │ └── model.tflite │ │ ├── tflite_session.cc │ │ ├── tflite_session.h │ │ ├── tflite_session_main.cc │ │ ├── tflite_session_test.cc │ │ ├── util.cc │ │ ├── util.h │ │ └── util_test.cc │ └── xgboost │ │ ├── BUILD │ │ ├── predict_impl.cc │ │ ├── predict_impl.h │ │ ├── predict_impl_test.cc │ │ ├── testdata │ │ ├── BUILD │ │ ├── agaricus.txt.test │ │ ├── agaricus.txt.train │ │ ├── export_test_model.py │ │ ├── model_config.txt │ │ ├── platform_config.txt │ │ └── test_model │ │ │ └── 1 │ │ │ └── deploy.model │ │ ├── util.cc │ │ ├── util.h │ │ ├── xgboost_bundle.cc │ │ ├── xgboost_bundle.h │ │ ├── xgboost_bundle_test.cc │ │ ├── xgboost_constants.h │ │ ├── xgboost_source_adapter.cc │ │ ├── xgboost_source_adapter.h │ │ ├── xgboost_source_adapter.proto │ │ └── xgboost_source_adapter_test.cc ├── serving.bzl ├── session_bundle │ ├── BUILD │ ├── manifest_proto.h │ ├── oss │ │ ├── BUILD │ │ ├── manifest.proto │ │ ├── session_bundle.h │ │ ├── session_bundle_util.cc │ │ └── session_bundle_util_test.cc │ ├── session_bundle.h │ ├── session_bundle_util.h │ └── testdata │ │ └── half_plus_two │ │ └── 00000123 │ │ ├── export-00000-of-00001 │ │ └── export.meta ├── sources │ └── storage_path │ │ ├── BUILD │ │ ├── file_system_storage_path_source.cc │ │ ├── file_system_storage_path_source.h │ │ ├── file_system_storage_path_source.proto │ │ ├── file_system_storage_path_source_test.cc │ │ ├── static_storage_path_source.cc │ │ ├── static_storage_path_source.h │ │ ├── static_storage_path_source.proto │ │ └── static_storage_path_source_test.cc ├── tensorflow_version.bzl ├── test_util │ ├── BUILD │ ├── test_util.cc │ └── test_util.h ├── tools │ ├── docker │ │ ├── Dockerfile │ │ ├── Dockerfile.devel │ │ ├── Dockerfile.devel-gpu │ │ ├── Dockerfile.devel-mkl │ │ ├── Dockerfile.gpu │ │ ├── Dockerfile.mkl │ │ ├── README.md │ │ └── tests │ │ │ ├── BUILD │ │ │ ├── docker_test_lib.sh │ │ │ ├── dockerfile_devel_gpu_test.sh │ │ │ ├── dockerfile_devel_gpu_trt_test.sh │ │ │ ├── dockerfile_devel_mkl_test.sh │ │ │ ├── dockerfile_devel_test.sh │ │ │ ├── dockerfile_gpu_test.sh │ │ │ ├── dockerfile_gpu_trt_test.sh │ │ │ ├── dockerfile_mkl_test.sh │ │ │ └── dockerfile_test.sh │ └── pip_package │ │ ├── BUILD │ │ ├── build_pip_package.sh │ │ └── setup.py ├── util │ ├── BUILD │ ├── any_ptr.h │ ├── any_ptr_test.cc │ ├── class_registration.h │ ├── class_registration_test.cc │ ├── class_registration_test.proto │ ├── class_registration_util.cc │ ├── class_registration_util.h │ ├── cleanup.h │ ├── cleanup_test.cc │ ├── event_bus.h │ ├── event_bus_test.cc │ ├── executor.h │ ├── fast_read_dynamic_ptr.h │ ├── fast_read_dynamic_ptr_benchmark.cc │ ├── fast_read_dynamic_ptr_test.cc │ ├── file_probing_env.cc │ ├── file_probing_env.h │ ├── hash.cc │ ├── hash.h │ ├── inline_executor.cc │ ├── inline_executor.h │ ├── inline_executor_test.cc │ ├── json_tensor.cc │ ├── json_tensor.h │ ├── json_tensor_test.cc │ ├── net_http │ │ ├── README.md │ │ ├── client │ │ │ ├── BUILD │ │ │ ├── README.md │ │ │ ├── evhttp_connection.cc │ │ │ ├── evhttp_connection.h │ │ │ └── testing │ │ │ │ ├── BUILD │ │ │ │ └── evhttp_echo_client.cc │ │ ├── compression │ │ │ ├── BUILD │ │ │ ├── README.md │ │ │ ├── gzip_zlib.cc │ │ │ ├── gzip_zlib.h │ │ │ └── gzip_zlib_test.cc │ │ ├── internal │ │ │ ├── BUILD │ │ │ ├── fixed_thread_pool.h │ │ │ ├── net_logging.cc │ │ │ ├── net_logging.h │ │ │ └── testing │ │ │ │ ├── BUILD │ │ │ │ └── net_logging_example.cc │ │ ├── server │ │ │ ├── internal │ │ │ │ ├── BUILD │ │ │ │ ├── evhttp_request.cc │ │ │ │ ├── evhttp_request.h │ │ │ │ ├── evhttp_request_test.cc │ │ │ │ ├── evhttp_server.cc │ │ │ │ ├── evhttp_server.h │ │ │ │ ├── evhttp_server_test.cc │ │ │ │ └── server_support.h │ │ │ ├── public │ │ │ │ ├── BUILD │ │ │ │ ├── header_names.cc │ │ │ │ ├── header_names.h │ │ │ │ ├── httpserver.h │ │ │ │ ├── httpserver_interface.h │ │ │ │ ├── response_code_enum.h │ │ │ │ └── server_request_interface.h │ │ │ └── testing │ │ │ │ ├── BUILD │ │ │ │ └── evhttp_echo_server.cc │ │ └── socket │ │ │ └── testing │ │ │ ├── BUILD │ │ │ ├── ev_fetch_client.cc │ │ │ └── ev_print_req_server.cc │ ├── observer.h │ ├── observer_test.cc │ ├── optional.cc │ ├── optional.h │ ├── optional_test.cc │ ├── oss_or_google.h │ ├── prometheus_exporter.cc │ ├── prometheus_exporter.h │ ├── prometheus_exporter_test.cc │ ├── retrier.cc │ ├── retrier.h │ ├── retrier_test.cc │ ├── status.proto │ ├── status_util.cc │ ├── status_util.h │ ├── status_util_test.cc │ ├── strings │ │ ├── BUILD │ │ ├── numeric.cc │ │ ├── numeric.h │ │ ├── split.cc │ │ ├── split.h │ │ ├── string_piece.cc │ │ └── string_piece.h │ ├── tensorflow │ │ ├── BUILD │ │ ├── fake_clock_env.cc │ │ ├── fake_clock_env.h │ │ ├── periodic_function.cc │ │ └── periodic_function.h │ ├── test_util │ │ ├── BUILD │ │ └── mock_file_probing_env.h │ ├── threadpool_executor.cc │ ├── threadpool_executor.h │ ├── threadpool_executor_test.cc │ ├── unique_ptr_with_deps.h │ └── unique_ptr_with_deps_test.cc └── workspace.bzl ├── third_party ├── leveldb │ └── BUILD ├── libevent │ └── BUILD ├── rapidjson │ └── BUILD ├── tf_text │ ├── BUILD │ └── tftext.patch └── xgboost │ └── BUILD └── tools ├── gen_status_stamp.sh └── run_in_docker.sh /.bazelrc: -------------------------------------------------------------------------------- 1 | # Optimizations used for TF Serving release builds. 2 | build:release --copt=-mavx 3 | build:release --copt=-msse4.2 4 | 5 | # Options used to build with CUDA. 6 | build:cuda --crosstool_top=@local_config_cuda//crosstool:toolchain 7 | build:cuda --define=using_cuda=true --define=using_cuda_nvcc=true 8 | 9 | # Please note that MKL on MacOS or windows is still not supported. 10 | # If you would like to use a local MKL instead of downloading, please set the 11 | # environment variable "TF_MKL_ROOT" every time before build. 12 | build:mkl --define=build_with_mkl=true --define=enable_mkl=true 13 | build:mkl --define=tensorflow_mkldnn_contraction_kernel=0 14 | 15 | # This config option is used to enable MKL-DNN open source library only, 16 | # without depending on MKL binary version. 17 | build:mkl_open_source_only --define=build_with_mkl_dnn_only=true 18 | build:mkl_open_source_only --define=build_with_mkl=true --define=enable_mkl=true 19 | build:mkl_open_source_only --define=tensorflow_mkldnn_contraction_kernel=0 20 | 21 | # Processor native optimizations (depends on build host capabilities). 22 | build:nativeopt --copt=-march=native 23 | build:nativeopt --host_copt=-march=native 24 | build:nativeopt --copt=-O3 25 | 26 | build --action_env PYTHON_BIN_PATH="/usr/bin/python" 27 | build --define PYTHON_BIN_PATH=/usr/bin/python 28 | 29 | build --spawn_strategy=standalone 30 | build --genrule_strategy=standalone 31 | 32 | build --define=grpc_no_ares=true 33 | 34 | # Sets the default Apple platform to macOS. 35 | build --apple_platform_type=macos 36 | 37 | build -c opt 38 | 39 | # LLVM, MLIR and TF require C++14. 40 | build --cxxopt=-std=c++14 41 | build --host_cxxopt=-std=c++14 42 | 43 | # Adding --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0" creates parity with TF 44 | # compilation options. It also addresses memory use due to 45 | # copy-on-write semantics of std::strings of the older ABI. 46 | build --cxxopt=-D_GLIBCXX_USE_CXX11_ABI=0 47 | 48 | build --workspace_status_command=/proc/self/cwd/tools/gen_status_stamp.sh 49 | -------------------------------------------------------------------------------- /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Build 2 | 3 | on: 4 | push: 5 | branches: [ xgboost ] 6 | pull_request: 7 | branches: [ xgboost ] 8 | 9 | jobs: 10 | build: 11 | runs-on: self-hosted 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: build 15 | run: bazel build -c opt //tensorflow_serving/model_servers:tensorflow_model_server 16 | -------------------------------------------------------------------------------- /.github/workflows/test.yaml: -------------------------------------------------------------------------------- 1 | name: Test 2 | 3 | on: 4 | push: 5 | branches: [ xgboost ] 6 | pull_request: 7 | branches: [ xgboost ] 8 | 9 | jobs: 10 | build: 11 | runs-on: self-hosted 12 | steps: 13 | - uses: actions/checkout@v2 14 | - name: test 15 | run: bazel test //tensorflow_serving/... 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | /bazel-bin 3 | /bazel-ci_build-cache 4 | /bazel-genfiles 5 | /bazel-out 6 | /bazel-serving 7 | /bazel-tensorflow 8 | /bazel-tensorflow_serving 9 | /bazel-xgboost-serving 10 | /bazel-testlogs 11 | /bazel-tf 12 | /bazel-workspace 13 | /third_party/py/numpy/numpy_include 14 | /util/python/python_include 15 | /util/python/python_lib 16 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/.gitmodules -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of XGBoost Serving authors for copyright purposes. 2 | 3 | # Names should be added to this file as: 4 | # Name or Organization 5 | # The email address is not required for organizations. 6 | 7 | Google Inc. 8 | iQIYI Inc. 9 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing guidelines 2 | 3 | ## Contributing code 4 | 5 | If you have improvements to XGBoost Serving, send us your pull requests! 6 | For those just getting started, Github has a [howto](https://help.github.com/articles/using-pull-requests/). 7 | 8 | If you want to contribute but you're not sure where to start, take a look at the 9 | [issues with the "contributions welcome" label](https://github.com/hzy001/xgboost-serving/labels/contributions%20welcome). 10 | These are issues that we believe are particularly well suited for outside 11 | contributions, often because we probably won't get to them right now. If you 12 | decide to start on an issue, leave a comment so that other people know that 13 | you're working on it. If you want to help out, but not alone, use the issue 14 | comment thread to coordinate. 15 | -------------------------------------------------------------------------------- /RELEASE.md: -------------------------------------------------------------------------------- 1 | # Release 0.1.0 2 | 3 | Initial release of XGBoost Serving. 4 | -------------------------------------------------------------------------------- /tensorflow_serving/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving. 2 | 3 | package( 4 | default_visibility = ["//tensorflow_serving:internal"], 5 | ) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | exports_files(["LICENSE"]) 10 | 11 | # open source marker; do not remove 12 | 13 | package_group( 14 | name = "internal", 15 | packages = [ 16 | "//tensorflow_serving/...", 17 | ], 18 | ) 19 | 20 | filegroup( 21 | name = "all_files", 22 | srcs = glob( 23 | ["**/*"], 24 | exclude = [ 25 | "**/METADATA", 26 | "**/OWNERS", 27 | "g3doc/sitemap.md", 28 | ], 29 | ), 30 | ) 31 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/classification.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option cc_enable_arenas = true; 4 | 5 | import "tensorflow_serving/apis/input.proto"; 6 | import "tensorflow_serving/apis/model.proto"; 7 | 8 | package tensorflow.serving; 9 | 10 | // A single class. 11 | message Class { 12 | // Label or name of the class. 13 | string label = 1; 14 | // Score for this class (e.g., the probability the item belongs to this 15 | // class). As per the proto3 default-value semantics, if the score is missing, 16 | // it should be treated as 0. 17 | float score = 2; 18 | } 19 | 20 | // List of classes for a single item (tensorflow.Example). 21 | message Classifications { 22 | repeated Class classes = 1; 23 | } 24 | 25 | // Contains one result per input example, in the same order as the input in 26 | // ClassificationRequest. 27 | message ClassificationResult { 28 | repeated Classifications classifications = 1; 29 | } 30 | 31 | // RPC Interfaces 32 | 33 | message ClassificationRequest { 34 | // Model Specification. If version is not specified, will use the latest 35 | // (numerical) version. 36 | ModelSpec model_spec = 1; 37 | 38 | // Input data. 39 | tensorflow.serving.Input input = 2; 40 | } 41 | 42 | message ClassificationResponse { 43 | // Effective Model Specification used for classification. 44 | ModelSpec model_spec = 2; 45 | 46 | // Result of the classification. 47 | ClassificationResult result = 1; 48 | } 49 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/get_model_metadata.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | import "google/protobuf/any.proto"; 7 | import "tensorflow/core/protobuf/meta_graph.proto"; 8 | import "tensorflow_serving/apis/model.proto"; 9 | 10 | // Message returned for "signature_def" field. 11 | message SignatureDefMap { 12 | map signature_def = 1; 13 | }; 14 | 15 | message GetModelMetadataRequest { 16 | // Model Specification indicating which model we are querying for metadata. 17 | // If version is not specified, will use the latest (numerical) version. 18 | ModelSpec model_spec = 1; 19 | // Metadata fields to get. Currently supported: "signature_def". 20 | repeated string metadata_field = 2; 21 | } 22 | 23 | message GetModelMetadataResponse { 24 | // Model Specification indicating which model this metadata belongs to. 25 | ModelSpec model_spec = 1; 26 | // Map of metadata field name to metadata field. The options for metadata 27 | // field name are listed in GetModelMetadataRequest. Currently supported: 28 | // "signature_def". 29 | map metadata = 2; 30 | } 31 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/internal/BUILD: -------------------------------------------------------------------------------- 1 | # Internal implementation details of serving APIs. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = ["-layering_check"], 8 | ) 9 | 10 | licenses(["notice"]) # Apache 2.0 11 | 12 | load("//tensorflow_serving:serving.bzl", "serving_proto_library") 13 | 14 | serving_proto_library( 15 | name = "serialized_input_proto", 16 | srcs = ["serialized_input.proto"], 17 | cc_api_version = 2, 18 | visibility = [ 19 | "//tensorflow_serving:internal", 20 | "@org_tensorflow//tensorflow_ranking/google:__pkg__", 21 | ], 22 | deps = [ 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/internal/serialized_input.proto: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Serialized counterparts of the messages in input.proto. These protos enable 17 | // us to keep the original tensorflow.serving.Input's structure but with the 18 | // tensorflow.Examples in their serialized form. When combined with lazy 19 | // parsing, this improves performance by allowing us to skip a redundant 20 | // deserialization/serialization loop. 21 | // 22 | // WARNING: These are internal implementation details and not part of the public 23 | // API. 24 | 25 | syntax = "proto3"; 26 | 27 | option cc_enable_arenas = true; 28 | 29 | package tensorflow.serving.internal; 30 | 31 | message SerializedExampleList { 32 | repeated bytes examples = 1; 33 | } 34 | 35 | message SerializedExampleListWithContext { 36 | repeated bytes examples = 1; 37 | bytes context = 2; 38 | } 39 | 40 | message SerializedInput { 41 | oneof kind { 42 | SerializedExampleList example_list = 1; 43 | SerializedExampleListWithContext example_list_with_context = 2; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/model.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | import "google/protobuf/wrappers.proto"; 7 | 8 | // Metadata for an inference request such as the model name and version. 9 | message ModelSpec { 10 | // Required servable name. 11 | string name = 1; 12 | 13 | // Optional choice of which version of the model to use. 14 | // 15 | // Recommended to be left unset in the common case. Should be specified only 16 | // when there is a strong version consistency requirement. 17 | // 18 | // When left unspecified, the system will serve the best available version. 19 | // This is typically the latest version, though during version transitions, 20 | // notably when serving on a fleet of instances, may be either the previous or 21 | // new version. 22 | oneof version_choice { 23 | // Use this specific version number. 24 | google.protobuf.Int64Value version = 2; 25 | 26 | // Use the version associated with the given label. 27 | string version_label = 4; 28 | } 29 | // A named signature to evaluate. If unspecified, the default signature will 30 | // be used. 31 | string signature_name = 3; 32 | } 33 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/model_management.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "tensorflow_serving/config/model_server_config.proto"; 4 | import "tensorflow_serving/util/status.proto"; 5 | 6 | package tensorflow.serving; 7 | option cc_enable_arenas = true; 8 | 9 | message ReloadConfigRequest { 10 | ModelServerConfig config = 1; 11 | } 12 | 13 | message ReloadConfigResponse { 14 | StatusProto status = 1; 15 | } 16 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/model_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option cc_enable_arenas = true; 4 | 5 | import "tensorflow_serving/apis/get_model_status.proto"; 6 | import "tensorflow_serving/apis/model_management.proto"; 7 | 8 | package tensorflow.serving; 9 | 10 | // ModelService provides methods to query and update the state of the server, 11 | // e.g. which models/versions are being served. 12 | service ModelService { 13 | // Gets status of model. If the ModelSpec in the request does not specify 14 | // version, information about all versions of the model will be returned. If 15 | // the ModelSpec in the request does specify a version, the status of only 16 | // that version will be returned. 17 | rpc GetModelStatus(GetModelStatusRequest) returns (GetModelStatusResponse); 18 | 19 | // Reloads the set of served models. The new config supersedes the old one, 20 | // so if a model is omitted from the new config it will be unloaded and no 21 | // longer served. 22 | rpc HandleReloadConfigRequest(ReloadConfigRequest) 23 | returns (ReloadConfigResponse); 24 | } 25 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/predict.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | import "tensorflow/core/framework/tensor.proto"; 7 | import "tensorflow_serving/apis/model.proto"; 8 | 9 | message FeatureScore { 10 | repeated uint64 id = 1; 11 | repeated float score = 2; 12 | } 13 | 14 | message FeatureScoreVector { 15 | repeated FeatureScore feature_score = 1; 16 | } 17 | 18 | // PredictRequest specifies which XGBoostFM model to run, as well as 19 | // the XGBoost inputs and the FM inputs. 20 | message PredictRequest { 21 | // Model Specification. If version is not specified, will use the latest 22 | // (numerical) version. 23 | ModelSpec model_spec = 1; 24 | 25 | // Input FeatureScoreVector. 26 | // One for the XGBoost inputs and the other for the FM inputs. 27 | map inputs = 2; 28 | // For XGBoost only models. 29 | int32 option_mask = 3; 30 | // For XGBoost only models. 31 | uint32 ntree_limit = 4; 32 | } 33 | 34 | // Response for PredictRequest on successful run. 35 | message PredictResponse { 36 | // Effective Model Specification used to process PredictRequest. 37 | ModelSpec model_spec = 2; 38 | 39 | // Output tensors. 40 | map outputs = 1; 41 | } 42 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/prediction_log.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option cc_enable_arenas = true; 4 | 5 | import "tensorflow_serving/apis/predict.proto"; 6 | import "tensorflow_serving/core/logging.proto"; 7 | 8 | package tensorflow.serving; 9 | 10 | message PredictLog { 11 | PredictRequest request = 1; 12 | PredictResponse response = 2; 13 | } 14 | 15 | // Logged model inference request. 16 | message PredictionLog { 17 | LogMetadata log_metadata = 1; 18 | oneof log_type { 19 | PredictLog predict_log = 2; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/prediction_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | import "tensorflow_serving/apis/predict.proto"; 7 | 8 | // open source marker; do not remove 9 | // PredictionService provides access to machine-learned models loaded by 10 | // model_servers. 11 | service PredictionService { 12 | // Predict -- provides access to loaded machine-learned model. 13 | rpc Predict(PredictRequest) returns (PredictResponse); 14 | // PredictAlphafm 15 | rpc PredictAlphafm(PredictRequest) returns (PredictResponse); 16 | // PredictAlphafmSoftmax 17 | rpc PredictAlphafmSoftmax(PredictRequest) returns (PredictResponse); 18 | } 19 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/regression.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option cc_enable_arenas = true; 4 | 5 | import "tensorflow_serving/apis/input.proto"; 6 | import "tensorflow_serving/apis/model.proto"; 7 | 8 | package tensorflow.serving; 9 | 10 | // Regression result for a single item (tensorflow.Example). 11 | message Regression { 12 | float value = 1; 13 | } 14 | 15 | // Contains one result per input example, in the same order as the input in 16 | // RegressionRequest. 17 | message RegressionResult { 18 | repeated Regression regressions = 1; 19 | } 20 | 21 | // RPC interfaces. 22 | 23 | message RegressionRequest { 24 | // Model Specification. If version is not specified, will use the latest 25 | // (numerical) version. 26 | ModelSpec model_spec = 1; 27 | 28 | // Input data. 29 | tensorflow.serving.Input input = 2; 30 | } 31 | 32 | message RegressionResponse { 33 | // Effective Model Specification used for regression. 34 | ModelSpec model_spec = 2; 35 | 36 | RegressionResult result = 1; 37 | } 38 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/regressor.h: -------------------------------------------------------------------------------- 1 | 2 | /* Copyright 2016 Google Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | ==============================================================================*/ 16 | 17 | #ifndef TENSORFLOW_SERVING_APIS_REGRESSOR_H_ 18 | #define TENSORFLOW_SERVING_APIS_REGRESSOR_H_ 19 | 20 | #include "tensorflow/core/lib/core/status.h" 21 | #include "tensorflow_serving/apis/regression.pb.h" 22 | 23 | namespace tensorflow { 24 | namespace serving { 25 | 26 | /// Model agnostic interface for performing regression. 27 | /// 28 | /// Specific implementations will exist for different model types 29 | /// (e.g. TensorFlow SavedModel) that can convert the request into a model 30 | /// specific input and know how to convert the output into a generic 31 | /// RegressionResult. 32 | class RegressorInterface { 33 | public: 34 | /// Given a RegressionRequest, populates the RegressionResult with the 35 | /// result. 36 | /// 37 | /// @param request Input request specifying the model/signature to query 38 | /// along with the data payload. 39 | /// @param result The output regression results that will get populated. 40 | /// @return A status object indicating success or failure. 41 | virtual Status Regress(const RegressionRequest& request, 42 | RegressionResult* result) = 0; 43 | 44 | virtual ~RegressorInterface() = default; 45 | }; 46 | 47 | } // namespace serving 48 | } // namespace tensorflow 49 | 50 | #endif // TENSORFLOW_SERVING_APIS_REGRESSOR_H_ 51 | -------------------------------------------------------------------------------- /tensorflow_serving/apis/session_service.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option cc_enable_arenas = true; 4 | 5 | import "tensorflow_serving/apis/model.proto"; 6 | import "tensorflow/core/protobuf/config.proto"; 7 | import "tensorflow/core/protobuf/named_tensor.proto"; 8 | 9 | package tensorflow.serving; 10 | 11 | message SessionRunRequest { 12 | // Model Specification. If version is not specified, will use the latest 13 | // (numerical) version. 14 | ModelSpec model_spec = 1; 15 | 16 | // Tensors to be fed in the step. Each feed is a named tensor. 17 | repeated NamedTensorProto feed = 2; 18 | 19 | // Fetches. A list of tensor names. The caller expects a tensor to 20 | // be returned for each fetch[i] (see RunResponse.tensor). The 21 | // order of specified fetches does not change the execution order. 22 | repeated string fetch = 3; 23 | 24 | // Target Nodes. A list of node names. The named nodes will be run 25 | // to but their outputs will not be fetched. 26 | repeated string target = 4; 27 | 28 | // Options for the run call. **Currently ignored.** 29 | RunOptions options = 5; 30 | } 31 | 32 | message SessionRunResponse { 33 | // Effective Model Specification used for session run. 34 | ModelSpec model_spec = 3; 35 | 36 | // NOTE: The order of the returned tensors may or may not match 37 | // the fetch order specified in RunRequest. 38 | repeated NamedTensorProto tensor = 1; 39 | 40 | // Returned metadata if requested in the options. 41 | RunMetadata metadata = 2; 42 | } 43 | 44 | // SessionService defines a service with which a client can interact to execute 45 | // Tensorflow model inference. The SessionService::SessionRun method is similar 46 | // to MasterService::RunStep of Tensorflow, except that all sessions are ready 47 | // to run, and you request a specific model/session with ModelSpec. 48 | service SessionService { 49 | // Runs inference of a given model. 50 | rpc SessionRun(SessionRunRequest) returns (SessionRunResponse); 51 | } 52 | -------------------------------------------------------------------------------- /tensorflow_serving/batching/test_util/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving batching test utilities. 2 | 3 | package( 4 | default_visibility = ["//tensorflow_serving:internal"], 5 | features = ["-layering_check"], 6 | ) 7 | 8 | licenses(["notice"]) # Apache 2.0 9 | 10 | filegroup( 11 | name = "all_files", 12 | srcs = glob( 13 | ["**/*"], 14 | exclude = [ 15 | "**/METADATA", 16 | "**/OWNERS", 17 | ], 18 | ), 19 | ) 20 | 21 | cc_library( 22 | name = "puppet_batch_scheduler", 23 | testonly = 1, 24 | hdrs = ["puppet_batch_scheduler.h"], 25 | visibility = ["//visibility:private"], 26 | deps = [ 27 | "@org_tensorflow//tensorflow/core:tensorflow", 28 | "@org_tensorflow//tensorflow/core/kernels/batching_util:batch_scheduler", 29 | ], 30 | ) 31 | 32 | cc_test( 33 | name = "puppet_batch_scheduler_test", 34 | srcs = [ 35 | "puppet_batch_scheduler_test.cc", 36 | ], 37 | deps = [ 38 | ":puppet_batch_scheduler", 39 | "//tensorflow_serving/core/test_util:test_main", 40 | "@org_tensorflow//tensorflow/core:lib", 41 | "@org_tensorflow//tensorflow/core:test", 42 | ], 43 | ) 44 | 45 | # script that generates saved_model for matrix_half_plus_two model. 46 | py_binary( 47 | name = "matrix_half_plus_two_saved_model", 48 | srcs = ["matrix_half_plus_two_saved_model.py"], 49 | python_version = "PY2", 50 | srcs_version = "PY2AND3", 51 | deps = ["@org_tensorflow//tensorflow:tensorflow_py"], 52 | ) 53 | -------------------------------------------------------------------------------- /tensorflow_serving/batching/testdata/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving batching test data. 2 | 3 | package( 4 | default_visibility = ["//tensorflow_serving:internal"], 5 | features = ["-layering_check"], 6 | ) 7 | 8 | licenses(["notice"]) # Apache 2.0 9 | 10 | filegroup( 11 | name = "matrix_half_plus_two", 12 | srcs = glob( 13 | ["matrix_half_plus_two/**/*"], 14 | ), 15 | ) 16 | -------------------------------------------------------------------------------- /tensorflow_serving/batching/testdata/matrix_half_plus_two/1/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/batching/testdata/matrix_half_plus_two/1/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/config/log_collector_config.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | message LogCollectorConfig { 7 | // Identifies the type of the LogCollector we will use to collect these logs. 8 | string type = 1; 9 | 10 | // The prefix to use for the filenames of the logs. 11 | string filename_prefix = 2; 12 | } 13 | -------------------------------------------------------------------------------- /tensorflow_serving/config/logging_config.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | import "tensorflow_serving/config/log_collector_config.proto"; 7 | 8 | message SamplingConfig { 9 | // Requests will be logged uniformly at random with this probability. Valid 10 | // range: [0, 1.0]. 11 | double sampling_rate = 1; 12 | } 13 | 14 | // Configuration for logging query/responses. 15 | message LoggingConfig { 16 | LogCollectorConfig log_collector_config = 1; 17 | SamplingConfig sampling_config = 2; 18 | } 19 | -------------------------------------------------------------------------------- /tensorflow_serving/config/monitoring_config.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | // Configuration for Prometheus monitoring. 7 | message PrometheusConfig { 8 | // Whether to expose Prometheus metrics. 9 | bool enable = 1; 10 | 11 | // The endpoint to expose Prometheus metrics. 12 | // If not specified, PrometheusExporter::kPrometheusPath value is used. 13 | string path = 2; 14 | } 15 | 16 | // Configuration for monitoring. 17 | message MonitoringConfig { 18 | PrometheusConfig prometheus_config = 1; 19 | } 20 | -------------------------------------------------------------------------------- /tensorflow_serving/config/platform_config.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | import "google/protobuf/any.proto"; 7 | 8 | // Configuration for a servable platform e.g. tensorflow or other ML systems. 9 | message PlatformConfig { 10 | // The config proto for a SourceAdapter in the StoragePathSourceAdapter 11 | // registry. 12 | google.protobuf.Any source_adapter_config = 1; 13 | }; 14 | 15 | message PlatformConfigMap { 16 | // A map from a platform name to a platform config. The platform name is used 17 | // in ModelConfig.model_platform. 18 | map platform_configs = 1; 19 | }; 20 | -------------------------------------------------------------------------------- /tensorflow_serving/config/ssl_config.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | option cc_enable_arenas = true; 5 | 6 | // Configuration for a secure gRPC channel 7 | message SSLConfig { 8 | // private server key for SSL 9 | string server_key = 1; 10 | // public server certificate 11 | string server_cert = 2; 12 | // custom certificate authority 13 | string custom_ca = 3; 14 | // valid client certificate required ? 15 | bool client_verify = 4; 16 | }; 17 | -------------------------------------------------------------------------------- /tensorflow_serving/core/README.md: -------------------------------------------------------------------------------- 1 | Directory for non-application-specific modules. 2 | -------------------------------------------------------------------------------- /tensorflow_serving/core/aspired_version_policy.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/aspired_version_policy.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | optional AspiredVersionPolicy::GetHighestAspiredNewServableId( 22 | const std::vector& all_versions) { 23 | optional highest_version_id; 24 | for (const auto& version : all_versions) { 25 | if (version.is_aspired && version.state == LoaderHarness::State::kNew) { 26 | if (!highest_version_id || 27 | version.id.version > highest_version_id.value().version) { 28 | highest_version_id = version.id; 29 | } 30 | } 31 | } 32 | return highest_version_id; 33 | } 34 | 35 | } // namespace serving 36 | } // namespace tensorflow 37 | -------------------------------------------------------------------------------- /tensorflow_serving/core/aspired_versions_manager_builder.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/aspired_versions_manager_builder.h" 17 | 18 | #include "tensorflow_serving/core/manager_wrapper.h" 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | 23 | Status AspiredVersionsManagerBuilder::Create( 24 | Options options, std::unique_ptr* builder) { 25 | std::unique_ptr aspired_versions_manager; 26 | TF_RETURN_IF_ERROR(AspiredVersionsManager::Create(std::move(options), 27 | &aspired_versions_manager)); 28 | builder->reset( 29 | new AspiredVersionsManagerBuilder(std::move(aspired_versions_manager))); 30 | return Status::OK(); 31 | } 32 | 33 | AspiredVersionsManagerBuilder::AspiredVersionsManagerBuilder( 34 | std::unique_ptr manager) 35 | : aspired_versions_manager_(manager.get()) { 36 | manager_with_sources_.SetOwned(std::move(manager)); 37 | } 38 | 39 | std::unique_ptr AspiredVersionsManagerBuilder::Build() { 40 | return std::unique_ptr( 41 | new ManagerWrapper(std::move(manager_with_sources_))); 42 | } 43 | 44 | } // namespace serving 45 | } // namespace tensorflow 46 | -------------------------------------------------------------------------------- /tensorflow_serving/core/logging.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | 5 | import "tensorflow_serving/apis/model.proto"; 6 | import "tensorflow_serving/config/logging_config.proto"; 7 | 8 | option cc_enable_arenas = true; 9 | 10 | // Metadata logged along with the request logs. 11 | message LogMetadata { 12 | ModelSpec model_spec = 1; 13 | SamplingConfig sampling_config = 2; 14 | // List of tags used to load the relevant MetaGraphDef from SavedModel. 15 | // repeated string saved_model_tags = 3; 16 | // TODO(b/33279154): Add more metadata as mentioned in the bug. 17 | } 18 | -------------------------------------------------------------------------------- /tensorflow_serving/core/manager_wrapper.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/manager_wrapper.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | ManagerWrapper::ManagerWrapper(UniquePtrWithDeps wrapped) 22 | : wrapped_(std::move(wrapped)) {} 23 | 24 | std::vector ManagerWrapper::ListAvailableServableIds() const { 25 | return wrapped_->ListAvailableServableIds(); 26 | } 27 | 28 | Status ManagerWrapper::GetUntypedServableHandle( 29 | const ServableRequest& request, 30 | std::unique_ptr* const untyped_handle) { 31 | return wrapped_->GetUntypedServableHandle(request, untyped_handle); 32 | } 33 | 34 | std::map> 35 | ManagerWrapper::GetAvailableUntypedServableHandles() const { 36 | return wrapped_->GetAvailableUntypedServableHandles(); 37 | } 38 | 39 | } // namespace serving 40 | } // namespace tensorflow 41 | -------------------------------------------------------------------------------- /tensorflow_serving/core/servable_data_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/servable_data.h" 17 | 18 | #include 19 | 20 | #include 21 | #include "tensorflow/core/lib/core/errors.h" 22 | #include "tensorflow/core/lib/core/status_test_util.h" 23 | #include "tensorflow/core/platform/types.h" 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | namespace { 28 | 29 | TEST(ServableDataTest, NoError) { 30 | ServableId id = {"name", 42}; 31 | ServableData data(id, "yo"); 32 | EXPECT_EQ(id, data.id()); 33 | TF_EXPECT_OK(data.status()); 34 | EXPECT_EQ("yo", data.DataOrDie()); 35 | EXPECT_EQ("yo", data.ConsumeDataOrDie()); 36 | } 37 | 38 | TEST(ServableDataTest, StaticCreateNoError) { 39 | ServableId id = {"name", 42}; 40 | auto data = CreateServableData(id, "yo"); 41 | EXPECT_EQ(id, data.id()); 42 | TF_EXPECT_OK(data.status()); 43 | EXPECT_EQ("yo", data.DataOrDie()); 44 | EXPECT_EQ("yo", data.ConsumeDataOrDie()); 45 | } 46 | 47 | TEST(ServableDataTest, Error) { 48 | ServableId id = {"name", 42}; 49 | ServableData data(id, errors::Unknown("d'oh")); 50 | EXPECT_EQ(id, data.id()); 51 | EXPECT_EQ(errors::Unknown("d'oh"), data.status()); 52 | } 53 | 54 | } // namespace 55 | } // namespace serving 56 | } // namespace tensorflow 57 | -------------------------------------------------------------------------------- /tensorflow_serving/core/static_manager.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/static_manager.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | StaticManagerBuilder::StaticManagerBuilder() { 22 | BasicManager::Options basic_manager_options; 23 | // We don't want multithreading. 24 | basic_manager_options.num_load_threads = 0; 25 | basic_manager_options.num_unload_threads = 0; 26 | const Status basic_manager_status = 27 | BasicManager::Create(std::move(basic_manager_options), &basic_manager_); 28 | if (!basic_manager_status.ok()) { 29 | LOG(ERROR) << "Error creating BasicManager: " << health_; 30 | health_ = basic_manager_status; 31 | } 32 | } 33 | 34 | std::unique_ptr StaticManagerBuilder::Build() { 35 | if (!health_.ok()) { 36 | LOG(ERROR) << health_; 37 | return nullptr; 38 | } 39 | 40 | // If Build() is called again, we'll produce the following error. 41 | health_ = errors::FailedPrecondition( 42 | "Build() already called on this StaticManagerBuilder."); 43 | 44 | return std::move(basic_manager_); 45 | } 46 | 47 | } // namespace serving 48 | } // namespace tensorflow 49 | -------------------------------------------------------------------------------- /tensorflow_serving/core/storage_path.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Typedefs and registries pertaining to storage system paths. 17 | 18 | #ifndef TENSORFLOW_SERVING_CORE_STORAGE_PATH_H_ 19 | #define TENSORFLOW_SERVING_CORE_STORAGE_PATH_H_ 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "tensorflow/core/lib/core/status.h" 26 | #include "tensorflow/core/platform/types.h" 27 | #include "tensorflow_serving/core/servable_data.h" 28 | #include "tensorflow_serving/core/servable_id.h" 29 | 30 | namespace tensorflow { 31 | namespace serving { 32 | 33 | // Strings that represent paths in some storage system. 34 | using StoragePath = string; 35 | 36 | inline bool operator==(const ServableData& a, 37 | const ServableData& b) { 38 | if (a.id() != b.id()) { 39 | return false; 40 | } 41 | if (a.status().ok() != b.status().ok()) { 42 | return false; 43 | } 44 | if (a.status().ok()) { 45 | return a.DataOrDie() == b.DataOrDie(); 46 | } else { 47 | return a.status() == b.status(); 48 | } 49 | } 50 | 51 | } // namespace serving 52 | } // namespace tensorflow 53 | 54 | #endif // TENSORFLOW_SERVING_CORE_STORAGE_PATH_H_ 55 | -------------------------------------------------------------------------------- /tensorflow_serving/core/storage_path_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/storage_path.h" 17 | 18 | #include 19 | #include "tensorflow/core/lib/core/errors.h" 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | namespace { 24 | 25 | TEST(StoragePathTest, ServableDataEquality) { 26 | ServableId id0 = {"0", 0}; 27 | ServableId id1 = {"1", 1}; 28 | 29 | ServableData a(id0, "x"); 30 | ServableData a2(id0, "x"); 31 | EXPECT_TRUE(a == a); 32 | EXPECT_TRUE(a == a2); 33 | EXPECT_TRUE(a2 == a); 34 | 35 | ServableData b(id0, "y"); 36 | ServableData c(id1, "x"); 37 | ServableData d(id0, errors::Unknown("error")); 38 | for (const ServableData& other : {b, c, d}) { 39 | EXPECT_TRUE(other == other); 40 | EXPECT_FALSE(a == other); 41 | EXPECT_FALSE(other == a); 42 | } 43 | } 44 | 45 | } // namespace 46 | } // namespace serving 47 | } // namespace tensorflow 48 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/availability_test_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Methods related to the availability of servables, that are useful in writing 17 | // tests. (Not intended for production use.) 18 | 19 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_AVAILABILITY_TEST_UTIL_H_ 20 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_AVAILABILITY_TEST_UTIL_H_ 21 | 22 | #include "tensorflow_serving/core/servable_state_monitor.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | namespace test_util { 27 | 28 | // Waits until 'monitor' shows that the manager state of 'servable' is one of 29 | // 'states'. 30 | void WaitUntilServableManagerStateIsOneOf( 31 | const ServableStateMonitor& monitor, const ServableId& servable, 32 | const std::vector& states); 33 | 34 | } // namespace test_util 35 | } // namespace serving 36 | } // namespace tensorflow 37 | 38 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_AVAILABILITY_TEST_UTIL_H_ 39 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/fake_loader_source_adapter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving.test_util; 4 | 5 | // Config proto for FakeLoaderSourceAdapter. 6 | message FakeLoaderSourceAdapterConfig { 7 | // FakeLoaderSourceAdapter's 'suffix' ctor parameter. 8 | string suffix = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/fake_log_collector.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_FAKE_LOG_COLLECTOR_H_ 17 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_FAKE_LOG_COLLECTOR_H_ 18 | 19 | #include "google/protobuf/message.h" 20 | #include "tensorflow/core/lib/core/status.h" 21 | #include "tensorflow_serving/core/log_collector.h" 22 | 23 | namespace tensorflow { 24 | namespace serving { 25 | 26 | // FakeLogCollector which does nothing except count the number of times 27 | // CollectMessage has been called on it. 28 | class FakeLogCollector : public LogCollector { 29 | public: 30 | Status CollectMessage(const google::protobuf::Message& message) override { 31 | ++collect_count_; 32 | return Status::OK(); 33 | } 34 | 35 | Status Flush() override { return Status::OK(); } 36 | 37 | int collect_count() const { return collect_count_; } 38 | 39 | private: 40 | int collect_count_ = 0; 41 | }; 42 | 43 | } // namespace serving 44 | } // namespace tensorflow 45 | 46 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_FAKE_LOG_COLLECTOR_H_ 47 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/fake_storage_path_source_adapter.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/core/test_util/fake_storage_path_source_adapter.h" 17 | 18 | #include "tensorflow/core/lib/core/errors.h" 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | namespace test_util { 23 | 24 | FakeStoragePathSourceAdapter::FakeStoragePathSourceAdapter( 25 | const string& suffix, std::function call_on_destruct) 26 | : suffix_(suffix), call_on_destruct_(call_on_destruct) {} 27 | 28 | FakeStoragePathSourceAdapter::~FakeStoragePathSourceAdapter() { 29 | Detach(); 30 | if (call_on_destruct_) { 31 | call_on_destruct_(suffix_); 32 | } 33 | } 34 | 35 | Status FakeStoragePathSourceAdapter::Convert( 36 | const StoragePath& data, StoragePath* const converted_data) { 37 | if (data == "invalid") { 38 | return errors::InvalidArgument( 39 | "FakeStoragePathSourceAdapter Convert() dutifully failing on " 40 | "\"invalid\" " 41 | "data"); 42 | } 43 | *converted_data = 44 | suffix_.empty() ? data : strings::StrCat(data, "/", suffix_); 45 | return Status::OK(); 46 | } 47 | 48 | } // namespace test_util 49 | } // namespace serving 50 | } // namespace tensorflow 51 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/mock_loader.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_LOADER_H_ 17 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_LOADER_H_ 18 | 19 | #include 20 | #include "tensorflow/core/lib/core/status.h" 21 | #include "tensorflow_serving/core/loader.h" 22 | #include "tensorflow_serving/util/any_ptr.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | namespace test_util { 27 | 28 | class MockLoader : public Loader { 29 | public: 30 | MOCK_CONST_METHOD1(EstimateResources, Status(ResourceAllocation* estimate)); 31 | MOCK_METHOD0(Load, Status()); 32 | MOCK_METHOD1(LoadWithMetadata, Status(const Metadata&)); 33 | MOCK_METHOD0(Unload, void()); 34 | MOCK_METHOD0(servable, AnyPtr()); 35 | }; 36 | 37 | } // namespace test_util 38 | } // namespace serving 39 | } // namespace tensorflow 40 | 41 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_LOADER_H_ 42 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/mock_log_collector.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_LOG_COLLECTOR_H_ 17 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_LOG_COLLECTOR_H_ 18 | 19 | #include "google/protobuf/message.h" 20 | #include 21 | #include "tensorflow/core/lib/core/status.h" 22 | #include "tensorflow_serving/core/log_collector.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | 27 | class MockLogCollector : public LogCollector { 28 | public: 29 | MockLogCollector() = default; 30 | MOCK_METHOD1(CollectMessage, Status(const google::protobuf::Message& message)); 31 | MOCK_METHOD0(Flush, Status()); 32 | }; 33 | 34 | } // namespace serving 35 | } // namespace tensorflow 36 | 37 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_LOG_COLLECTOR_H_ 38 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/mock_server_request_logger.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_SERVER_REQUEST_LOGGER_H_ 17 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_SERVER_REQUEST_LOGGER_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include 23 | #include "tensorflow_serving/core/server_request_logger.h" 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | namespace test_util { 28 | 29 | class MockServerRequestLogger : public ServerRequestLogger { 30 | public: 31 | MockServerRequestLogger() : ServerRequestLogger({}) {} 32 | 33 | MOCK_METHOD1(Update, 34 | Status(const std::map>& 35 | logging_config_map)); 36 | 37 | MOCK_METHOD3(Log, Status(const google::protobuf::Message& request, 38 | const google::protobuf::Message& response, 39 | const LogMetadata& log_metadata)); 40 | }; 41 | 42 | } // namespace test_util 43 | } // namespace serving 44 | } // namespace tensorflow 45 | 46 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_SERVER_REQUEST_LOGGER_H_ 47 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/mock_storage_path_target.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_STORAGE_PATH_TARGET_H_ 17 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_STORAGE_PATH_TARGET_H_ 18 | 19 | #include 20 | 21 | #include 22 | #include "tensorflow/core/lib/core/status.h" 23 | #include "tensorflow_serving/core/storage_path.h" 24 | #include "tensorflow_serving/core/target.h" 25 | 26 | namespace tensorflow { 27 | namespace serving { 28 | namespace test_util { 29 | 30 | class MockStoragePathTarget : public TargetBase { 31 | public: 32 | ~MockStoragePathTarget() override { Detach(); } 33 | MOCK_METHOD2(SetAspiredVersions, 34 | void(const StringPiece, std::vector>)); 35 | }; 36 | 37 | } // namespace test_util 38 | } // namespace serving 39 | } // namespace tensorflow 40 | 41 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_MOCK_STORAGE_PATH_TARGET_H_ 42 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/session_test_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_CORE_TEST_UTIL_SESSION_TEST_UTIL_H_ 17 | #define TENSORFLOW_SERVING_CORE_TEST_UTIL_SESSION_TEST_UTIL_H_ 18 | 19 | #include 20 | 21 | #include "absl/base/attributes.h" 22 | #include "tensorflow/core/lib/core/status.h" 23 | #include "tensorflow/core/public/session_options.h" 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | namespace test_util { 28 | 29 | // Sets a 'hook' function, which will be called when a new session is created 30 | // via the tensorflow::NewSession() API. If the hook returns an error status, 31 | // the session creation fails. 32 | // 33 | // For this hook to be enabled, create a session by setting 34 | // SessionOptions::target as "new_session_hook/". This 35 | // will call the hook as well as return the session created when target is 36 | // "". 37 | // 38 | // Calling this method again replaces the previous hook. 39 | // 40 | // This method is NOT thread-safe. 41 | ABSL_CONST_INIT extern const char kNewSessionHookSessionTargetPrefix[]; 42 | void SetNewSessionHook(std::function hook); 43 | 44 | } // namespace test_util 45 | } // namespace serving 46 | } // namespace tensorflow 47 | 48 | #endif // TENSORFLOW_SERVING_CORE_TEST_UTIL_SESSION_TEST_UTIL_H_ 49 | -------------------------------------------------------------------------------- /tensorflow_serving/core/test_util/test_main.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // A program with a main that is suitable for unittests, including those 17 | // that also define microbenchmarks. Based on whether the user specified 18 | // the --benchmark_filter flag which specifies which benchmarks to run, 19 | // we will either run benchmarks or run the gtest tests in the program. 20 | 21 | #include "tensorflow/core/platform/platform.h" 22 | #include "tensorflow/core/platform/types.h" 23 | 24 | #if defined(PLATFORM_GOOGLE) || defined(__ANDROID__) 25 | // main() is supplied by gunit_main 26 | #else 27 | #include "gtest/gtest.h" 28 | #include "tensorflow/core/lib/strings/str_util.h" 29 | #include "tensorflow/core/platform/test_benchmark.h" 30 | 31 | GTEST_API_ int main(int argc, char** argv) { 32 | std::cout << "Running main() from test_main.cc\n"; 33 | 34 | testing::InitGoogleTest(&argc, argv); 35 | for (int i = 1; i < argc; i++) { 36 | if (tensorflow::str_util::StartsWith(argv[i], "--benchmarks=")) { 37 | const char* pattern = argv[i] + strlen("--benchmarks="); 38 | tensorflow::testing::Benchmark::Run(pattern); 39 | return 0; 40 | } 41 | } 42 | return RUN_ALL_TESTS(); 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /tensorflow_serving/docs/cn/building_with_docker.md: -------------------------------------------------------------------------------- 1 | # 在 Docker 中构建 XGBoost Serving 2 | 3 | 为了统一构建环境,我们推荐在 Docker 中构建 XGBoost Serving。XGBoost Serving Docker 开发镜像集成了构建 XGBoost Serving 所需的全部依赖。 4 | 5 | **注意:目前我们仅支持构建运行在 Linux 平台上的可执行文件。** 6 | 7 | ## 安装 Docker 8 | 9 | 安装 Docker 的方法请参考 [安装 Docker](https://docs.docker.com/get-docker/). 10 | 11 | ## Clone XGBoost Serving 仓库 12 | 13 | 安装 Docker 后,执行以下命令 Clone XGBoost Serving 仓库: 14 | 15 | ``` 16 | git clone https://github.com/iqiyi/xgboost-serving.git 17 | cd xgboost-serving 18 | ``` 19 | 20 | 该命令会安装 xgboost 分支,如果需要安装其它分支,请 checkout 到所需分支。 21 | 22 | ## Pull Docker 开发镜像 23 | 24 | 执行以下命令 Pull Docker 开发镜像: 25 | 26 | ``` 27 | docker pull hzy001/xgboost-serving:latest-devel 28 | ``` 29 | 30 | ## 构建 tensorflow_model_server 31 | 32 | 执行以下命令构建 `tensorflow_model_server`: 33 | 34 | ``` 35 | ./tools/run_in_docker.sh bazel build -c opt //tensorflow_serving/model_servers:tensorflow_model_server 36 | ``` 37 | 38 | `tensorflow_model_server` 可执行文件放在 `bazel-bin` 路径,执行以下命令运行 `tensorflow_model_server`: 39 | 40 | ``` 41 | ./tools/run_in_docker.sh ./bazel-bin/tensorflow_serving/model_servers/tensorflow_model_server 42 | ``` 43 | 44 | ## 构建 Python API PIP 包 45 | 46 | 执行以下命令生成 `build_pip_package` 可执行文件: 47 | 48 | ``` 49 | ./tools/run_in_docker.sh bazel build -c opt //tensorflow_serving/tools/pip_package:build_pip_package 50 | ``` 51 | 52 | `build_pip_package` 可执行文件放在 `bazel-bin` 路径,执行以下命令生成 Python API PIP 包: 53 | 54 | ``` 55 | ./tools/run_in_docker.sh ./bazel-bin/tensorflow_serving/tools/pip_package/build_pip_package $(pwd) 56 | ``` 57 | 58 | 该命令会在当前路径生成 `tensorflow_serving_api-2.0.0-py2.py3-none-any.whl` 包,安装后可使用 tensorflow serving apis。 59 | -------------------------------------------------------------------------------- /tensorflow_serving/example/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving examples. 2 | 3 | package( 4 | default_visibility = ["//tensorflow_serving:internal"], 5 | features = ["no_layering_check"], 6 | ) 7 | 8 | licenses(["notice"]) # Apache 2.0 9 | 10 | filegroup( 11 | name = "all_files", 12 | srcs = glob( 13 | ["**/*"], 14 | exclude = [ 15 | "**/METADATA", 16 | "**/OWNERS", 17 | ], 18 | ), 19 | ) 20 | 21 | cc_binary( 22 | name = "xgboost_client_cc", 23 | srcs = [ 24 | "xgboost_client.cc", 25 | ], 26 | deps = [ 27 | "//tensorflow_serving/apis:prediction_service_proto", 28 | "@com_google_protobuf//:protobuf_lite", 29 | "@grpc//:grpc++", 30 | "@org_tensorflow//tensorflow/core:framework", 31 | "@org_tensorflow//tensorflow/core:lib", 32 | ], 33 | ) 34 | 35 | cc_binary( 36 | name = "alphafm_client_cc", 37 | srcs = [ 38 | "alphafm_client.cc", 39 | ], 40 | deps = [ 41 | "//tensorflow_serving/apis:prediction_service_proto", 42 | "@com_google_protobuf//:protobuf_lite", 43 | "@grpc//:grpc++", 44 | "@org_tensorflow//tensorflow/core:framework", 45 | "@org_tensorflow//tensorflow/core:lib", 46 | ], 47 | ) 48 | 49 | cc_binary( 50 | name = "alphafm_softmax_client_cc", 51 | srcs = [ 52 | "alphafm_softmax_client.cc", 53 | ], 54 | deps = [ 55 | "//tensorflow_serving/apis:prediction_service_proto", 56 | "@com_google_protobuf//:protobuf_lite", 57 | "@grpc//:grpc++", 58 | "@org_tensorflow//tensorflow/core:framework", 59 | "@org_tensorflow//tensorflow/core:lib", 60 | ], 61 | ) 62 | -------------------------------------------------------------------------------- /tensorflow_serving/example/resnet_k8s.yaml: -------------------------------------------------------------------------------- 1 | # Copyright 2017 Google Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ============================================================================== 15 | 16 | apiVersion: extensions/v1beta1 17 | kind: Deployment 18 | metadata: 19 | name: resnet-deployment 20 | spec: 21 | replicas: 3 22 | template: 23 | metadata: 24 | labels: 25 | app: resnet-server 26 | spec: 27 | containers: 28 | - name: resnet-container 29 | image: gcr.io/tensorflow-serving/resnet 30 | ports: 31 | - containerPort: 8500 32 | --- 33 | apiVersion: v1 34 | kind: Service 35 | metadata: 36 | labels: 37 | run: resnet-service 38 | name: resnet-service 39 | spec: 40 | ports: 41 | - port: 8500 42 | targetPort: 8500 43 | selector: 44 | app: resnet-server 45 | type: LoadBalancer 46 | -------------------------------------------------------------------------------- /tensorflow_serving/g3doc/_toc.yaml: -------------------------------------------------------------------------------- 1 | toc: 2 | - title: TensorFlow Serving with Docker 3 | path: /tfx/serving/docker 4 | - title: Installation 5 | path: /tfx/serving/setup 6 | - title: Serve a TensorFlow model 7 | path: /tfx/serving/serving_basic 8 | - title: Architecture 9 | path: /tfx/serving/architecture 10 | - title: Advanced model server configuration 11 | path: /tfx/serving/serving_config 12 | - title: Build a TensorFlow ModelServer 13 | path: /tfx/serving/serving_advanced 14 | - title: Use TensorFlow Serving with Kubernetes 15 | path: /tfx/serving/serving_kubernetes 16 | - title: Create a new kind of servable 17 | path: /tfx/serving/custom_servable 18 | - title: Create a module that discovers new servable paths 19 | path: /tfx/serving/custom_source 20 | - title: Serving TensorFlow models with custom ops 21 | path: /tfx/serving/custom_op 22 | - title: SignatureDefs in SavedModel for TensorFlow Serving 23 | path: /tfx/serving/signature_defs 24 | -------------------------------------------------------------------------------- /tensorflow_serving/g3doc/tutorials/README.md: -------------------------------------------------------------------------------- 1 | # TensorFlow Serving tutorials 2 | 3 | Tutorials moved to: https://github.com/tensorflow/tfx/tree/master/docs/tutorials 4 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/grpc_status_util.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/model_servers/grpc_status_util.h" 17 | 18 | #include "grpcpp/support/status_code_enum.h" 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | 23 | ::grpc::Status ToGRPCStatus(const ::tensorflow::Status& status) { 24 | const int kErrorMessageLimit = 1024; 25 | string error_message; 26 | if (status.error_message().length() > kErrorMessageLimit) { 27 | error_message = 28 | status.error_message().substr(0, kErrorMessageLimit) + "...TRUNCATED"; 29 | } else { 30 | error_message = status.error_message(); 31 | } 32 | return ::grpc::Status(static_cast(status.code()), 33 | error_message); 34 | } 35 | 36 | } // namespace serving 37 | } // namespace tensorflow 38 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/grpc_status_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_MODEL_SERVERS_GRPC_STATUS_UTIL_H_ 17 | #define TENSORFLOW_SERVING_MODEL_SERVERS_GRPC_STATUS_UTIL_H_ 18 | 19 | #include "grpcpp/support/status.h" 20 | #include "tensorflow/core/lib/core/status.h" 21 | 22 | namespace tensorflow { 23 | namespace serving { 24 | 25 | // Converts from tensorflow Status to GRPC Status. 26 | ::grpc::Status ToGRPCStatus(const ::tensorflow::Status& status); 27 | 28 | } // namespace serving 29 | } // namespace tensorflow 30 | 31 | #endif // TENSORFLOW_SERVING_MODEL_SERVERS_GRPC_STATUS_UTIL_H_ 32 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/http_server.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_SERVER_H_ 16 | #define TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_SERVER_H_ 17 | 18 | #include 19 | 20 | #include "tensorflow_serving/config/monitoring_config.pb.h" 21 | #include "tensorflow_serving/util/net_http/server/public/httpserver_interface.h" 22 | 23 | namespace tensorflow { 24 | namespace serving { 25 | 26 | class ServerCore; 27 | 28 | // Returns a HTTP Server that has following endpoints: 29 | // 30 | // o HTTP/REST API (under /v1/models/...) 31 | // 32 | // The returned server is in a state of accepting new requests. 33 | std::unique_ptr CreateAndStartHttpServer( 34 | int port, int num_threads, int timeout_in_ms, 35 | const MonitoringConfig& monitoring_config, ServerCore* core); 36 | 37 | } // namespace serving 38 | } // namespace tensorflow 39 | #endif // TENSORFLOW_SERVING_MODEL_SERVERS_HTTP_SERVER_H_ 40 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/model_platform_types.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_MODEL_SERVERS_MODEL_PLATFORM_TYPES_H_ 17 | #define TENSORFLOW_SERVING_MODEL_SERVERS_MODEL_PLATFORM_TYPES_H_ 18 | 19 | namespace tensorflow { 20 | namespace serving { 21 | 22 | constexpr char kTensorFlowModelPlatform[] = "tensorflow"; 23 | constexpr char kXGBoostModelPlatform[] = "xgboost"; 24 | 25 | } // namespace serving 26 | } // namespace tensorflow 27 | 28 | #endif // TENSORFLOW_SERVING_MODEL_SERVERS_MODEL_PLATFORM_TYPES_H_ 29 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/tensorflow_model_server_test_client.py: -------------------------------------------------------------------------------- 1 | # Copyright 2016 Google Inc. All Rights Reserved. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # ============================================================================== 15 | """Manual test client for tensorflow_model_server.""" 16 | 17 | from __future__ import absolute_import 18 | from __future__ import division 19 | from __future__ import print_function 20 | 21 | # This is a placeholder for a Google-internal import. 22 | 23 | import grpc 24 | import tensorflow as tf 25 | 26 | from tensorflow.core.framework import types_pb2 27 | from tensorflow.python.platform import flags 28 | from tensorflow_serving.apis import predict_pb2 29 | from tensorflow_serving.apis import prediction_service_pb2_grpc 30 | 31 | 32 | tf.app.flags.DEFINE_string('server', 'localhost:8500', 33 | 'inception_inference service host:port') 34 | FLAGS = tf.app.flags.FLAGS 35 | 36 | 37 | def main(_): 38 | # Prepare request 39 | request = predict_pb2.PredictRequest() 40 | request.model_spec.name = 'default' 41 | request.inputs['x'].dtype = types_pb2.DT_FLOAT 42 | request.inputs['x'].float_val.append(2.0) 43 | request.output_filter.append('y') 44 | # Send request 45 | channel = grpc.insecure_channel(FLAGS.server) 46 | stub = prediction_service_pb2_grpc.PredictionServiceStub(channel) 47 | print(stub.Predict(request, 5.0)) # 5 secs timeout 48 | 49 | 50 | if __name__ == '__main__': 51 | tf.app.run() 52 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/test_util/storage_path_error_injecting_source_adapter.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/model_servers/test_util/storage_path_error_injecting_source_adapter.h" 17 | #include "tensorflow_serving/core/source_adapter.h" 18 | #include "tensorflow_serving/model_servers/test_util/storage_path_error_injecting_source_adapter.pb.h" 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | namespace test_util { 23 | 24 | // Register the source adapter. 25 | class StoragePathErrorInjectingSourceAdapterCreator { 26 | public: 27 | static Status Create( 28 | const StoragePathErrorInjectingSourceAdapterConfig& config, 29 | std::unique_ptr>>* 30 | adapter) { 31 | adapter->reset( 32 | new ErrorInjectingSourceAdapter>( 33 | Status(error::CANCELLED, config.error_message()))); 34 | return Status::OK(); 35 | } 36 | }; 37 | REGISTER_STORAGE_PATH_SOURCE_ADAPTER( 38 | StoragePathErrorInjectingSourceAdapterCreator, 39 | StoragePathErrorInjectingSourceAdapterConfig); 40 | 41 | } // namespace test_util 42 | } // namespace serving 43 | } // namespace tensorflow 44 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/test_util/storage_path_error_injecting_source_adapter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_MODEL_SERVERS_TEST_UTIL_STORAGE_PATH_ERROR_INJECTING_SOURCE_ADAPTER_H_ 17 | #define TENSORFLOW_SERVING_MODEL_SERVERS_TEST_UTIL_STORAGE_PATH_ERROR_INJECTING_SOURCE_ADAPTER_H_ 18 | 19 | #include "tensorflow_serving/core/source_adapter.h" 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | namespace test_util { 24 | 25 | // An ErrorInjectingSourceAdapter> (see 26 | // source_adapter.h) registered in StoragePathSourceAdapterRegistry and keyed on 27 | // StoragePathErrorInjectingSourceAdapterConfig. 28 | using StoragePathErrorInjectingSourceAdapter = 29 | ErrorInjectingSourceAdapter>; 30 | 31 | } // namespace test_util 32 | } // namespace serving 33 | } // namespace tensorflow 34 | 35 | #endif // TENSORFLOW_SERVING_MODEL_SERVERS_TEST_UTIL_STORAGE_PATH_ERROR_INJECTING_SOURCE_ADAPTER_H_ 36 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/test_util/storage_path_error_injecting_source_adapter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving.test_util; 4 | 5 | // Config proto for StoragePathErrorInjectingSourceAdapter. 6 | message StoragePathErrorInjectingSourceAdapterConfig { 7 | // The error message the adapter emits. 8 | string error_message = 1; 9 | } 10 | -------------------------------------------------------------------------------- /tensorflow_serving/model_servers/version.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/model_servers/version.h" 17 | 18 | const char kTFS_SCM_Revision[] = TF_MODELSERVER_VERSION_STRING; 19 | 20 | extern "C" { 21 | const char* TF_Serving_Version() { return kTFS_SCM_Revision; } 22 | } 23 | -------------------------------------------------------------------------------- /tensorflow_serving/oss_or_google.bzl: -------------------------------------------------------------------------------- 1 | """ 2 | Module for build utilities to distiguish different build environment. 3 | """ 4 | 5 | # Whether the compilation environment is open source environment. 6 | is_oss = True 7 | 8 | # Helper build function. 9 | # Returns the input if is_oss is true. 10 | # Returns empty list otherwise. 11 | def if_oss(a): 12 | if is_oss: 13 | return a 14 | else: 15 | return [] 16 | 17 | # Helper build function. 18 | # Returns the input if is_oss is false. 19 | # Returns empty list otherwise. 20 | def if_google(a): 21 | if is_oss: 22 | return [] 23 | else: 24 | return a 25 | 26 | # cc_test that is only run in open source environment. 27 | def oss_only_cc_test(name, srcs = [], deps = [], data = [], size = "medium", linkstatic = 0): 28 | if is_oss: 29 | return native.cc_test( 30 | name = name, 31 | deps = deps, 32 | srcs = srcs, 33 | data = data, 34 | size = size, 35 | linkstatic = linkstatic, 36 | ) 37 | else: 38 | return None 39 | -------------------------------------------------------------------------------- /tensorflow_serving/repo.bzl: -------------------------------------------------------------------------------- 1 | """ TensorFlow Http Archive 2 | 3 | Modified http_archive that allows us to override the TensorFlow commit that is 4 | downloaded by setting an environment variable. This override is to be used for 5 | testing purposes. 6 | 7 | Add the following to your Bazel build command in order to override the 8 | TensorFlow revision. 9 | 10 | build: --action_env TF_REVISION="" 11 | 12 | * `TF_REVISION`: tensorflow revision override (git commit hash) 13 | """ 14 | 15 | _TF_REVISION = "TF_REVISION" 16 | 17 | def _tensorflow_http_archive(ctx): 18 | git_commit = ctx.attr.git_commit 19 | sha256 = ctx.attr.sha256 20 | 21 | override_git_commit = ctx.os.environ.get(_TF_REVISION) 22 | if override_git_commit: 23 | sha256 = "" 24 | git_commit = override_git_commit 25 | 26 | strip_prefix = "tensorflow-%s" % git_commit 27 | urls = [ 28 | "https://mirror.bazel.build/github.com/tensorflow/tensorflow/archive/%s.tar.gz" % git_commit, 29 | "https://github.com/tensorflow/tensorflow/archive/%s.tar.gz" % git_commit, 30 | ] 31 | ctx.download_and_extract( 32 | urls, 33 | "", 34 | sha256, 35 | "", 36 | strip_prefix, 37 | ) 38 | 39 | tensorflow_http_archive = repository_rule( 40 | implementation = _tensorflow_http_archive, 41 | attrs = { 42 | "git_commit": attr.string(mandatory = True), 43 | "sha256": attr.string(mandatory = True), 44 | }, 45 | ) 46 | -------------------------------------------------------------------------------- /tensorflow_serving/resources/resource_values.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/resources/resource_values.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | namespace device_types { 22 | const char* const kMain = "main"; 23 | const char* const kGpu = "gpu"; 24 | const char* const kTpu = "tpu"; 25 | } // namespace device_types 26 | 27 | namespace resource_kinds { 28 | const char* const kNumModelSlots = "num_model_slots"; 29 | const char* const kRamBytes = "ram_in_bytes"; 30 | const char* const kHeapRamBytes = "heap_ram_in_bytes"; 31 | const char* const kStackRamBytes = "stack_ram_in_bytes"; 32 | const char* const kProcessingMillis = "processing_in_millicores"; 33 | } // namespace resource_kinds 34 | 35 | } // namespace serving 36 | } // namespace tensorflow 37 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/alphafm_bundle_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/servables/alphafm/alphafm_bundle.h" 17 | 18 | #include "tensorflow/core/lib/core/errors.h" 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow/core/lib/core/status_test_util.h" 21 | #include "tensorflow/core/lib/io/path.h" 22 | #include "tensorflow/core/lib/strings/strcat.h" 23 | #include "tensorflow/core/platform/env.h" 24 | #include "tensorflow/core/platform/test.h" 25 | #include "tensorflow/core/platform/types.h" 26 | #include 27 | #include 28 | 29 | namespace tensorflow { 30 | namespace serving { 31 | namespace { 32 | TEST(AlphafmBundleTest, Basic) { 33 | AlphafmBundle bundle; 34 | TF_ASSERT_OK(bundle.LoadAllModel( 35 | "tensorflow_serving/servables/alphafm/testdata/test_model/1")); 36 | } 37 | } // namespace 38 | } // namespace serving 39 | } // namespace tensorflow 40 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/alphafm_source_adapter.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "alphafm_source_adapter.h" 17 | 18 | #include 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | 23 | AlphafmSourceAdapter::AlphafmSourceAdapter() 24 | : SimpleLoaderSourceAdapter( 25 | [](const StoragePath &path, std::unique_ptr * bundle) { 26 | bundle->reset(new AlphafmBundle()); 27 | return (*bundle)->LoadAllModel(path); 28 | }, 29 | SimpleLoaderSourceAdapter::EstimateNoResources()) {} 31 | AlphafmSourceAdapter::~AlphafmSourceAdapter() { Detach(); } 32 | 33 | // Register the source adapter. 34 | class AlphafmSourceAdapterCreator { 35 | public: 36 | static Status 37 | Create(const AlphafmSourceAdapterConfig &config, 38 | std::unique_ptr>> 39 | *adapter) { 40 | adapter->reset(new AlphafmSourceAdapter()); 41 | return Status::OK(); 42 | } 43 | }; 44 | REGISTER_STORAGE_PATH_SOURCE_ADAPTER(AlphafmSourceAdapterCreator, 45 | AlphafmSourceAdapterConfig); 46 | 47 | } // namespace serving 48 | } // namespace tensorflow 49 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/alphafm_source_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_ALPHAFM_ALPHAFM_SOURCE_ADAPTER_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_ALPHAFM_ALPHAFM_SOURCE_ADAPTER_H_ 18 | 19 | #include "tensorflow_serving/core/simple_loader.h" 20 | #include "tensorflow_serving/core/source_adapter.h" 21 | #include "tensorflow_serving/core/storage_path.h" 22 | #include "tensorflow_serving/servables/alphafm/alphafm_bundle.h" 23 | #include "tensorflow_serving/servables/alphafm/alphafm_source_adapter.pb.h" 24 | #include "xgboost/c_api.h" 25 | 26 | namespace tensorflow { 27 | namespace serving { 28 | class AlphafmSourceAdapter final 29 | : public SimpleLoaderSourceAdapter { 30 | public: 31 | AlphafmSourceAdapter(); 32 | ~AlphafmSourceAdapter() override; 33 | 34 | private: 35 | friend class AlphafmSourceAdapterCreator; 36 | TF_DISALLOW_COPY_AND_ASSIGN(AlphafmSourceAdapter); 37 | }; 38 | } 39 | } 40 | 41 | #endif // TENSORFLOW_SERVING_SERVABLES_ALPHAFM_ALPHAFM_SOURCE_ADAPTER_H_ 42 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/alphafm_source_adapter.proto: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | syntax = "proto3"; 17 | 18 | package tensorflow.serving; 19 | 20 | // Config proto for AlphafmSourceAdapter. 21 | message AlphafmSourceAdapterConfig { 22 | } 23 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/feature_mapping.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_ALPHAFM_FEATURE_MAPPING_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_ALPHAFM_FEATURE_MAPPING_H_ 18 | 19 | #include "tensorflow/core/lib/core/errors.h" 20 | #include "tensorflow/core/lib/core/status.h" 21 | 22 | #include 23 | #include 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | class FeatureMapping { 28 | public: 29 | FeatureMapping(); 30 | FeatureMapping(std::string model_path); 31 | Status LoadModel(std::string model_path); 32 | Status GetFeatureId(uint32_t tree_num, uint32_t leaf_index, 33 | uint64_t *feature_id); 34 | void UnloadModel(); 35 | ~FeatureMapping(); 36 | 37 | private: 38 | std::unordered_map> 39 | tree_leaf_feature_map_; 40 | Status GetFeatureIdInMap(uint32_t tree_num, uint32_t leaf_index, 41 | uint64_t *feature_id); 42 | }; 43 | } // namespace serving 44 | } // namespace tensorflow 45 | 46 | #endif // TENSORFLOW_SERVING_SERVABLES_ALPHAFM_FEATURE_MAPPING_H_ 47 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/feature_mapping_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/servables/alphafm/feature_mapping.h" 17 | 18 | #include "tensorflow/core/lib/core/errors.h" 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow/core/lib/core/status_test_util.h" 21 | #include "tensorflow/core/lib/io/path.h" 22 | #include "tensorflow/core/lib/strings/strcat.h" 23 | #include "tensorflow/core/platform/env.h" 24 | #include "tensorflow/core/platform/test.h" 25 | #include "tensorflow/core/platform/types.h" 26 | #include 27 | #include 28 | 29 | namespace tensorflow { 30 | namespace serving { 31 | namespace { 32 | TEST(FeatureMappingTest, Basic) { 33 | FeatureMapping feature_mapping("tensorflow_serving/servables/alphafm/" 34 | "testdata/test_model/1/deploy.leaf_mapping"); 35 | uint32_t tree_num = 0; 36 | uint32_t leaf_index = 31; 37 | uint64_t feature_id; 38 | Status status = 39 | feature_mapping.GetFeatureId(tree_num, leaf_index, &feature_id); 40 | EXPECT_EQ(feature_id, 4097); 41 | } 42 | } // namespace 43 | } // namespace serving 44 | } // namespace tensorflow 45 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/predict_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_ALPHAFM_PREDICT_IMPL_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_ALPHAFM_PREDICT_IMPL_H_ 18 | 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow_serving/apis/predict.pb.h" 21 | #include "tensorflow_serving/model_servers/server_core.h" 22 | 23 | #include 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | 28 | class AlphafmPredictor { 29 | public: 30 | AlphafmPredictor(); 31 | 32 | Status Predict(ServerCore *core, const PredictRequest &request, 33 | PredictResponse *response); 34 | 35 | Status PredictWithModelSpec(ServerCore *core, const ModelSpec &model_spec, 36 | const PredictRequest &request, 37 | PredictResponse *response); 38 | 39 | ~AlphafmPredictor(); 40 | 41 | private: 42 | static bvar::LatencyRecorder alphafm_xgboost_latency_recorder; 43 | static bvar::LatencyRecorder alphafm_latency_recorder; 44 | }; 45 | } // namespace serving 46 | } // namespace tensorflow 47 | 48 | #endif // TENSORFLOW_SERVING_SERVABLES_ALPHAFM_PREDICT_IMPL_H_ 49 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/testdata/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Example xgboost model export. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = [ 8 | "-layering_check", 9 | "-parse_headers", 10 | ], 11 | ) 12 | 13 | licenses(["notice"]) # Apache 2.0 14 | 15 | filegroup( 16 | name = "all_files", 17 | srcs = glob( 18 | ["**/*"], 19 | exclude = [ 20 | "**/METADATA", 21 | "**/OWNERS", 22 | ], 23 | ), 24 | ) 25 | 26 | py_runtime( 27 | name = "xgboost_python3_runtime", 28 | interpreter_path = "/usr/local/bin/python3.7", 29 | files = [], 30 | ) 31 | 32 | py_binary( 33 | name = "export_test_model", 34 | srcs = [ 35 | "export_test_model.py", 36 | ], 37 | python_version = "PY3", 38 | srcs_version = "PY3", 39 | deps = [ 40 | ], 41 | data = [ 42 | "agaricus.txt.train", 43 | "agaricus.txt.test", 44 | ], 45 | ) 46 | 47 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/testdata/export_test_model.py: -------------------------------------------------------------------------------- 1 | # Written by Hao Ziyu , May 2020. 2 | 3 | #!/usr/bin/env python3.7 4 | 5 | import xgboost as xgb 6 | import scipy 7 | 8 | import time 9 | 10 | if __name__ == "__main__": 11 | dtrain = xgb.DMatrix("bazel-out/k8-py3-opt/bin/tensorflow_serving/servables/xgboost/testdata/export_test_model.runfiles/tf_serving/tensorflow_serving/servables/xgboost/testdata/agaricus.txt.train") 12 | dtest = xgb.DMatrix("bazel-out/k8-py3-opt/bin/tensorflow_serving/servables/xgboost/testdata/export_test_model.runfiles/tf_serving/tensorflow_serving/servables/xgboost/testdata/agaricus.txt.test") 13 | params = {"max_depth": 2, "eta": 1, "silent": 1, "objective": "binary:logistic"} 14 | num_round = 2 15 | bst = xgb.train(params, dtrain, num_round) 16 | bst.save_model("/tmp/deploy.model") 17 | indptr = [0, 127] 18 | indices = [i for i in range(0, 127)] 19 | data = [i+1 for i in range(0, 127)] 20 | dtest = scipy.sparse.csr_matrix((data, indices, indptr), shape=(1, 127)) 21 | dtest = xgb.DMatrix(dtest) 22 | preds = bst.predict(dtest, False, 0, True) 23 | print(preds) 24 | 25 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/testdata/model_config.txt: -------------------------------------------------------------------------------- 1 | model_config_list { 2 | config { 3 | name: "test" 4 | base_path: "/home/haoziyu/github/opensource/xgboost-serving/tensorflow_serving/servables/alphafm/testdata/test_model" 5 | model_platform: "alphafm" 6 | model_version_policy { 7 | latest { 8 | num_versions: 2 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/testdata/platform_config.txt: -------------------------------------------------------------------------------- 1 | platform_configs { 2 | key: "alphafm" 3 | value { 4 | source_adapter_config { 5 | [type.googleapis.com/tensorflow.serving.AlphafmSourceAdapterConfig] { 6 | } 7 | } 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm/testdata/test_model/1/deploy.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/alphafm/testdata/test_model/1/deploy.model -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_bundle_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_bundle.h" 17 | 18 | #include "tensorflow/core/lib/core/errors.h" 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow/core/lib/core/status_test_util.h" 21 | #include "tensorflow/core/lib/io/path.h" 22 | #include "tensorflow/core/lib/strings/strcat.h" 23 | #include "tensorflow/core/platform/env.h" 24 | #include "tensorflow/core/platform/test.h" 25 | #include "tensorflow/core/platform/types.h" 26 | #include 27 | #include 28 | 29 | namespace tensorflow { 30 | namespace serving { 31 | namespace { 32 | TEST(AlphafmSoftmaxBundleTest, Basic) { 33 | AlphafmSoftmaxBundle bundle; 34 | TF_ASSERT_OK(bundle.LoadAlphafmSoftmaxModel( 35 | "tensorflow_serving/servables/alphafm_softmax/testdata/test_model/1")); 36 | } 37 | } // namespace 38 | } // namespace serving 39 | } // namespace tensorflow 40 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_source_adapter.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "alphafm_softmax_source_adapter.h" 17 | 18 | #include 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | 23 | AlphafmSoftmaxSourceAdapter::AlphafmSoftmaxSourceAdapter() 24 | : SimpleLoaderSourceAdapter( 25 | [](const StoragePath &path, 26 | std::unique_ptr * bundle) { 27 | bundle->reset(new AlphafmSoftmaxBundle()); 28 | return (*bundle)->LoadAlphafmSoftmaxModel(path); 29 | }, 30 | SimpleLoaderSourceAdapter< 31 | StoragePath, AlphafmSoftmaxBundle>::EstimateNoResources()) {} 32 | AlphafmSoftmaxSourceAdapter::~AlphafmSoftmaxSourceAdapter() { Detach(); } 33 | 34 | // Register the source adapter. 35 | class AlphafmSoftmaxSourceAdapterCreator { 36 | public: 37 | static Status 38 | Create(const AlphafmSoftmaxSourceAdapterConfig &config, 39 | std::unique_ptr>> 40 | *adapter) { 41 | adapter->reset(new AlphafmSoftmaxSourceAdapter()); 42 | return Status::OK(); 43 | } 44 | }; 45 | REGISTER_STORAGE_PATH_SOURCE_ADAPTER(AlphafmSoftmaxSourceAdapterCreator, 46 | AlphafmSoftmaxSourceAdapterConfig); 47 | 48 | } // namespace serving 49 | } // namespace tensorflow 50 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_source_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_ALPHAFM_SOFTMAX_ALPHAFM_SOFTMAX_SOURCE_ADAPTER_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_ALPHAFM_SOFTMAX_ALPHAFM_SOFTMAX_SOURCE_ADAPTER_H_ 18 | #include "tensorflow_serving/core/simple_loader.h" 19 | #include "tensorflow_serving/core/source_adapter.h" 20 | #include "tensorflow_serving/core/storage_path.h" 21 | #include "tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_bundle.h" 22 | #include "tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_source_adapter.pb.h" 23 | #include "xgboost/c_api.h" 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | class AlphafmSoftmaxSourceAdapter final 28 | : public SimpleLoaderSourceAdapter { 29 | public: 30 | AlphafmSoftmaxSourceAdapter(); 31 | ~AlphafmSoftmaxSourceAdapter() override; 32 | 33 | private: 34 | friend class AlphafmSoftmaxSourceAdapterCreator; 35 | TF_DISALLOW_COPY_AND_ASSIGN(AlphafmSoftmaxSourceAdapter); 36 | }; 37 | } 38 | } 39 | 40 | #endif // TENSORFLOW_SERVING_SERVABLES_ALPHAFM_SOFTMAX_ALPHAFM_SOFTMAX_SOURCE_ADAPTER_H_ 41 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/alphafm_softmax_source_adapter.proto: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | syntax = "proto3"; 17 | 18 | package tensorflow.serving; 19 | 20 | // Config proto for AlphafmSoftmaxSourceAdapter. 21 | message AlphafmSoftmaxSourceAdapterConfig { 22 | } 23 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/predict_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_ALPHAFM_SOFTMAX_PREDICT_IMPL_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_ALPHAFM_SOFTMAX_PREDICT_IMPL_H_ 18 | 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow_serving/apis/predict.pb.h" 21 | #include "tensorflow_serving/model_servers/server_core.h" 22 | 23 | #include 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | 28 | class AlphafmSoftmaxPredictor { 29 | public: 30 | AlphafmSoftmaxPredictor(); 31 | 32 | Status Predict(ServerCore *core, const PredictRequest &request, 33 | PredictResponse *response); 34 | 35 | Status PredictWithModelSpec(ServerCore *core, const ModelSpec &model_spec, 36 | const PredictRequest &request, 37 | PredictResponse *response); 38 | 39 | ~AlphafmSoftmaxPredictor(); 40 | 41 | private: 42 | static bvar::LatencyRecorder alphafm_softmax_xgboost_latency_recorder; 43 | static bvar::LatencyRecorder alphafm_softmax_latency_recorder; 44 | }; 45 | } // namespace serving 46 | } // namespace tensorflow 47 | 48 | #endif // TENSORFLOW_SERVING_SERVABLES_ALPHAFM_SOFTMAX_PREDICT_IMPL_H_ 49 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/testdata/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Example xgboost model export. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = [ 8 | "-layering_check", 9 | "-parse_headers", 10 | ], 11 | ) 12 | 13 | licenses(["notice"]) # Apache 2.0 14 | 15 | filegroup( 16 | name = "all_files", 17 | srcs = glob( 18 | ["**/*"], 19 | exclude = [ 20 | "**/METADATA", 21 | "**/OWNERS", 22 | ], 23 | ), 24 | ) 25 | 26 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/testdata/model_config.txt: -------------------------------------------------------------------------------- 1 | model_config_list { 2 | config { 3 | name: "test" 4 | base_path: "/home/haoziyu/github/opensource/xgboost-serving/tensorflow_serving/servables/alphafm_softmax/testdata/test_model" 5 | model_platform: "alphafm_softmax" 6 | model_version_policy { 7 | latest { 8 | num_versions: 2 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/testdata/platform_config.txt: -------------------------------------------------------------------------------- 1 | platform_configs { 2 | key: "alphafm_softmax" 3 | value { 4 | source_adapter_config { 5 | [type.googleapis.com/tensorflow.serving.AlphafmSoftmaxSourceAdapterConfig] { 6 | } 7 | } 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/alphafm_softmax/testdata/test_model/1/deploy.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/alphafm_softmax/testdata/test_model/1/deploy.model -------------------------------------------------------------------------------- /tensorflow_serving/servables/hashmap/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving hashmap servable. 2 | 3 | package( 4 | default_visibility = ["//tensorflow_serving:internal"], 5 | features = ["-layering_check"], 6 | ) 7 | 8 | licenses(["notice"]) # Apache 2.0 9 | 10 | filegroup( 11 | name = "all_files", 12 | srcs = glob( 13 | ["**/*"], 14 | exclude = [ 15 | "**/METADATA", 16 | "**/OWNERS", 17 | "g3doc/sitemap.md", 18 | ], 19 | ), 20 | ) 21 | 22 | cc_library( 23 | name = "hashmap_source_adapter", 24 | srcs = ["hashmap_source_adapter.cc"], 25 | hdrs = ["hashmap_source_adapter.h"], 26 | visibility = [ 27 | "//visibility:public", 28 | ], 29 | deps = [ 30 | ":hashmap_source_adapter_proto", 31 | "//tensorflow_serving/core:simple_loader", 32 | "//tensorflow_serving/core:source_adapter", 33 | "//tensorflow_serving/core:storage_path", 34 | "@org_tensorflow//tensorflow/core:lib", 35 | # "@org_tensorflow//tensorflow/core:tensorflow", 36 | ], 37 | ) 38 | 39 | cc_test( 40 | name = "hashmap_source_adapter_test", 41 | size = "medium", 42 | srcs = ["hashmap_source_adapter_test.cc"], 43 | deps = [ 44 | ":hashmap_source_adapter", 45 | ":hashmap_source_adapter_proto", 46 | "//tensorflow_serving/core:loader", 47 | "//tensorflow_serving/core:servable_data", 48 | "//tensorflow_serving/core/test_util:test_main", 49 | "//tensorflow_serving/util:any_ptr", 50 | "@org_tensorflow//tensorflow/core:lib", 51 | "@org_tensorflow//tensorflow/core:test", 52 | ], 53 | ) 54 | 55 | load("//tensorflow_serving:serving.bzl", "serving_proto_library") 56 | 57 | serving_proto_library( 58 | name = "hashmap_source_adapter_proto", 59 | srcs = ["hashmap_source_adapter.proto"], 60 | cc_api_version = 2, 61 | ) 62 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/hashmap/hashmap_source_adapter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_HASHMAP_HASHMAP_SOURCE_ADAPTER_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_HASHMAP_HASHMAP_SOURCE_ADAPTER_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "tensorflow_serving/core/simple_loader.h" 23 | #include "tensorflow_serving/core/source_adapter.h" 24 | #include "tensorflow_serving/core/storage_path.h" 25 | #include "tensorflow_serving/servables/hashmap/hashmap_source_adapter.pb.h" 26 | 27 | namespace tensorflow { 28 | namespace serving { 29 | 30 | // A SourceAdapter for string-string hashmaps. It takes storage paths that give 31 | // the locations of serialized hashmaps (in the format indicated in the config) 32 | // and produces loaders for them. 33 | class HashmapSourceAdapter final 34 | : public SimpleLoaderSourceAdapter> { 36 | public: 37 | explicit HashmapSourceAdapter(const HashmapSourceAdapterConfig& config); 38 | ~HashmapSourceAdapter() override; 39 | 40 | private: 41 | TF_DISALLOW_COPY_AND_ASSIGN(HashmapSourceAdapter); 42 | }; 43 | 44 | } // namespace serving 45 | } // namespace tensorflow 46 | 47 | #endif // TENSORFLOW_SERVING_SERVABLES_HASHMAP_HASHMAP_SOURCE_ADAPTER_H_ 48 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/hashmap/hashmap_source_adapter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | 5 | // Config proto for HashmapSourceAdapter. 6 | message HashmapSourceAdapterConfig { 7 | // The format used by the file containing a serialized hashmap. 8 | enum Format { 9 | // A simple kind of CSV text file of the form: 10 | // key0,value0\n 11 | // key1,value1\n 12 | // ... 13 | SIMPLE_CSV = 0; 14 | } 15 | Format format = 1; 16 | } 17 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/get_model_metadata_impl.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_GET_MODEL_METADATA_IMPL_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_GET_MODEL_METADATA_IMPL_H_ 18 | 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow_serving/apis/get_model_metadata.pb.h" 21 | #include "tensorflow_serving/model_servers/server_core.h" 22 | 23 | namespace tensorflow { 24 | namespace serving { 25 | 26 | class GetModelMetadataImpl { 27 | public: 28 | static constexpr const char kSignatureDef[] = "signature_def"; 29 | 30 | static Status GetModelMetadata(ServerCore* core, 31 | const GetModelMetadataRequest& request, 32 | GetModelMetadataResponse* response); 33 | 34 | // Like GetModelMetadata(), but uses 'model_spec' instead of the one embedded 35 | // in 'request'. 36 | static Status GetModelMetadataWithModelSpec( 37 | ServerCore* core, const ModelSpec& model_spec, 38 | const GetModelMetadataRequest& request, 39 | GetModelMetadataResponse* response); 40 | }; 41 | 42 | } // namespace serving 43 | } // namespace tensorflow 44 | 45 | #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_GET_MODEL_METADATA_IMPL_H_ 46 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/multi_inference_helper.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_MULTI_INFERENCE_HELPER_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_MULTI_INFERENCE_HELPER_H_ 18 | 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow_serving/apis/inference.pb.h" 21 | #include "tensorflow_serving/model_servers/server_core.h" 22 | #include "tensorflow_serving/util/optional.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | 27 | // Runs MultiInference 28 | Status RunMultiInferenceWithServerCore(const RunOptions& run_options, 29 | ServerCore* core, 30 | const MultiInferenceRequest& request, 31 | MultiInferenceResponse* response); 32 | 33 | // Like RunMultiInferenceWithServerCore(), but uses 'model_spec' instead of the 34 | // one(s) embedded in 'request'. 35 | Status RunMultiInferenceWithServerCoreWithModelSpec( 36 | const RunOptions& run_options, ServerCore* core, 37 | const ModelSpec& model_spec, const MultiInferenceRequest& request, 38 | MultiInferenceResponse* response); 39 | 40 | } // namespace serving 41 | } // namespace tensorflow 42 | 43 | #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_MULTI_INFERENCE_HELPER_H_ 44 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/saved_model_bundle_source_adapter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "tensorflow_serving/servables/tensorflow/session_bundle_config.proto"; 4 | 5 | package tensorflow.serving; 6 | 7 | // Config proto for SavedModelBundleSourceAdapter. 8 | message SavedModelBundleSourceAdapterConfig { 9 | // A SessionBundleConfig. 10 | // FOR INTERNAL USE ONLY DURING TRANSITION TO SAVED_MODEL. WILL BE DEPRECATED. 11 | // TODO(b/32248363): Replace this field with the "real" field(s). 12 | SessionBundleConfig legacy_config = 1000; 13 | } 14 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/serving_session.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/servables/tensorflow/serving_session.h" 17 | 18 | #include "tensorflow/core/framework/graph.pb.h" 19 | #include "tensorflow/core/lib/core/errors.h" 20 | #include "tensorflow/core/lib/core/status.h" 21 | 22 | namespace tensorflow { 23 | namespace serving { 24 | 25 | Status ServingSession::Create(const GraphDef& graph) { 26 | return errors::PermissionDenied("State changes denied via ServingSession"); 27 | } 28 | 29 | Status ServingSession::Extend(const GraphDef& graph) { 30 | return errors::PermissionDenied("State changes denied via ServingSession"); 31 | } 32 | 33 | Status ServingSession::Close() { 34 | return errors::PermissionDenied("State changes denied via ServingSession"); 35 | } 36 | 37 | } // namespace serving 38 | } // namespace tensorflow 39 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/session_bundle_source_adapter.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | import "tensorflow_serving/servables/tensorflow/session_bundle_config.proto"; 4 | 5 | package tensorflow.serving; 6 | 7 | // Config proto for SessionBundleSourceAdapter. 8 | message SessionBundleSourceAdapterConfig { 9 | SessionBundleConfig config = 1; 10 | } 11 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/bad_half_plus_two/00000123/checkpoint: -------------------------------------------------------------------------------- 1 | model_checkpoint_path: "/tmp/bad_half_plus_two/00000123/export" 2 | all_model_checkpoint_paths: "/tmp/bad_half_plus_two/00000123/export" 3 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/bad_half_plus_two/00000123/export: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/bad_half_plus_two/00000123/export -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/bad_half_plus_two/00000123/export.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/bad_half_plus_two/00000123/export.meta -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/bad_model_config.txt: -------------------------------------------------------------------------------- 1 | improperly formatted file -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/batching_config.txt: -------------------------------------------------------------------------------- 1 | max_batch_size { value: 128 } 2 | batch_timeout_micros { value: 0 } 3 | max_enqueued_batches { value: 1000000 } 4 | num_batch_threads { value: 8 } 5 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/good_model_config.txt: -------------------------------------------------------------------------------- 1 | model_config_list: { 2 | config: { 3 | name: "half_plus_two", 4 | base_path: "${TEST_HALF_PLUS_TWO_DIR}", 5 | model_platform: "tensorflow" 6 | }, 7 | config: { 8 | name: "half_plus_three", 9 | base_path: "${TEST_HALF_PLUS_THREE_DIR}", 10 | model_platform: "tensorflow" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two/00000123/export.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two/00000123/export.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/half_plus_two/00000123/export.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two/00000123/export.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/half_plus_two/00000123/export.meta -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000123/export.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000123/export.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000123/export.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000123/export.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000123/export.meta -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000124/export.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000124/export.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000124/export.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000124/export.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/half_plus_two_2_versions/00000124/export.meta -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/monitoring_config.txt: -------------------------------------------------------------------------------- 1 | prometheus_config: { 2 | enable: true, 3 | path: "/monitoring/prometheus/metrics" 4 | } 5 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_counter/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_counter/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_counter/00000123/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_counter/00000123/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_counter/00000123/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/00000123/assets/foo.txt: -------------------------------------------------------------------------------- 1 | asset-file-contents -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/00000123/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@@@@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/00000123/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_three/00000123/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000123/assets/foo.txt: -------------------------------------------------------------------------------- 1 | asset-file-contents -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000123/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@@@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000123/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000123/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000124/assets/foo.txt: -------------------------------------------------------------------------------- 1 | asset-file-contents -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000124/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000124/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000124/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@@@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000124/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_2_versions/00000124/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123/assets/foo.txt: -------------------------------------------------------------------------------- 1 | asset-file-contents -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ??@@@@@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_cpu/00000123/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu/00000123/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- 1 | ?@@@ -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu/00000123/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu/00000123/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu_trt/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_gpu_trt/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/assets/foo.txt: -------------------------------------------------------------------------------- 1 | asset-file-contents -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/saved_model.pb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/saved_model.pb -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/variables/variables.data-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/variables/variables.data-00000-of-00001 -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/variables/variables.index: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_mkl/00000123/variables/variables.index -------------------------------------------------------------------------------- /tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_tflite/00000123/model.tflite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/tensorflow/testdata/saved_model_half_plus_two_tflite/00000123/model.tflite -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/predict_impl.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_XGBOOST_PREDICT_IMPL_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_XGBOOST_PREDICT_IMPL_H_ 18 | 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow_serving/apis/predict.pb.h" 21 | #include "tensorflow_serving/model_servers/server_core.h" 22 | 23 | #include 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | 28 | class XgboostPredictor { 29 | public: 30 | XgboostPredictor(); 31 | 32 | Status Predict(ServerCore *core, const PredictRequest &request, 33 | PredictResponse *response); 34 | 35 | Status PredictWithModelSpec(ServerCore *core, const ModelSpec &model_spec, 36 | const PredictRequest &request, 37 | PredictResponse *response); 38 | 39 | ~XgboostPredictor(); 40 | 41 | private: 42 | static bvar::LatencyRecorder xgboost_latency_recorder; 43 | }; 44 | } // namespace serving 45 | } // namespace tensorflow 46 | 47 | #endif // TENSORFLOW_SERVING_SERVABLES_XGBOOST_PREDICT_IMPL_H_ 48 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/testdata/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Example xgboost model export. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = [ 8 | "-layering_check", 9 | "-parse_headers", 10 | ], 11 | ) 12 | 13 | licenses(["notice"]) # Apache 2.0 14 | 15 | filegroup( 16 | name = "all_files", 17 | srcs = glob( 18 | ["**/*"], 19 | exclude = [ 20 | "**/METADATA", 21 | "**/OWNERS", 22 | ], 23 | ), 24 | ) 25 | 26 | py_runtime( 27 | name = "xgboost_python3_runtime", 28 | interpreter_path = "/usr/local/bin/python3.7", 29 | files = [], 30 | ) 31 | 32 | py_binary( 33 | name = "export_test_model", 34 | srcs = [ 35 | "export_test_model.py", 36 | ], 37 | python_version = "PY3", 38 | srcs_version = "PY3", 39 | deps = [ 40 | ], 41 | data = [ 42 | "agaricus.txt.train", 43 | "agaricus.txt.test", 44 | ], 45 | ) 46 | 47 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/testdata/export_test_model.py: -------------------------------------------------------------------------------- 1 | # Written by Hao Ziyu , May 2020. 2 | 3 | #!/usr/bin/env python3.7 4 | 5 | import xgboost as xgb 6 | import scipy 7 | 8 | import time 9 | 10 | if __name__ == "__main__": 11 | dtrain = xgb.DMatrix("bazel-out/k8-py3-opt/bin/tensorflow_serving/servables/xgboost/testdata/export_test_model.runfiles/tf_serving/tensorflow_serving/servables/xgboost/testdata/agaricus.txt.train") 12 | dtest = xgb.DMatrix("bazel-out/k8-py3-opt/bin/tensorflow_serving/servables/xgboost/testdata/export_test_model.runfiles/tf_serving/tensorflow_serving/servables/xgboost/testdata/agaricus.txt.test") 13 | params = {"max_depth": 2, "eta": 1, "silent": 1, "objective": "binary:logistic"} 14 | num_round = 2 15 | bst = xgb.train(params, dtrain, num_round) 16 | bst.save_model("/tmp/deploy.model") 17 | indptr = [0, 127] 18 | indices = [i for i in range(0, 127)] 19 | data = [i+1 for i in range(0, 127)] 20 | dtest = scipy.sparse.csr_matrix((data, indices, indptr), shape=(1, 127)) 21 | dtest = xgb.DMatrix(dtest) 22 | preds = bst.predict(dtest, False, 0, True) 23 | print(preds) 24 | 25 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/testdata/model_config.txt: -------------------------------------------------------------------------------- 1 | model_config_list { 2 | config { 3 | name: "test" 4 | base_path: "/home/haoziyu/github/opensource/xgboost-serving/tensorflow_serving/servables/xgboost/testdata/test_model" 5 | model_platform: "xgboost" 6 | model_version_policy { 7 | latest { 8 | num_versions: 2 9 | } 10 | } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/testdata/platform_config.txt: -------------------------------------------------------------------------------- 1 | platform_configs { 2 | key: "xgboost" 3 | value { 4 | source_adapter_config { 5 | [type.googleapis.com/tensorflow.serving.XgboostSourceAdapterConfig] { 6 | } 7 | } 8 | } 9 | } 10 | 11 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/testdata/test_model/1/deploy.model: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/servables/xgboost/testdata/test_model/1/deploy.model -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/xgboost_bundle.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_BUNDLE_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_BUNDLE_H_ 18 | 19 | #include "tensorflow/core/lib/core/errors.h" 20 | #include "tensorflow/core/lib/core/status.h" 21 | #include "xgboost/c_api.h" 22 | #include 23 | #include 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | class XgboostBundle { 28 | public: 29 | XgboostBundle(); 30 | 31 | XgboostBundle(std::string model_path); 32 | 33 | // Load the xgboost model from the given path. 34 | Status LoadXgboostModel(std::string model_path); 35 | 36 | // Unload the xgboost model. 37 | Status UnloadXgboostModel(); 38 | 39 | // Get the BoosterHandle. 40 | BoosterHandle GetBoosterHandle() const; 41 | 42 | ~XgboostBundle(); 43 | 44 | private: 45 | BoosterHandle xgbooster_; // Handle to the Booster. 46 | }; 47 | } 48 | } 49 | 50 | #endif // TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_BUNDLE_H_ 51 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/xgboost_bundle_test.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/servables/xgboost/xgboost_bundle.h" 17 | 18 | #include "tensorflow/core/lib/core/errors.h" 19 | #include "tensorflow/core/lib/core/status.h" 20 | #include "tensorflow/core/lib/core/status_test_util.h" 21 | #include "tensorflow/core/lib/io/path.h" 22 | #include "tensorflow/core/lib/strings/strcat.h" 23 | #include "tensorflow/core/platform/env.h" 24 | #include "tensorflow/core/platform/test.h" 25 | #include "tensorflow/core/platform/types.h" 26 | #include 27 | #include 28 | 29 | namespace tensorflow { 30 | namespace serving { 31 | namespace { 32 | TEST(XgboostBundleTest, Basic) { 33 | XgboostBundle bundle; 34 | TF_ASSERT_OK(bundle.LoadXgboostModel( 35 | "tensorflow_serving/servables/xgboost/testdata/test_model/1")); 36 | } 37 | } // namespace 38 | } // namespace serving 39 | } // namespace tensorflow 40 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/xgboost_constants.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_CONSTANTS_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_CONSTANTS_H_ 18 | 19 | #include 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | const std::string kXGBoostModelFileName = "deploy.model"; 24 | const std::string kFmModelFileName = "deploy.fm"; 25 | const std::string kFeatureMappingFileName = "deploy.leaf_mapping"; 26 | const std::string kXGBoostFeaturesName = "xgboost_features"; 27 | const std::string kFMFeaturesName = "fm_features"; 28 | } // namespace serving 29 | } // namespace tensorflow 30 | 31 | #endif // TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_CONSTANTS_H_ 32 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/xgboost_source_adapter.cc: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "xgboost_source_adapter.h" 17 | 18 | #include 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | 23 | XgboostSourceAdapter::XgboostSourceAdapter() 24 | : SimpleLoaderSourceAdapter( 25 | [](const StoragePath &path, std::unique_ptr * bundle) { 26 | bundle->reset(new XgboostBundle()); 27 | return (*bundle)->LoadXgboostModel(path); 28 | }, 29 | SimpleLoaderSourceAdapter::EstimateNoResources()) {} 31 | XgboostSourceAdapter::~XgboostSourceAdapter() { Detach(); } 32 | 33 | // Register the source adapter. 34 | class XgboostSourceAdapterCreator { 35 | public: 36 | static Status 37 | Create(const XgboostSourceAdapterConfig &config, 38 | std::unique_ptr>> 39 | *adapter) { 40 | adapter->reset(new XgboostSourceAdapter()); 41 | return Status::OK(); 42 | } 43 | }; 44 | REGISTER_STORAGE_PATH_SOURCE_ADAPTER(XgboostSourceAdapterCreator, 45 | XgboostSourceAdapterConfig); 46 | 47 | } // namespace serving 48 | } // namespace tensorflow 49 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/xgboost_source_adapter.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_SOURCE_ADAPTER_H_ 17 | #define TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_SOURCE_ADAPTER_H_ 18 | 19 | #include "tensorflow_serving/core/simple_loader.h" 20 | #include "tensorflow_serving/core/source_adapter.h" 21 | #include "tensorflow_serving/core/storage_path.h" 22 | #include "tensorflow_serving/servables/xgboost/xgboost_bundle.h" 23 | #include "tensorflow_serving/servables/xgboost/xgboost_source_adapter.pb.h" 24 | #include "xgboost/c_api.h" 25 | 26 | namespace tensorflow { 27 | namespace serving { 28 | class XgboostSourceAdapter final 29 | : public SimpleLoaderSourceAdapter { 30 | public: 31 | XgboostSourceAdapter(); 32 | ~XgboostSourceAdapter() override; 33 | 34 | private: 35 | friend class XgboostSourceAdapterCreator; 36 | TF_DISALLOW_COPY_AND_ASSIGN(XgboostSourceAdapter); 37 | }; 38 | } 39 | } 40 | 41 | #endif // TENSORFLOW_SERVING_SERVABLES_XGBOOST_XGBOOST_SOURCE_ADAPTER_H_ 42 | -------------------------------------------------------------------------------- /tensorflow_serving/servables/xgboost/xgboost_source_adapter.proto: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | syntax = "proto3"; 17 | 18 | package tensorflow.serving; 19 | 20 | // Config proto for XgboostSourceAdapter. 21 | message XgboostSourceAdapterConfig { 22 | } 23 | -------------------------------------------------------------------------------- /tensorflow_serving/serving.bzl: -------------------------------------------------------------------------------- 1 | load("@com_google_protobuf//:protobuf.bzl", "cc_proto_library") 2 | load("@com_google_protobuf//:protobuf.bzl", "py_proto_library") 3 | 4 | def serving_proto_library( 5 | name, 6 | srcs = [], 7 | has_services = False, # pylint: disable=unused-argument 8 | deps = [], 9 | visibility = None, 10 | testonly = 0, 11 | cc_grpc_version = None, 12 | cc_api_version = 2): # pylint: disable=unused-argument 13 | native.filegroup( 14 | name = name + "_proto_srcs", 15 | srcs = srcs, 16 | testonly = testonly, 17 | ) 18 | 19 | use_grpc_plugin = None 20 | if cc_grpc_version: 21 | use_grpc_plugin = True 22 | cc_proto_library( 23 | name = name, 24 | srcs = srcs, 25 | deps = deps, 26 | cc_libs = ["@com_google_protobuf//:protobuf"], 27 | protoc = "@com_google_protobuf//:protoc", 28 | default_runtime = "@com_google_protobuf//:protobuf", 29 | use_grpc_plugin = use_grpc_plugin, 30 | testonly = testonly, 31 | visibility = visibility, 32 | ) 33 | 34 | def serving_go_grpc_library(**kwargs): # pylint: disable=unused-argument 35 | """Build the Go gRPC bindings for a service. Not yet implemented.""" 36 | return 37 | 38 | def serving_proto_library_py(name, proto_library, srcs = [], deps = [], visibility = None, testonly = 0): # pylint: disable=unused-argument 39 | py_proto_library( 40 | name = name, 41 | srcs = srcs, 42 | srcs_version = "PY2AND3", 43 | deps = ["@com_google_protobuf//:protobuf_python"] + deps, 44 | default_runtime = "@com_google_protobuf//:protobuf_python", 45 | protoc = "@com_google_protobuf//:protoc", 46 | visibility = visibility, 47 | testonly = testonly, 48 | ) 49 | -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/BUILD: -------------------------------------------------------------------------------- 1 | load("//tensorflow_serving:oss_or_google.bzl", "if_google", "if_oss") 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | package( 6 | default_visibility = [ 7 | "//tensorflow_serving:internal", 8 | ], 9 | ) 10 | 11 | filegroup( 12 | name = "session_bundle_half_plus_two", 13 | srcs = glob([ 14 | "testdata/half_plus_two/**", 15 | ]), 16 | ) 17 | 18 | cc_library( 19 | name = "manifest_proto_header", 20 | hdrs = ["manifest_proto.h"], 21 | deps = ["//tensorflow_serving/util:oss_or_google"] + if_oss([ 22 | "//tensorflow_serving/session_bundle/oss:manifest_proto_cc", 23 | ]) + if_google(["//tensorflow_serving/session_bundle/google:manifest_proto_cc"]), 24 | ) 25 | 26 | cc_library( 27 | name = "session_bundle", 28 | hdrs = ["session_bundle.h"], 29 | deps = ["//tensorflow_serving/util:oss_or_google"] + if_oss([ 30 | "//tensorflow_serving/session_bundle/oss:session_bundle", 31 | ]) + if_google(["@org_tensorflow//tensorflow/contrib/session_bundle"]), 32 | ) 33 | 34 | cc_library( 35 | name = "session_bundle_util_header", 36 | hdrs = ["session_bundle_util.h"], 37 | deps = [ 38 | ":manifest_proto_header", 39 | ":session_bundle", 40 | "@org_tensorflow//tensorflow/cc/saved_model:loader", 41 | ], 42 | ) 43 | 44 | cc_library( 45 | name = "session_bundle_util", 46 | deps = if_oss(["//tensorflow_serving/session_bundle/oss:session_bundle_util"]) + if_google(["//tensorflow_serving/session_bundle/google:session_bundle_util"]), 47 | ) 48 | -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/manifest_proto.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SESSION_BUNDLE_MANIFEST_PROTO_H_ 17 | #define TENSORFLOW_SERVING_SESSION_BUNDLE_MANIFEST_PROTO_H_ 18 | 19 | #include "tensorflow_serving/util/oss_or_google.h" 20 | 21 | #ifdef TENSORFLOW_SERVING_GOOGLE 22 | #include "tensorflow_serving/session_bundle/google/manifest.pb.h" 23 | #else 24 | #include "tensorflow_serving/session_bundle/oss/manifest.pb.h" 25 | #endif 26 | 27 | #endif // TENSORFLOW_SERVING_SESSION_BUNDLE_MANIFEST_PROTO_H_ 28 | -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/oss/BUILD: -------------------------------------------------------------------------------- 1 | load("@org_tensorflow//tensorflow/core:platform/default/build_config.bzl", "tf_proto_library") 2 | load("//tensorflow_serving:oss_or_google.bzl", "oss_only_cc_test") 3 | 4 | licenses(["notice"]) # Apache 2.0 5 | 6 | package( 7 | default_visibility = [ 8 | "//tensorflow_serving:internal", 9 | ], 10 | features = ["-layering_check"], 11 | ) 12 | 13 | tf_proto_library( 14 | name = "manifest_proto", 15 | srcs = ["manifest.proto"], 16 | cc_api_version = 2, 17 | ) 18 | 19 | cc_library( 20 | name = "session_bundle", 21 | hdrs = ["session_bundle.h"], 22 | deps = [ 23 | "@org_tensorflow//tensorflow/core:core_cpu", 24 | ], 25 | ) 26 | 27 | cc_library( 28 | name = "session_bundle_util", 29 | srcs = ["session_bundle_util.cc"], 30 | deps = [ 31 | ":manifest_proto_cc", 32 | ":session_bundle", 33 | "//tensorflow_serving/session_bundle:session_bundle_util_header", 34 | "@org_tensorflow//tensorflow/cc/saved_model:loader", 35 | ], 36 | ) 37 | 38 | oss_only_cc_test( 39 | name = "session_bundle_util_test", 40 | srcs = ["session_bundle_util_test.cc"], 41 | data = [ 42 | "//tensorflow_serving/session_bundle:session_bundle_half_plus_two", 43 | "@org_tensorflow//tensorflow/cc/saved_model:saved_model_half_plus_two", 44 | ], 45 | deps = [ 46 | ":session_bundle_util", 47 | "//tensorflow_serving/core/test_util:test_main", 48 | "//tensorflow_serving/test_util", 49 | ], 50 | ) 51 | -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/oss/session_bundle.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SESSION_BUNDLE_OSS_SESSION_BUNDLE_H_ 17 | #define TENSORFLOW_SERVING_SESSION_BUNDLE_OSS_SESSION_BUNDLE_H_ 18 | 19 | #include "tensorflow/core/protobuf/meta_graph.pb.h" 20 | #include "tensorflow/core/public/session.h" 21 | 22 | namespace tensorflow { 23 | namespace serving { 24 | 25 | // Dummy SessionBundle class. 26 | // SessionBundle is deprecated and not supported in Tensorflow Serving. 27 | struct SessionBundle { 28 | std::unique_ptr session; 29 | MetaGraphDef meta_graph_def; 30 | }; 31 | 32 | } // namespace serving 33 | } // namespace tensorflow 34 | 35 | #endif // TENSORFLOW_SERVING_SESSION_BUNDLE_OSS_SESSION_BUNDLE_H_ 36 | -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/session_bundle.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_SESSION_BUNDLE_SESSION_BUNDLE_H_ 17 | #define TENSORFLOW_SERVING_SESSION_BUNDLE_SESSION_BUNDLE_H_ 18 | 19 | #include "tensorflow_serving/util/oss_or_google.h" 20 | 21 | #ifdef TENSORFLOW_SERVING_GOOGLE 22 | #include "tensorflow/contrib/session_bundle/session_bundle.h" 23 | #else 24 | #include "tensorflow_serving/session_bundle/oss/session_bundle.h" 25 | #endif 26 | 27 | #endif // TENSORFLOW_SERVING_SESSION_BUNDLE_SESSION_BUNDLE_H_ 28 | -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/testdata/half_plus_two/00000123/export-00000-of-00001: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/session_bundle/testdata/half_plus_two/00000123/export-00000-of-00001 -------------------------------------------------------------------------------- /tensorflow_serving/session_bundle/testdata/half_plus_two/00000123/export.meta: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/iqiyi/xgboost-serving/394f104921130020aa05fe0fb575133f0137faf7/tensorflow_serving/session_bundle/testdata/half_plus_two/00000123/export.meta -------------------------------------------------------------------------------- /tensorflow_serving/sources/storage_path/static_storage_path_source.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/sources/storage_path/static_storage_path_source.h" 17 | 18 | #include 19 | #include 20 | 21 | #include "tensorflow_serving/core/servable_data.h" 22 | #include "tensorflow_serving/core/servable_id.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | 27 | Status StaticStoragePathSource::Create( 28 | const StaticStoragePathSourceConfig& config, 29 | std::unique_ptr* result) { 30 | auto raw_result = new StaticStoragePathSource; 31 | raw_result->config_ = config; 32 | result->reset(raw_result); 33 | return Status::OK(); 34 | } 35 | 36 | void StaticStoragePathSource::SetAspiredVersionsCallback( 37 | AspiredVersionsCallback callback) { 38 | const ServableId id = {config_.servable_name(), config_.version_num()}; 39 | LOG(INFO) << "Aspiring servable " << id; 40 | callback(config_.servable_name(), 41 | {CreateServableData(id, config_.version_path())}); 42 | } 43 | 44 | } // namespace serving 45 | } // namespace tensorflow 46 | -------------------------------------------------------------------------------- /tensorflow_serving/sources/storage_path/static_storage_path_source.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | package tensorflow.serving; 4 | 5 | // Config proto for StaticStoragePathSource. 6 | message StaticStoragePathSourceConfig { 7 | // The single servable name, version number and path to supply statically. 8 | string servable_name = 1; 9 | int64 version_num = 2; 10 | string version_path = 3; 11 | } 12 | -------------------------------------------------------------------------------- /tensorflow_serving/tensorflow_version.bzl: -------------------------------------------------------------------------------- 1 | """ 2 | Module for build utilities to distiguish different tensorflow versions. 3 | """ 4 | 5 | load("@org_tensorflow//tensorflow:tensorflow.bzl", "VERSION_MAJOR") 6 | 7 | def if_v2(a): 8 | if VERSION_MAJOR == "2": 9 | return a 10 | else: 11 | return [] 12 | 13 | def if_not_v2(a): 14 | if VERSION_MAJOR == "2": 15 | return [] 16 | else: 17 | return a 18 | -------------------------------------------------------------------------------- /tensorflow_serving/test_util/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving test utils. 2 | 3 | package(default_visibility = [ 4 | "//tensorflow_serving:internal", 5 | ]) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | filegroup( 10 | name = "all_files", 11 | srcs = glob( 12 | ["**/*"], 13 | exclude = [ 14 | "**/METADATA", 15 | "**/OWNERS", 16 | ], 17 | ), 18 | ) 19 | 20 | cc_library( 21 | name = "test_util", 22 | testonly = 1, 23 | srcs = ["test_util.cc"], 24 | hdrs = ["test_util.h"], 25 | deps = [ 26 | "@com_google_googletest//:gtest", 27 | "@com_google_protobuf//:protobuf", 28 | "@org_tensorflow//tensorflow/core", 29 | "@org_tensorflow//tensorflow/core:lib", 30 | "@org_tensorflow//tensorflow/core:test", 31 | ], 32 | ) 33 | -------------------------------------------------------------------------------- /tensorflow_serving/test_util/test_util.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | 18 | #include "tensorflow_serving/test_util/test_util.h" 19 | 20 | #include "tensorflow/core/lib/io/path.h" 21 | #include "tensorflow/core/platform/env.h" 22 | #include "tensorflow/core/platform/test.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | namespace test_util { 27 | 28 | string TensorflowTestSrcDirPath(const string& relative_path) { 29 | const string base_path = tensorflow::io::JoinPath( // 30 | getenv("TEST_SRCDIR"), // 31 | "tf_serving/external/org_tensorflow/tensorflow/"); 32 | return tensorflow::io::JoinPath(base_path, relative_path); 33 | } 34 | 35 | string TestSrcDirPath(const string& relative_path) { 36 | const string base_path = tensorflow::io::JoinPath( 37 | getenv("TEST_SRCDIR"), "tf_serving/tensorflow_serving"); 38 | return tensorflow::io::JoinPath(base_path, relative_path); 39 | } 40 | 41 | string GetCWD() { 42 | return get_current_dir_name(); 43 | } 44 | 45 | ProtoStringMatcher::ProtoStringMatcher(const string& expected) 46 | : expected_(expected) {} 47 | ProtoStringMatcher::ProtoStringMatcher(const google::protobuf::Message& expected) 48 | : expected_(expected.DebugString()) {} 49 | 50 | } // namespace test_util 51 | } // namespace serving 52 | } // namespace tensorflow 53 | -------------------------------------------------------------------------------- /tensorflow_serving/tools/docker/README.md: -------------------------------------------------------------------------------- 1 | Files for using the [Docker](http://www.docker.com) container system. 2 | Please see [Docker instructions](https://github.com/tensorflow/serving/blob/master/tensorflow_serving/g3doc/docker.md) 3 | for more info. 4 | -------------------------------------------------------------------------------- /tensorflow_serving/tools/docker/tests/dockerfile_mkl_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2018 Google Inc. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | # 17 | # Tests if a Docker image built from Dockerfile basically functions. 18 | # 19 | # It does this by loading up a half plus two toy model in the Docker image 20 | # and querying it, validating the response. 21 | # 22 | # The image passed to this test must be already available locally. 23 | # 24 | # Ex: $ bazel test :unittest_dockerfile_mkl --test_arg=tensorflow/serving:latest-mkl \ 25 | # --test_output=streamed --verbose_failures 26 | 27 | declare -r PROJDIR=$(pwd)/tensorflow_serving 28 | source ${PROJDIR}/tools/docker/tests/docker_test_lib.sh || exit 1 29 | 30 | # Values to fill in for test 31 | # ------------------------------------------------------------------------------ 32 | declare -r USE_NVIDIA_RUNTIME=false 33 | declare -r IS_MKL_IMAGE=true 34 | declare -r IS_DEVEL_IMAGE=false 35 | declare -r MODELDIR="${PROJDIR}/servables/tensorflow/testdata" 36 | declare -r MODELNAME="saved_model_half_plus_two_mkl" 37 | declare -r REQUEST='{"instances": [1.0,2.0,5.0]}' 38 | declare -r RESPONSE='{"predictions":[2.5,3.0,4.5]}' 39 | # ------------------------------------------------------------------------------ 40 | 41 | # Grab the last argument as the image, so we can override the test arg in 42 | # the BUILD file 43 | test_docker_image ${@: -1} 44 | -------------------------------------------------------------------------------- /tensorflow_serving/tools/docker/tests/dockerfile_test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2018 Google Inc. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | # 17 | # Tests if a Docker image built from Dockerfile basically functions. 18 | # 19 | # It does this by loading up a half plus two toy model in the Docker image 20 | # and querying it, validating the response. 21 | # 22 | # The image passed to this test must be already available locally. 23 | # 24 | # Ex: $ bazel test :unittest_Dockerfile --test_arg=tensorflow/serving \ 25 | # --test_output=streamed --verbose_failures 26 | 27 | declare -r PROJDIR=$(pwd)/tensorflow_serving 28 | source ${PROJDIR}/tools/docker/tests/docker_test_lib.sh || exit 1 29 | 30 | # Values to fill in for test 31 | # ------------------------------------------------------------------------------ 32 | declare -r USE_NVIDIA_RUNTIME=false 33 | declare -r IS_MKL_IMAGE=false 34 | declare -r IS_DEVEL_IMAGE=false 35 | declare -r MODELDIR="${PROJDIR}/servables/tensorflow/testdata" 36 | declare -r MODELNAME="saved_model_half_plus_two_cpu" 37 | declare -r REQUEST='{"instances": [1.0,2.0,5.0]}' 38 | declare -r RESPONSE='{"predictions":[2.5,3.0,4.5]}' 39 | # ------------------------------------------------------------------------------ 40 | 41 | # Grab the last argument as the image, so we can override the test arg in 42 | # the BUILD file 43 | test_docker_image ${@: -1} 44 | -------------------------------------------------------------------------------- /tensorflow_serving/tools/pip_package/BUILD: -------------------------------------------------------------------------------- 1 | # Description: Tensorflow Serving pip package. 2 | 3 | licenses(["notice"]) # Apache 2.0 4 | 5 | sh_binary( 6 | name = "build_pip_package", 7 | srcs = ["build_pip_package.sh"], 8 | data = [ 9 | "setup.py", 10 | 11 | # Python scripts needed for the Python TF Serving API 12 | "//tensorflow_serving/apis:get_model_status_proto_py_pb2", 13 | "//tensorflow_serving/apis:model_management_proto_py_pb2", 14 | "//tensorflow_serving/apis:model_proto_py_pb2", 15 | "//tensorflow_serving/apis:model_service_proto_py_pb2", 16 | "//tensorflow_serving/apis:prediction_log_proto_py_pb2", 17 | "//tensorflow_serving/apis:prediction_service_proto_py_pb2", 18 | "//tensorflow_serving/apis:predict_proto_py_pb2", 19 | "//tensorflow_serving/config:log_collector_config_proto_py_pb2", 20 | "//tensorflow_serving/config:logging_config_proto_py_pb2", 21 | "//tensorflow_serving/config:model_server_config_proto_py_pb2", 22 | "//tensorflow_serving/sources/storage_path:file_system_storage_path_source_proto_py_pb2", 23 | "//tensorflow_serving/util:status_proto_py_pb2", 24 | "//tensorflow_serving/core:logging_proto_py_pb2", 25 | ], 26 | ) 27 | -------------------------------------------------------------------------------- /tensorflow_serving/util/class_registration_test.proto: -------------------------------------------------------------------------------- 1 | // Proto messages used by class_registration_test.cc. 2 | 3 | syntax = "proto3"; 4 | 5 | import "google/protobuf/any.proto"; 6 | 7 | package tensorflow.serving; 8 | 9 | message Config1 { 10 | string string_field = 1; 11 | } 12 | 13 | message Config2 { 14 | string string_field = 1; 15 | } 16 | 17 | message MessageWithAny { 18 | google.protobuf.Any any_field = 1; 19 | } 20 | -------------------------------------------------------------------------------- /tensorflow_serving/util/class_registration_util.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/class_registration_util.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | Status ParseUrlForAnyType(const string& type_url, 22 | string* const full_type_name) { 23 | std::vector splits = str_util::Split(type_url, '/'); 24 | if (splits.size() < 2 || splits[splits.size() - 1].empty()) { 25 | return errors::InvalidArgument( 26 | "Supplied config's type_url could not be parsed: ", type_url); 27 | } 28 | *full_type_name = splits[splits.size() - 1]; 29 | return Status::OK(); 30 | } 31 | 32 | } // namespace serving 33 | } // namespace tensorflow 34 | -------------------------------------------------------------------------------- /tensorflow_serving/util/class_registration_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_CLASS_REGISTRATION_UTIL_H_ 17 | #define TENSORFLOW_SERVING_UTIL_CLASS_REGISTRATION_UTIL_H_ 18 | 19 | #include "tensorflow/core/lib/core/errors.h" 20 | #include "tensorflow/core/lib/core/status.h" 21 | #include "tensorflow/core/lib/strings/str_util.h" 22 | 23 | namespace tensorflow { 24 | namespace serving { 25 | 26 | // Parses a url whose final '/' is followed by a proto type name, e.g. 27 | // "type.googleapis.com/some_namespace.some_proto_type_name". 28 | // Returns Status::OK() iff parsing succeeded. 29 | Status ParseUrlForAnyType(const string& type_url, string* const full_type_name); 30 | 31 | } // namespace serving 32 | } // namespace tensorflow 33 | 34 | #endif // TENSORFLOW_SERVING_UTIL_CLASS_REGISTRATION_UTIL_H_ 35 | -------------------------------------------------------------------------------- /tensorflow_serving/util/executor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_EXECUTOR_H_ 17 | #define TENSORFLOW_SERVING_UTIL_EXECUTOR_H_ 18 | 19 | #include 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | 24 | /// An abstract object that can execute closures. 25 | /// 26 | /// Implementations of executor must be thread-safe. 27 | class Executor { 28 | public: 29 | virtual ~Executor() = default; 30 | 31 | /// Schedule the specified 'fn' for execution in this executor. Depending on 32 | /// the subclass implementation, this may block in some situations. 33 | virtual void Schedule(std::function fn) = 0; 34 | }; 35 | 36 | } // namespace serving 37 | } // namespace tensorflow 38 | 39 | #endif // TENSORFLOW_SERVING_UTIL_EXECUTOR_H_ 40 | -------------------------------------------------------------------------------- /tensorflow_serving/util/file_probing_env.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/file_probing_env.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | Status TensorflowFileProbingEnv::FileExists(const string& fname) { 22 | return env_->FileExists(fname); 23 | } 24 | 25 | Status TensorflowFileProbingEnv::GetChildren(const string& dir, 26 | std::vector* children) { 27 | return env_->GetChildren(dir, children); 28 | } 29 | 30 | Status TensorflowFileProbingEnv::IsDirectory(const string& fname) { 31 | return env_->IsDirectory(fname); 32 | } 33 | 34 | Status TensorflowFileProbingEnv::GetFileSize(const string& fname, 35 | uint64* file_size) { 36 | return env_->GetFileSize(fname, file_size); 37 | } 38 | 39 | } // namespace serving 40 | } // namespace tensorflow 41 | -------------------------------------------------------------------------------- /tensorflow_serving/util/hash.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/hash.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | uint64 HashCombine(const uint64 hash1, const uint64 hash2) { 22 | return hash1 ^ (hash2 + 0x9e3779b97f4a7800 + (hash1 << 10) + (hash1 >> 4)); 23 | } 24 | 25 | } // namespace serving 26 | } // namespace tensorflow 27 | -------------------------------------------------------------------------------- /tensorflow_serving/util/hash.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_HASH_H_ 17 | #define TENSORFLOW_SERVING_UTIL_HASH_H_ 18 | 19 | #include "tensorflow/core/platform/types.h" 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | 24 | // Combines 2 hashes and returns a 3rd one. 25 | uint64 HashCombine(uint64 hash1, uint64 hash2); 26 | 27 | } // namespace serving 28 | } // namespace tensorflow 29 | 30 | #endif // TENSORFLOW_SERVING_UTIL_HASH_H_ 31 | -------------------------------------------------------------------------------- /tensorflow_serving/util/inline_executor.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/inline_executor.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | InlineExecutor::InlineExecutor() {} 22 | 23 | InlineExecutor::~InlineExecutor() {} 24 | 25 | void InlineExecutor::Schedule(std::function fn) { fn(); } 26 | 27 | } // namespace serving 28 | } // namespace tensorflow 29 | -------------------------------------------------------------------------------- /tensorflow_serving/util/inline_executor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_INLINE_EXECUTOR_H_ 17 | #define TENSORFLOW_SERVING_UTIL_INLINE_EXECUTOR_H_ 18 | 19 | #include 20 | 21 | #include "tensorflow/core/platform/macros.h" 22 | #include "tensorflow_serving/util/executor.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | 27 | // An InlineExecutor is a trivial executor that immediately executes the closure 28 | // given to it. It's useful as a fake, and in cases where an executor is needed, 29 | // but multi-threadedness is not. 30 | class InlineExecutor : public Executor { 31 | public: 32 | InlineExecutor(); 33 | ~InlineExecutor() override; 34 | void Schedule(std::function fn) override; 35 | }; 36 | 37 | } // namespace serving 38 | } // namespace tensorflow 39 | 40 | #endif // TENSORFLOW_SERVING_UTIL_INLINE_EXECUTOR_H_ 41 | -------------------------------------------------------------------------------- /tensorflow_serving/util/inline_executor_test.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/inline_executor.h" 17 | 18 | #include 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | namespace { 23 | 24 | TEST(InlineExecutorTest, Executes) { 25 | InlineExecutor inline_executor; 26 | 27 | int total_calls = 0; 28 | inline_executor.Schedule([&]() { ++total_calls; }); 29 | EXPECT_EQ(1, total_calls); 30 | } 31 | 32 | } // namespace 33 | } // namespace serving 34 | } // namespace tensorflow 35 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/README.md: -------------------------------------------------------------------------------- 1 | A (truly) lightweight OSS HTTP Server 2 | ===================================== 3 | 4 | Design and implementation started in April 2018, within the TF serving code base. 5 | 6 | APIs are subject to change. 7 | 8 | Questions? 9 | ---------- 10 | 11 | If you have any questions, please send them to [web|awk]@google.com 12 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/client/BUILD: -------------------------------------------------------------------------------- 1 | # Description: a lightweight http client 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving/util/net_http:__subpackages__", 6 | ], 7 | ) 8 | 9 | licenses(["notice"]) # Apache 2.0 10 | 11 | cc_library( 12 | name = "evhttp_client", 13 | srcs = [ 14 | "evhttp_connection.cc", 15 | ], 16 | hdrs = [ 17 | "evhttp_connection.h", 18 | ], 19 | deps = [ 20 | "//tensorflow_serving/util/net_http/internal:net_logging", 21 | "//tensorflow_serving/util/net_http/server/public:http_server_api", 22 | "@com_github_libevent_libevent//:libevent", 23 | "@com_google_absl//absl/base", 24 | "@com_google_absl//absl/strings", 25 | "@com_google_absl//absl/synchronization", 26 | ], 27 | ) 28 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/client/README.md: -------------------------------------------------------------------------------- 1 | The client library is still under development, and currently used for writing tests. 2 | 3 | The API specs are yet to be finalized. -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/client/testing/BUILD: -------------------------------------------------------------------------------- 1 | # Description: net_http/client/testing 2 | 3 | package( 4 | default_visibility = ["//visibility:private"], 5 | ) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | cc_binary( 10 | name = "evhttp_echo_client", 11 | srcs = ["evhttp_echo_client.cc"], 12 | deps = [ 13 | "//tensorflow_serving/util/net_http/client:evhttp_client", 14 | ], 15 | ) 16 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/compression/BUILD: -------------------------------------------------------------------------------- 1 | # Description: compression support libraries 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | "//tensorflow_serving/util/net_http:__subpackages__", 7 | ], 8 | ) 9 | 10 | licenses(["notice"]) # Apache 2.0 11 | 12 | # C++ lib based on zlib for gzip support 13 | cc_library( 14 | name = "gzip_zlib", 15 | srcs = [ 16 | "gzip_zlib.cc", 17 | ], 18 | hdrs = [ 19 | "gzip_zlib.h", 20 | ], 21 | deps = [ 22 | "//tensorflow_serving/util/net_http/internal:net_logging", 23 | "@com_google_absl//absl/base", 24 | "@com_google_absl//absl/base:core_headers", 25 | "@com_google_absl//absl/strings", 26 | "@zlib_archive//:zlib", 27 | ], 28 | ) 29 | 30 | # cc_test( 31 | # name = "gzip_zlib_test", 32 | # size = "large", 33 | # srcs = ["gzip_zlib_test.cc"], 34 | # features = ["-layering_check"], 35 | # deps = [ 36 | # ":gzip_zlib", 37 | # "//tensorflow_serving/core/test_util:test_main", 38 | # ], 39 | # ) 40 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/compression/README.md: -------------------------------------------------------------------------------- 1 | Compression support 2 | =================== 3 | 4 | This package provides C++ wrappers for compression libraries such as gzip, br. 5 | 6 | APIs are subject to change but usage outside net_http is expected. 7 | 8 | gzip_zlib.h 9 | --------------------- 10 | 11 | Minimum APIs and implementation to support gzip Content-Encoding via zlib. 12 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/internal/BUILD: -------------------------------------------------------------------------------- 1 | # Description: shared code for net_http 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving/util/net_http:__subpackages__", 6 | ], 7 | ) 8 | 9 | licenses(["notice"]) # Apache 2.0 10 | 11 | cc_library( 12 | name = "fixed_thread_pool", 13 | testonly = 1, 14 | hdrs = ["fixed_thread_pool.h"], 15 | deps = [ 16 | "@com_google_absl//absl/base:core_headers", 17 | "@com_google_absl//absl/synchronization", 18 | ], 19 | ) 20 | 21 | cc_library( 22 | name = "net_logging", 23 | srcs = ["net_logging.cc"], 24 | hdrs = ["net_logging.h"], 25 | deps = [ 26 | "@com_google_absl//absl/base:config", 27 | "@com_google_absl//absl/base:core_headers", 28 | "@com_google_absl//absl/base:log_severity", 29 | ], 30 | ) 31 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/internal/testing/BUILD: -------------------------------------------------------------------------------- 1 | # Description: net_http/internal/testing 2 | 3 | package( 4 | default_visibility = ["//visibility:private"], 5 | ) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | cc_binary( 10 | name = "net_logging_example", 11 | srcs = ["net_logging_example.cc"], 12 | deps = [ 13 | "//tensorflow_serving/util/net_http/internal:net_logging", 14 | ], 15 | ) 16 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/internal/testing/net_logging_example.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include 17 | #include 18 | 19 | #include "tensorflow_serving/util/net_http/internal/net_logging.h" 20 | 21 | int main(int argc, char** argv) { 22 | NET_LOG(INFO, "started!"); 23 | 24 | size_t size = 100; 25 | NET_LOG(ERROR, "read less than specified bytes : %zu", size); 26 | 27 | const char* url = "/url"; 28 | NET_LOG(WARNING, "%s: read less than specified bytes : %zu", url, size); 29 | 30 | NET_LOG(FATAL, "aborted!"); 31 | 32 | return 0; // unexpected 33 | } 34 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/server/public/BUILD: -------------------------------------------------------------------------------- 1 | # Description: a lightweight http server and related utils to support Web clients 2 | 3 | package( 4 | default_visibility = [ 5 | ":http_server_clients", 6 | "//tensorflow_serving:internal", 7 | "//tensorflow_serving/util/net_http:__subpackages__", 8 | ], 9 | ) 10 | 11 | package_group(name = "http_server_clients") 12 | 13 | licenses(["notice"]) # Apache 2.0 14 | 15 | cc_library( 16 | name = "http_server_api", 17 | srcs = [ 18 | "header_names.cc", 19 | ], 20 | hdrs = [ 21 | "header_names.h", 22 | "httpserver_interface.h", 23 | "response_code_enum.h", 24 | "server_request_interface.h", 25 | ], 26 | deps = [ 27 | "@com_google_absl//absl/strings", 28 | "@com_google_absl//absl/time", 29 | ], 30 | ) 31 | 32 | cc_library( 33 | name = "http_server", 34 | hdrs = [ 35 | "httpserver.h", 36 | ], 37 | deps = [ 38 | ":http_server_api", 39 | "//tensorflow_serving/util/net_http/server/internal:evhttp_server", 40 | "@com_google_absl//absl/memory", 41 | ], 42 | ) 43 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/server/public/httpserver.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // The entry point to access different HTTP server implementations. 17 | 18 | #ifndef TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ 19 | #define TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ 20 | 21 | #include 22 | 23 | #include "absl/memory/memory.h" 24 | 25 | #include "tensorflow_serving/util/net_http/server/internal/evhttp_server.h" 26 | #include "tensorflow_serving/util/net_http/server/public/httpserver_interface.h" 27 | 28 | namespace tensorflow { 29 | namespace serving { 30 | namespace net_http { 31 | 32 | // Creates a server implemented based on the libevents library. 33 | // Returns nullptr if there is any error. 34 | // 35 | // Must call WaitForTermination() or WaitForTerminationWithTimeout() before 36 | // the server is to be destructed. 37 | inline std::unique_ptr CreateEvHTTPServer( 38 | std::unique_ptr options) { 39 | auto server = absl::make_unique(std::move(options)); 40 | bool result = server->Initialize(); 41 | if (!result) { 42 | return nullptr; 43 | } 44 | 45 | return std::move(server); 46 | } 47 | 48 | } // namespace net_http 49 | } // namespace serving 50 | } // namespace tensorflow 51 | 52 | #endif // TENSORFLOW_SERVING_UTIL_NET_HTTP_SERVER_PUBLIC_HTTPSERVER_H_ 53 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/server/testing/BUILD: -------------------------------------------------------------------------------- 1 | # Description: net_http/server/testing 2 | 3 | package( 4 | default_visibility = ["//visibility:private"], 5 | ) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | cc_binary( 10 | name = "evhttp_echo_server", 11 | srcs = ["evhttp_echo_server.cc"], 12 | deps = [ 13 | "//tensorflow_serving/util/net_http/server/public:http_server", 14 | "//tensorflow_serving/util/net_http/server/public:http_server_api", 15 | "@com_google_absl//absl/memory", 16 | "@com_google_absl//absl/strings", 17 | ], 18 | ) 19 | -------------------------------------------------------------------------------- /tensorflow_serving/util/net_http/socket/testing/BUILD: -------------------------------------------------------------------------------- 1 | # Description: net_http/socket testing utils 2 | 3 | package( 4 | default_visibility = ["//visibility:private"], 5 | ) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | cc_binary( 10 | name = "ev_print_req_server", 11 | srcs = ["ev_print_req_server.cc"], 12 | deps = [ 13 | "@com_github_libevent_libevent//:libevent", 14 | "@com_google_absl//absl/strings", 15 | ], 16 | ) 17 | 18 | cc_binary( 19 | name = "ev_fetch_client", 20 | srcs = ["ev_fetch_client.cc"], 21 | deps = [ 22 | "@com_github_libevent_libevent//:libevent", 23 | ], 24 | ) 25 | -------------------------------------------------------------------------------- /tensorflow_serving/util/optional.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/optional.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | extern const in_place_t in_place{}; 22 | extern const nullopt_t nullopt{{}}; 23 | 24 | } // namespace serving 25 | } // namespace tensorflow 26 | -------------------------------------------------------------------------------- /tensorflow_serving/util/oss_or_google.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2019 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_SERVING_UTIL_OSS_OR_GOOGLE_H_ 16 | #define TENSORFLOW_SERVING_UTIL_OSS_OR_GOOGLE_H_ 17 | 18 | #define TENSORFLOW_SERVING_OSS 19 | 20 | namespace tensorflow { 21 | namespace serving { 22 | 23 | // Used to distinguish the context of the code; whether it's part of our OSS 24 | // distribution or within Google. 25 | // 26 | // This is useful in cases where we want to enable/disable running some piece of 27 | // code based on whether we are in/out of OSS. 28 | // 29 | // NB that the method is marked 'constexpr' so that the value can be used as 30 | // a compile-time constant. 31 | inline constexpr bool IsTensorflowServingOSS() { 32 | #ifdef TENSORFLOW_SERVING_GOOGLE 33 | return false; 34 | #else 35 | return true; 36 | #endif 37 | } 38 | 39 | } // namespace serving 40 | } // namespace tensorflow 41 | 42 | #endif // TENSORFLOW_SERVING_UTIL_OSS_OR_GOOGLE_H_ 43 | -------------------------------------------------------------------------------- /tensorflow_serving/util/prometheus_exporter.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_PROMETHEUS_EXPORTER_H_ 17 | #define TENSORFLOW_SERVING_UTIL_PROMETHEUS_EXPORTER_H_ 18 | 19 | #include 20 | 21 | #include "tensorflow/core/lib/core/status.h" 22 | #include "tensorflow/core/lib/monitoring/collected_metrics.h" 23 | #include "tensorflow/core/lib/monitoring/collection_registry.h" 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | 28 | // Exports metrics in Prometheus monitoring format. 29 | class PrometheusExporter { 30 | public: 31 | // Default path to expose the metrics. 32 | static const char* const kPrometheusPath; 33 | 34 | PrometheusExporter(); 35 | 36 | // Generates text page in Prometheus format: 37 | // https://prometheus.io/docs/instrumenting/exposition_formats/#text-format-example 38 | // If an error status returned, http_page is unchanged. 39 | Status GeneratePage(string* http_page); 40 | 41 | private: 42 | // The metrics registry. 43 | monitoring::CollectionRegistry* collection_registry_; 44 | }; 45 | 46 | } // namespace serving 47 | } // namespace tensorflow 48 | 49 | #endif // TENSORFLOW_SERVING_UTIL_PROMETHEUS_EXPORTER_H_ 50 | -------------------------------------------------------------------------------- /tensorflow_serving/util/retrier.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/retrier.h" 17 | 18 | #include "tensorflow/core/platform/env.h" 19 | #include "tensorflow/core/platform/logging.h" 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | 24 | Status Retry(const string& description, const uint32 max_num_retries, 25 | const int64 retry_interval_micros, 26 | const std::function& retried_fn, 27 | const std::function& is_cancelled) { 28 | Status status; 29 | int num_tries = 0; 30 | do { 31 | if (num_tries > 0) { 32 | Env::Default()->SleepForMicroseconds(retry_interval_micros); 33 | LOG(INFO) << "Retrying of " << description << " retry: " << num_tries; 34 | } 35 | status = retried_fn(); 36 | if (!status.ok()) { 37 | LOG(ERROR) << description << " failed: " << status; 38 | } 39 | ++num_tries; 40 | } while (!is_cancelled() && !status.ok() && num_tries < max_num_retries + 1); 41 | 42 | if (is_cancelled()) { 43 | LOG(INFO) << "Retrying of " << description << " was cancelled."; 44 | } 45 | if (num_tries == max_num_retries + 1) { 46 | LOG(INFO) << "Retrying of " << description 47 | << " exhausted max_num_retries: " << max_num_retries; 48 | } 49 | return status; 50 | } 51 | 52 | } // namespace serving 53 | } // namespace tensorflow 54 | -------------------------------------------------------------------------------- /tensorflow_serving/util/retrier.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2017 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_RETRIER_H_ 17 | #define TENSORFLOW_SERVING_UTIL_RETRIER_H_ 18 | 19 | #include 20 | #include 21 | 22 | #include "tensorflow/core/lib/core/status.h" 23 | 24 | namespace tensorflow { 25 | namespace serving { 26 | 27 | // Tries running 'retried_fn' once, and if it doesn't succeed, retries running 28 | // the 'retried_fn' till it returns an ok status or max_num_retries are 29 | // exhausted or cancelled() returns true. Each retry is attempted after an 30 | // interval of 'retry_interval_micros'. The 'description' is useful for logging. 31 | // 32 | // Returns the status returned by the last call to 'retried_fn'. 33 | Status Retry(const string& description, uint32 max_num_retries, 34 | int64 retry_interval_micros, 35 | const std::function& retried_fn, 36 | const std::function& is_cancelled = [] { return false; }); 37 | 38 | } // namespace serving 39 | } // namespace tensorflow 40 | 41 | #endif // TENSORFLOW_SERVING_UTIL_RETRIER_H_ 42 | -------------------------------------------------------------------------------- /tensorflow_serving/util/status.proto: -------------------------------------------------------------------------------- 1 | syntax = "proto3"; 2 | 3 | option cc_enable_arenas = true; 4 | 5 | import "tensorflow/core/lib/core/error_codes.proto"; 6 | 7 | package tensorflow.serving; 8 | 9 | // Status that corresponds to Status in 10 | // third_party/tensorflow/core/lib/core/status.h. 11 | message StatusProto { 12 | // Error code. 13 | error.Code error_code = 1 [json_name = "error_code"]; 14 | 15 | // Error message. Will only be set if an error was encountered. 16 | string error_message = 2 [json_name = "error_message"]; 17 | } 18 | -------------------------------------------------------------------------------- /tensorflow_serving/util/status_util.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/status_util.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | StatusProto ToStatusProto(const Status& status) { 22 | StatusProto status_proto; 23 | status_proto.set_error_code(status.code()); 24 | if (!status.ok()) { 25 | status_proto.set_error_message(status.error_message()); 26 | } 27 | return status_proto; 28 | } 29 | 30 | Status FromStatusProto(const StatusProto& status_proto) { 31 | return status_proto.error_code() == tensorflow::error::OK 32 | ? Status() 33 | : Status(status_proto.error_code(), status_proto.error_message()); 34 | } 35 | 36 | } // namespace serving 37 | } // namespace tensorflow 38 | -------------------------------------------------------------------------------- /tensorflow_serving/util/status_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2018 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | #ifndef TENSORFLOW_SERVING_UTIL_STATUS_UTIL_H_ 16 | #define TENSORFLOW_SERVING_UTIL_STATUS_UTIL_H_ 17 | 18 | #include "tensorflow/core/lib/core/status.h" 19 | #include "tensorflow_serving/util/status.pb.h" 20 | 21 | namespace tensorflow { 22 | namespace serving { 23 | 24 | // Converts from tensorflow Status to StatusProto. 25 | StatusProto ToStatusProto(const Status& status); 26 | 27 | // Converts from StatusProto to tensorflow Status. 28 | Status FromStatusProto(const StatusProto& status_proto); 29 | 30 | } // namespace serving 31 | } // namespace tensorflow 32 | 33 | #endif // TENSORFLOW_SERVING_UTIL_STATUS_UTIL_H_ 34 | -------------------------------------------------------------------------------- /tensorflow_serving/util/strings/BUILD: -------------------------------------------------------------------------------- 1 | # Description: string utils. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = ["-layering_check"], 8 | ) 9 | 10 | licenses(["notice"]) # Apache 2.0 11 | 12 | filegroup( 13 | name = "all_files", 14 | srcs = glob( 15 | ["**/*"], 16 | exclude = [ 17 | "**/METADATA", 18 | "**/OWNERS", 19 | "**/google_*", 20 | ], 21 | ), 22 | ) 23 | 24 | cc_library( 25 | name = "numeric", 26 | srcs = ["numeric.cc"], 27 | hdrs = ["numeric.h"], 28 | ) 29 | 30 | cc_library( 31 | name = "string_piece", 32 | srcs = ["string_piece.cc"], 33 | hdrs = ["string_piece.h"], 34 | ) 35 | 36 | cc_library( 37 | name = "split", 38 | srcs = ["split.cc"], 39 | hdrs = ["split.h"], 40 | deps = [ 41 | ":string_piece", 42 | ], 43 | ) 44 | -------------------------------------------------------------------------------- /tensorflow_serving/util/strings/numeric.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | // Author: Gaidong Mou (mougaidong@qiyi.com) 17 | // Author: Hao Ziyu 18 | // This class contains utility functions for processing numeric strings. 19 | 20 | #ifndef STRINGS_NUMERIC_H_ 21 | #define STRINGS_NUMERIC_H_ 22 | 23 | #include 24 | 25 | // Checks whether 'str' is a decimal digit string, return true if so. 26 | bool IsDigitalString(const std::string &str); 27 | 28 | // Convert numeric string 'str' to integer, result stored in 'out'. 29 | // Return true if converted successfully, otherwise false. 30 | bool safe_strtol(const char *str, int32_t *out); 31 | bool safe_strtol(const std::string &str, int32_t *out); 32 | 33 | bool safe_strtoul(const char *str, uint32_t *out); 34 | bool safe_strtoul(const std::string &str, uint32_t *out); 35 | 36 | bool safe_strtoll(const char *str, int64_t *out); 37 | bool safe_strtoll(const std::string &str, int64_t *out); 38 | 39 | bool safe_strtoull(const char *str, uint64_t *out); 40 | bool safe_strtoull(const std::string &str, uint64_t *out); 41 | 42 | // For floating point number. 43 | bool safe_strtof(const char *str, float *out); 44 | bool safe_strtof(const std::string &str, float *out); 45 | bool safe_strtod(const char *str, double *out); 46 | bool safe_strtod(const std::string &str, double *out); 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /tensorflow_serving/util/tensorflow/BUILD: -------------------------------------------------------------------------------- 1 | # Description: tensorflow utils. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = ["-layering_check"], 8 | ) 9 | 10 | licenses(["notice"]) # Apache 2.0 11 | 12 | filegroup( 13 | name = "all_files", 14 | srcs = glob( 15 | ["**/*"], 16 | exclude = [ 17 | "**/METADATA", 18 | "**/OWNERS", 19 | "**/google_*", 20 | ], 21 | ), 22 | ) 23 | 24 | cc_library( 25 | name = "fake_clock_env", 26 | testonly = 1, 27 | srcs = ["fake_clock_env.cc"], 28 | hdrs = ["fake_clock_env.h"], 29 | deps = [ 30 | "@org_tensorflow//tensorflow/core:lib", 31 | ], 32 | ) 33 | 34 | cc_library( 35 | name = "periodic_function_dynamic", 36 | srcs = ["periodic_function.cc"], 37 | hdrs = ["periodic_function.h"], 38 | deps = [ 39 | # "@org_tensorflow//tensorflow/core:lib", 40 | "@org_tensorflow//tensorflow/core:framework_headers_lib", 41 | "@org_tensorflow//tensorflow/core:protos_all_cc", 42 | ], 43 | ) 44 | 45 | -------------------------------------------------------------------------------- /tensorflow_serving/util/test_util/BUILD: -------------------------------------------------------------------------------- 1 | # Description: testing utils for Tensorflow Serving utils. 2 | 3 | package( 4 | default_visibility = [ 5 | "//tensorflow_serving:internal", 6 | ], 7 | features = ["-layering_check"], 8 | ) 9 | 10 | licenses(["notice"]) # Apache 2.0 11 | 12 | cc_library( 13 | name = "mock_file_probing_env", 14 | testonly = 1, 15 | hdrs = ["mock_file_probing_env.h"], 16 | deps = [ 17 | "//tensorflow_serving/util:file_probing_env", 18 | "@com_google_googletest//:gtest", 19 | "@org_tensorflow//tensorflow/core:lib", 20 | ], 21 | ) 22 | -------------------------------------------------------------------------------- /tensorflow_serving/util/test_util/mock_file_probing_env.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_TEST_UTIL_MOCK_FILE_PROBING_ENV_H_ 17 | #define TENSORFLOW_SERVING_UTIL_TEST_UTIL_MOCK_FILE_PROBING_ENV_H_ 18 | 19 | #include 20 | #include "tensorflow/core/lib/core/status.h" 21 | #include "tensorflow_serving/util/file_probing_env.h" 22 | 23 | namespace tensorflow { 24 | namespace serving { 25 | namespace test_util { 26 | 27 | class MockFileProbingEnv : public FileProbingEnv { 28 | public: 29 | MOCK_METHOD1(FileExists, Status(const string& fname)); 30 | MOCK_METHOD2(GetChildren, 31 | Status(const string& fname, std::vector* children)); 32 | MOCK_METHOD1(IsDirectory, Status(const string& fname)); 33 | MOCK_METHOD2(GetFileSize, Status(const string& fname, uint64* file_size)); 34 | }; 35 | 36 | } // namespace test_util 37 | } // namespace serving 38 | } // namespace tensorflow 39 | 40 | #endif // TENSORFLOW_SERVING_UTIL_TEST_UTIL_MOCK_FILE_PROBING_ENV_H_ 41 | -------------------------------------------------------------------------------- /tensorflow_serving/util/threadpool_executor.cc: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #include "tensorflow_serving/util/threadpool_executor.h" 17 | 18 | namespace tensorflow { 19 | namespace serving { 20 | 21 | ThreadPoolExecutor::ThreadPoolExecutor(Env* const env, const string& name, 22 | int num_threads) 23 | : thread_pool_(env, name, num_threads) {} 24 | 25 | ThreadPoolExecutor::~ThreadPoolExecutor() {} 26 | 27 | void ThreadPoolExecutor::Schedule(std::function fn) { 28 | thread_pool_.Schedule(fn); 29 | } 30 | 31 | } // namespace serving 32 | } // namespace tensorflow 33 | -------------------------------------------------------------------------------- /tensorflow_serving/util/threadpool_executor.h: -------------------------------------------------------------------------------- 1 | /* Copyright 2016 Google Inc. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | ==============================================================================*/ 15 | 16 | #ifndef TENSORFLOW_SERVING_UTIL_THREADPOOL_EXECUTOR_H_ 17 | #define TENSORFLOW_SERVING_UTIL_THREADPOOL_EXECUTOR_H_ 18 | 19 | #include 20 | 21 | #include "tensorflow/core/lib/core/threadpool.h" 22 | #include "tensorflow/core/platform/env.h" 23 | #include "tensorflow_serving/util/executor.h" 24 | 25 | namespace tensorflow { 26 | namespace serving { 27 | 28 | // An executor which uses a pool of threads to execute the scheduled closures. 29 | class ThreadPoolExecutor : public Executor { 30 | public: 31 | // Constructs a threadpool that has 'num_threads' threads with specified 32 | // 'thread_pool_name'. Env is used to start the thread. 33 | // 34 | // REQUIRES: num_threads > 0. 35 | ThreadPoolExecutor(Env* env, const string& thread_pool_name, int num_threads); 36 | 37 | // Waits until all scheduled work has finished and then destroy the set of 38 | // threads. 39 | ~ThreadPoolExecutor() override; 40 | 41 | void Schedule(std::function fn) override; 42 | 43 | private: 44 | thread::ThreadPool thread_pool_; 45 | 46 | TF_DISALLOW_COPY_AND_ASSIGN(ThreadPoolExecutor); 47 | }; 48 | 49 | } // namespace serving 50 | } // namespace tensorflow 51 | 52 | #endif // TENSORFLOW_SERVING_UTIL_THREADPOOL_EXECUTOR_H_ 53 | -------------------------------------------------------------------------------- /third_party/rapidjson/BUILD: -------------------------------------------------------------------------------- 1 | # RapidJSON (rapidjson.org) library. 2 | # from https://github.com/Tencent/rapidjson 3 | 4 | package( 5 | default_visibility = ["//visibility:public"], 6 | ) 7 | 8 | licenses(["notice"]) # BSD/MIT. 9 | 10 | cc_library( 11 | name = "rapidjson", 12 | hdrs = glob(["include/rapidjson/**/*.h"]), 13 | includes = ["include"], 14 | ) 15 | -------------------------------------------------------------------------------- /third_party/tf_text/BUILD: -------------------------------------------------------------------------------- 1 | # Empty BUILD so this is treated like a package. 2 | -------------------------------------------------------------------------------- /third_party/tf_text/tftext.patch: -------------------------------------------------------------------------------- 1 | --- a/tensorflow_text/tftext.bzl 2019-09-18 15:24:07.320915272 -0700 2 | +++ b/tensorflow_text/tftext.bzl 2019-09-18 15:26:52.859611294 -0700 3 | @@ -40,8 +40,7 @@ 4 | copts = [ "-pthread", "-std=c++11", ], 5 | alwayslink = 1, 6 | deps = cc_op_kernels + [ 7 | - "@local_config_tf//:libtensorflow_framework", 8 | - "@local_config_tf//:tf_header_lib", 9 | + "@org_tensorflow//tensorflow/core:tensorflow_opensource", 10 | ], 11 | ) 12 | -------------------------------------------------------------------------------- /third_party/xgboost/BUILD: -------------------------------------------------------------------------------- 1 | # Description: XGBoost BUILD File. 2 | 3 | package( 4 | default_visibility = ["//visibility:public"], 5 | ) 6 | 7 | licenses(["notice"]) # Apache 2.0 8 | 9 | filegroup( 10 | name = "all_files", 11 | srcs = glob( 12 | ["**/*"], 13 | exclude = [ 14 | "**/METADATA", 15 | "**/OWNERS", 16 | "g3doc/sitemap.md", 17 | ], 18 | ), 19 | ) 20 | 21 | include_files = [ 22 | "xgboost/include/xgboost/c_api.h", 23 | ] 24 | 25 | lib_files = [ 26 | "xgboost/lib/libxgboost.a", 27 | "xgboost/lib/libdmlc.a", 28 | ] 29 | 30 | genrule( 31 | name = "xgboost-srcs", 32 | srcs = ["@xgboost//:CMakeLists.txt"], 33 | outs = include_files + lib_files, 34 | cmd = "\n".join([ 35 | "export INSTALL_DIR=$$(pwd)/$(@D)/xgboost", 36 | "export TMP_DIR=$$(mktemp -d -t xgboost.XXXXXX)", 37 | "mkdir -p $$TMP_DIR", 38 | "cp -R $$(pwd)/external/xgboost/* $$TMP_DIR", 39 | "cd $$TMP_DIR", 40 | "mkdir -p build", 41 | "cd build", 42 | "cmake .. -DBUILD_STATIC_LIB:bool=ON", 43 | "make -j4", 44 | "mkdir -p $$INSTALL_DIR/lib", 45 | "mkdir -p $$INSTALL_DIR/include", 46 | "cp -rf ../lib/libxgboost.a $$INSTALL_DIR/lib/", 47 | "cp dmlc-core/libdmlc.a $$INSTALL_DIR/lib/", 48 | "cp -rf $$TMP_DIR/include/* $$INSTALL_DIR/include/", 49 | "rm -rf $$TMP_DIR", 50 | ]), 51 | ) 52 | 53 | cc_library( 54 | name = "xgboost", 55 | srcs = ["xgboost/lib/libxgboost.a"], 56 | hdrs = include_files, 57 | includes = ["xgboost/include"], 58 | linkopts = ["-lpthread", "-lgomp"], 59 | linkstatic = 1, 60 | ) 61 | 62 | cc_library( 63 | name = "dmlc", 64 | srcs = ["xgboost/lib/libdmlc.a"], 65 | linkstatic = 1, 66 | ) 67 | -------------------------------------------------------------------------------- /tools/gen_status_stamp.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # Copyright 2018 The TensorFlow Authors. All Rights Reserved. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | # ============================================================================== 16 | 17 | # This script will be run by the building process to generate key-value 18 | # information that represents the status of the workspace. The output should be 19 | # in the format: 20 | # 21 | # KEY1 VALUE1 22 | # KEY2 VALUE2 23 | # 24 | # If the script exits with non-zero code, it's considered as a failure 25 | # and the output will be discarded. 26 | 27 | # if we're inside a git tree 28 | if [ -d .git ] || git rev-parse --git-dir > /dev/null 2>&1; then 29 | git_rev=$(git rev-parse --short HEAD) 30 | if [[ $? != 0 ]]; 31 | then 32 | exit 1 33 | fi 34 | echo "BUILD_SCM_REVISION ${git_rev}" 35 | else 36 | echo "BUILD_SCM_REVISION no_git" 37 | fi; 38 | 39 | 40 | --------------------------------------------------------------------------------