• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1syntax = "proto3";
2
3package tensorflow;
4
5import "google/protobuf/any.proto";
6import "tensorflow/core/framework/tensor_shape.proto";
7import "tensorflow/core/framework/types.proto";
8import "tensorflow/core/framework/variable.proto";
9import "tensorflow/core/framework/versions.proto";
10import "tensorflow/core/protobuf/struct.proto";
11import "tensorflow/core/protobuf/trackable_object_graph.proto";
12
13option cc_enable_arenas = true;
14option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/protobuf/for_core_protos_go_proto";
15
16// A SavedObjectGraph is part of object-based SavedModels in TF 2.0. It
17// describes the directed graph of Python objects (or equivalent in other
18// languages) that make up a model, with nodes[0] at the root.
19
20// SavedObjectGraph shares some structure with TrackableObjectGraph, but
21// SavedObjectGraph belongs to the MetaGraph and contains pointers to functions
22// and type information, while TrackableObjectGraph lives in the checkpoint
23// and contains pointers only to variable values.
24
25message SavedObjectGraph {
26  // Flattened list of objects in the object graph.
27  //
28  // The position of the object in this list indicates its id.
29  // Nodes[0] is considered the root node.
30  repeated SavedObject nodes = 1;
31
32  // Information about captures and output structures in concrete functions.
33  // Referenced from SavedBareConcreteFunction and SavedFunction.
34  map<string, SavedConcreteFunction> concrete_functions = 2;
35}
36
37message SavedObject {
38  // Objects which this object depends on: named edges in the dependency
39  // graph.
40  //
41  // Note: All kinds of SavedObject may have children, except
42  // "constant" and "captured_tensor".
43  repeated TrackableObjectGraph.TrackableObject.ObjectReference children = 1;
44
45  // Ordered list of dependencies that must be loaded before this object.
46  // SavedModel loads with the bottom-up approach, by first creating all objects
47  // (in the order defined by the dependencies), then connecting the edges.
48  repeated TrackableObjectGraph.TrackableObject.ObjectReference dependencies =
49      15;
50
51  // Removed when forking SavedObject from TrackableObjectGraph.
52  reserved "attributes";
53  reserved 2;
54
55  // Slot variables owned by this object. This describes the three-way
56  // (optimizer, variable, slot variable) relationship; none of the three
57  // depend on the others directly.
58  //
59  // Note: currently only valid if kind == "user_object".
60  repeated TrackableObjectGraph.TrackableObject.SlotVariableReference
61      slot_variables = 3;
62
63  oneof kind {
64    SavedUserObject user_object = 4;
65    SavedAsset asset = 5;
66    SavedFunction function = 6;
67    SavedVariable variable = 7;
68    SavedBareConcreteFunction bare_concrete_function = 8;
69    SavedConstant constant = 9;
70    SavedResource resource = 10;
71    CapturedTensor captured_tensor = 12;
72  }
73
74  // Stores the functions used to save and restore this object. At most one of
75  // `saveable_objects` or `registered_saver` is defined for each SavedObject.
76  // See the comment below for the difference between SaveableObject and
77  // registered savers.
78  map<string, SaveableObject> saveable_objects = 11;
79
80  // The fields below are filled when the user serializes a registered Trackable
81  // class or an object with a registered saver function.
82  //
83  // Registered classes may save additional metadata and supersede the
84  // default loading process where nodes are recreated from the proto.
85  // If the registered class cannot be found, then the object will load as one
86  // one of the default trackable objects: Autotrackable (a class similar to
87  // tf.Module), tf.function, or tf.Variable.
88  //
89  // Unlike SaveableObjects, which store the functions for saving and restoring
90  // from tensors, registered savers allow Trackables to write checkpoint shards
91  // directly (e.g. for performance or coordination reasons).
92  // *All registered savers must be available when loading the SavedModel.*
93
94  // The name of the registered class of the form "{package}.{class_name}".
95  // This field is used to search for the registered class at loading time.
96  string registered_name = 13;
97  // The user-generated proto storing metadata for this object, to be passed to
98  // the registered classes's _deserialize_from_proto method when this object is
99  // loaded from the SavedModel.
100  google.protobuf.Any serialized_user_proto = 14;
101
102  // String name of the registered saver. At most one of `saveable_objects` or
103  // `registered_saver` is defined for each SavedObject.
104  string registered_saver = 16;
105}
106
107// A SavedUserObject is an object (in the object-oriented language of the
108// TensorFlow program) of some user- or framework-defined class other than
109// those handled specifically by the other kinds of SavedObjects.
110//
111// This object cannot be evaluated as a tensor, and therefore cannot be bound
112// to an input of a function.
113message SavedUserObject {
114  // Corresponds to a registration of the type to use in the loading program.
115  string identifier = 1;
116  // Version information from the producer of this SavedUserObject.
117  VersionDef version = 2;
118  // Metadata for deserializing this object.
119  //
120  // Deprecated! At the time of deprecation, Keras was the only user of this
121  // field, and its saving and loading code will be updated shortly.
122  // Please save your application-specific metadata to a separate file.
123  string metadata = 3 [deprecated = true];
124}
125
126// A SavedAsset points to an asset in the MetaGraph.
127//
128// When bound to a function this object evaluates to a tensor with the absolute
129// filename. Users should not depend on a particular part of the filename to
130// remain stable (e.g. basename could be changed).
131message SavedAsset {
132  // Index into `MetaGraphDef.asset_file_def[]` that describes the Asset.
133  //
134  // Only the field `AssetFileDef.filename` is used. Other fields, such as
135  // `AssetFileDef.tensor_info`, MUST be ignored.
136  int32 asset_file_def_index = 1;
137}
138
139// A function with multiple signatures, possibly with non-Tensor arguments.
140message SavedFunction {
141  repeated string concrete_functions = 1;
142  FunctionSpec function_spec = 2;
143}
144
145message CapturedTensor {
146  // Name of captured tensor
147  string name = 1;
148
149  // Name of concrete function which contains the computed graph tensor.
150  string concrete_function = 2;
151}
152
153// Stores low-level information about a concrete function. Referenced in either
154// a SavedFunction or a SavedBareConcreteFunction.
155message SavedConcreteFunction {
156  repeated int32 bound_inputs = 2;
157
158  // Input in canonicalized form that was received to create this concrete
159  // function.
160  StructuredValue canonicalized_input_signature = 3;
161  // Output that was the return value of this function after replacing all
162  // Tensors with TensorSpecs. This can be an arbitrary nested function and will
163  // be used to reconstruct the full structure from pure tensors.
164  StructuredValue output_signature = 4;
165}
166
167message SavedBareConcreteFunction {
168  // Identifies a SavedConcreteFunction.
169  string concrete_function_name = 1;
170
171  // A sequence of unique strings, one per Tensor argument.
172  repeated string argument_keywords = 2;
173  // The prefix of `argument_keywords` which may be identified by position.
174  int64 allowed_positional_arguments = 3;
175  // The spec of the function that this ConcreteFunction is traced from. This
176  // allows the ConcreteFunction to be called with nest structure inputs. This
177  // field may not be populated. If this field is absent, the concrete function
178  // can only be called with flat inputs.
179  // TODO(b/169361281): support calling saved ConcreteFunction with structured
180  // inputs in C++ SavedModel API.
181  FunctionSpec function_spec = 4;
182}
183
184message SavedConstant {
185  // An Operation name for a ConstantOp in this SavedObjectGraph's MetaGraph.
186  string operation = 1;
187}
188
189// Represents a Variable that is initialized by loading the contents from the
190// checkpoint.
191message SavedVariable {
192  DataType dtype = 1;
193  TensorShapeProto shape = 2;
194  bool trainable = 3;
195  VariableSynchronization synchronization = 4;
196  VariableAggregation aggregation = 5;
197  string name = 6;
198  string device = 7;
199  // List of component variables for a distributed variable.
200  //
201  // When this field is non-empty, the SavedVariable will be assumed
202  // to be a distributed variable defined by the components listed here.
203  //
204  // This is only supported by experimental loaders at the moment.
205  repeated SavedVariable experimental_distributed_variable_components = 8;
206}
207
208// Represents `FunctionSpec` used in `Function`. This represents a
209// function that has been wrapped as a TensorFlow `Function`.
210message FunctionSpec {
211  // Full arg spec from inspect.getfullargspec().
212  StructuredValue fullargspec = 1;
213  // Whether this represents a class method.
214  bool is_method = 2;
215  // The input signature, if specified.
216  StructuredValue input_signature = 5;
217
218  // Whether the function should be compiled by XLA.
219  //
220  // The public interface to `tf.function` uses an optional boolean to
221  // represent three distinct states for this field.  Unfortunately, proto3
222  // removes the ability to explicitly check for the presence or absence of a
223  // field, so we instead map to an enum.
224  //
225  // See `tf.function` for details.
226  enum JitCompile {
227    DEFAULT = 0;
228    ON = 1;
229    OFF = 2;
230  }
231  JitCompile jit_compile = 6;
232
233  reserved 3, 4;
234}
235
236// A SavedResource represents a TF object that holds state during its lifetime.
237// An object of this type can have a reference to a:
238// create_resource() and an initialize() function.
239message SavedResource {
240  // A device specification indicating a required placement for the resource
241  // creation function, e.g. "CPU". An empty string allows the user to select a
242  // device.
243  string device = 1;
244}
245
246message SaveableObject {
247  // Node ids of concrete functions for saving and loading from a checkpoint.
248  // These functions save and restore directly from tensors.
249  int32 save_function = 2;
250  int32 restore_function = 3;
251}
252