TensorFlow Serving C++ API Documentation
saved_model_config.cc
1 /* Copyright 2023 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/session_bundle/saved_model_config.h"
17 
18 #include <string>
19 
20 #include "absl/status/statusor.h"
21 #include "tensorflow/core/platform/status.h"
22 #include "tensorflow/core/public/session_options.h"
23 #include "tensorflow_serving/servables/tensorflow/saved_model_config.pb.h"
24 #include "tensorflow_serving/servables/tensorflow/saved_model_config_util.h"
25 
26 namespace tensorflow {
27 namespace serving {
28 namespace session_bundle {
29 
30 Status MaybeLoadSavedModelConfig(const std::string& export_dir,
31  SessionOptions* session_options) {
32  absl::StatusOr<SavedModelConfig> saved_model_config =
33  LoadSavedModelConfigOrDefault(export_dir);
34  if (!saved_model_config.ok()) {
35  return saved_model_config.status();
36  }
37  if (saved_model_config->has_session_overrides()) {
38  UpdateRewriterConfig(saved_model_config->session_overrides(),
39  session_options->config.mutable_graph_options()
40  ->mutable_rewrite_options());
41  }
42 
43  return Status();
44 }
45 
46 } // namespace session_bundle
47 } // namespace serving
48 } // namespace tensorflow