xref: /aosp_15_r20/external/tensorflow/tensorflow/cc/experimental/libtf/module.h (revision b6fb3261f9314811a0f4371741dbb8839866f948)
1 /* Copyright 2021 The TensorFlow Authors. 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_CC_EXPERIMENTAL_LIBTF_MODULE_H_
16 #define TENSORFLOW_CC_EXPERIMENTAL_LIBTF_MODULE_H_
17 
18 #include "tensorflow/cc/experimental/libexport/load.h"
19 #include "tensorflow/cc/experimental/libtf/runtime/runtime.h"
20 #include "tensorflow/core/platform/statusor.h"
21 #include "tensorflow/core/protobuf/saved_object_graph.pb.h"
22 
23 namespace tf {
24 namespace libtf {
25 namespace impl {
26 
27 // The main interface for taking a serialized saved model and getting back a
28 // fully-built model.
29 //
30 // Implementation steps:
31 //
32 //   1) For each function def in the SavedModel, register it with the runtime.
33 //   2) For each object in the object graph def, build it.
34 //   3) For each variable stored in the checkpoint in the SavedModel,
35 //      restore it, and attach it to the associated variable object.
36 //   4) For each polymorphic function, associate it with the appropriate
37 //      concrete function(s).
38 //   5) For each function with captures, bind the appropriate objects as
39 //      captured inputs.
40 //   6) Take the fully-prepared objects, and build them into a hierarchy.
41 //   7) Return the prepared model.
42 
43 // Converts a SavedUserObject into its corresponding data structure.
44 // TODO(b/185579152): This method returns empty data structures currently.
45 tensorflow::StatusOr<Handle> BuildSavedUserObject(
46     tensorflow::SavedObject saved_object_proto);
47 
48 // "Build" all SavedObjects, ie convert from proto to their runtime
49 // representation, in the tf_package.
50 tensorflow::StatusOr<std::vector<Handle>> BuildObjects(
51     tensorflow::libexport::TFPackage& tf_package);
52 
53 // Convert tf_package to a program in the runtime.
54 tensorflow::StatusOr<Handle> BuildProgram(
55     runtime::Runtime runtime, tensorflow::libexport::TFPackage& tf_package);
56 
57 }  // namespace impl
58 }  // namespace libtf
59 }  // namespace tf
60 
61 #endif  // TENSORFLOW_CC_EXPERIMENTAL_LIBTF_MODULE_H_
62