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