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