TensorFlow Serving C++ API Documentation
saved_model_bundle_factory.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_TENSORFLOW_SAVED_MODEL_BUNDLE_FACTORY_H_
17 #define TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_FACTORY_H_
18 
19 #include "absl/types/optional.h"
20 #include "tensorflow/cc/saved_model/loader.h"
21 #include "tensorflow/core/kernels/batching_util/shared_batch_scheduler.h"
22 #include "tensorflow/core/lib/core/status.h"
23 #include "tensorflow/core/platform/macros.h"
24 #include "tensorflow_serving/batching/batching_session.h"
25 #include "tensorflow_serving/core/loader.h"
26 #include "tensorflow_serving/resources/resources.pb.h"
27 #include "tensorflow_serving/servables/tensorflow/session_bundle_config.pb.h"
28 
29 namespace tensorflow {
30 namespace serving {
31 
53  public:
58  static Status Create(const SessionBundleConfig& config,
59  std::unique_ptr<SavedModelBundleFactory>* factory);
60 
66  Status CreateSavedModelBundle(const string& path,
67  std::unique_ptr<SavedModelBundle>* bundle);
68 
77  const Loader::Metadata& metadata, const string& path,
78  std::unique_ptr<SavedModelBundle>* bundle);
79 
86  Status EstimateResourceRequirement(const string& path,
87  ResourceAllocation* estimate) const;
88 
89  const SessionBundleConfig& config() const { return config_; }
90  SessionBundleConfig& mutable_config() { return config_; }
91 
92  private:
93  using Batcher = SharedBatchScheduler<BatchingSessionTask>;
94 
95  SavedModelBundleFactory(const SessionBundleConfig& config,
96  std::shared_ptr<Batcher> batch_scheduler);
97 
98  Status InternalCreateSavedModelBundle(
99  const absl::optional<Loader::Metadata>& metadata, const string& path,
100  std::unique_ptr<SavedModelBundle>* bundle);
101 
102  SessionBundleConfig config_;
103 
104  // A shared batch scheduler. One queue is used for each session this factory
105  // emits. If batching is not configured, this remains null.
106  std::shared_ptr<Batcher> batch_scheduler_;
107 
108  TF_DISALLOW_COPY_AND_ASSIGN(SavedModelBundleFactory);
109 };
110 
111 } // namespace serving
112 } // namespace tensorflow
113 
114 #endif // TENSORFLOW_SERVING_SERVABLES_TENSORFLOW_SAVED_MODEL_BUNDLE_FACTORY_H_
static Status Create(const SessionBundleConfig &config, std::unique_ptr< SavedModelBundleFactory > *factory)
Status EstimateResourceRequirement(const string &path, ResourceAllocation *estimate) const
Status CreateSavedModelBundleWithMetadata(const Loader::Metadata &metadata, const string &path, std::unique_ptr< SavedModelBundle > *bundle)
Status CreateSavedModelBundle(const string &path, std::unique_ptr< SavedModelBundle > *bundle)
The metadata consists of the ServableId.
Definition: loader.h:94