TensorFlow Serving C++ API Documentation
saved_model_warmup_util.h
1 /* Copyright 2020 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 THIRD_PARTY_TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_WARMUP_UTIL_H_
17 #define THIRD_PARTY_TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_WARMUP_UTIL_H_
18 
19 #include "tensorflow/cc/saved_model/loader.h"
20 #include "tensorflow/core/protobuf/saved_model.pb.h"
21 #include "tensorflow_serving/apis/prediction_log.pb.h"
22 #include "tensorflow_serving/servables/tensorflow/session_bundle_config.pb.h"
23 
24 namespace tensorflow {
25 namespace serving {
26 namespace internal {
27 
28 struct WarmupConsts {
29  static constexpr char kRequestsFileName[] = "tf_serving_warmup_requests";
30  static constexpr int kMaxNumRecords = 1000;
31 };
32 
33 // Reads sample warmup requests from assets.extra/tf_serving_warmup_requests
34 // file (if exists) and invokes them one by one on the given saved_model,
35 // to trigger lazy initializations (such as TF optimizations, XLA compilations)
36 // at load time, and consequently improve first request latency.
37 // Warmup is skipped if no warmup file present.
38 Status RunSavedModelWarmup(
39  const ModelWarmupOptions& model_warmup_options, const string export_dir,
40  std::function<Status(PredictionLog)> warmup_request_executor);
41 
42 } // namespace internal
43 } // namespace serving
44 } // namespace tensorflow
45 
46 #endif // THIRD_PARTY_TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_WARMUP_UTIL_H_