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". 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 } 64 65 map<string, SaveableObject> saveable_objects = 11; 66} 67 68// A SavedUserObject is an object (in the object-oriented language of the 69// TensorFlow program) of some user- or framework-defined class other than 70// those handled specifically by the other kinds of SavedObjects. 71// 72// This object cannot be evaluated as a tensor, and therefore cannot be bound 73// to an input of a function. 74message SavedUserObject { 75 // Corresponds to a registration of the type to use in the loading program. 76 string identifier = 1; 77 // Version information from the producer of this SavedUserObject. 78 VersionDef version = 2; 79 // Deprecated! At the time of deprecation, Keras was the only user of this 80 // field, and its saving and loading code will be updated shortly. 81 // Please save your application-specific metadata to separate file 82 // Initialization-related metadata. 83 string metadata = 3; 84} 85 86// A SavedAsset points to an asset in the MetaGraph. 87// 88// When bound to a function this object evaluates to a tensor with the absolute 89// filename. Users should not depend on a particular part of the filename to 90// remain stable (e.g. basename could be changed). 91message SavedAsset { 92 // Index into `MetaGraphDef.asset_file_def[]` that describes the Asset. 93 // 94 // Only the field `AssetFileDef.filename` is used. Other fields, such as 95 // `AssetFileDef.tensor_info`, MUST be ignored. 96 int32 asset_file_def_index = 1; 97} 98 99// A function with multiple signatures, possibly with non-Tensor arguments. 100message SavedFunction { 101 repeated string concrete_functions = 1; 102 FunctionSpec function_spec = 2; 103} 104 105// Stores low-level information about a concrete function. Referenced in either 106// a SavedFunction or a SavedBareConcreteFunction. 107message SavedConcreteFunction { 108 // Bound inputs to the function. The SavedObjects identified by the node ids 109 // given here are appended as extra inputs to the caller-supplied inputs. 110 // The only types of SavedObjects valid here are SavedVariable, SavedResource 111 // and SavedAsset. 112 repeated int32 bound_inputs = 2; 113 // Input in canonicalized form that was received to create this concrete 114 // function. 115 StructuredValue canonicalized_input_signature = 3; 116 // Output that was the return value of this function after replacing all 117 // Tensors with TensorSpecs. This can be an arbitrary nested function and will 118 // be used to reconstruct the full structure from pure tensors. 119 StructuredValue output_signature = 4; 120} 121 122message SavedBareConcreteFunction { 123 // Identifies a SavedConcreteFunction. 124 string concrete_function_name = 1; 125 126 // A sequence of unique strings, one per Tensor argument. 127 repeated string argument_keywords = 2; 128 // The prefix of `argument_keywords` which may be identified by position. 129 int64 allowed_positional_arguments = 3; 130 // The spec of the function that this ConcreteFunction is traced from. This 131 // allows the ConcreteFunction to be called with nest structure inputs. This 132 // field may not be populated. If this field is absent, the concrete function 133 // can only be called with flat inputs. 134 // TODO(b/169361281): support calling saved ConcreteFunction with structured 135 // inputs in C++ SavedModel API. 136 FunctionSpec function_spec = 4; 137} 138 139message SavedConstant { 140 // An Operation name for a ConstantOp in this SavedObjectGraph's MetaGraph. 141 string operation = 1; 142} 143 144// Represents a Variable that is initialized by loading the contents from the 145// checkpoint. 146message SavedVariable { 147 DataType dtype = 1; 148 TensorShapeProto shape = 2; 149 bool trainable = 3; 150 VariableSynchronization synchronization = 4; 151 VariableAggregation aggregation = 5; 152 string name = 6; 153 string device = 7; 154 // List of component variables for a distributed variable. 155 // 156 // When this field is non-empty, the SavedVariable will be assumed 157 // to be a distributed variable defined by the components listed here. 158 // 159 // This is only supported by experimental loaders at the moment. 160 repeated SavedVariable experimental_distributed_variable_components = 8; 161} 162 163 164// Represents `FunctionSpec` used in `Function`. This represents a 165// function that has been wrapped as a TensorFlow `Function`. 166message FunctionSpec { 167 // Full arg spec from inspect.getfullargspec(). 168 StructuredValue fullargspec = 1; 169 // Whether this represents a class method. 170 bool is_method = 2; 171 // The input signature, if specified. 172 StructuredValue input_signature = 5; 173 174 // Whether the function should be compiled by XLA. 175 // 176 // The public interface to `tf.function` uses an optional boolean to 177 // represent three distinct states for this field. Unfortunately, proto3 178 // removes the ability to explicitly check for the presence or absence of a 179 // field, so we instead map to an enum. 180 // 181 // See `tf.function` for details. 182 enum JitCompile { 183 DEFAULT = 0; 184 ON = 1; 185 OFF = 2; 186 } 187 JitCompile jit_compile = 6; 188 189 reserved 3, 4; 190} 191 192// A SavedResource represents a TF object that holds state during its lifetime. 193// An object of this type can have a reference to a: 194// create_resource() and an initialize() function. 195message SavedResource { 196 // A device specification indicating a required placement for the resource 197 // creation function, e.g. "CPU". An empty string allows the user to select a 198 // device. 199 string device = 1; 200} 201 202message SaveableObject { 203 // Node ids of concrete functions for saving and loading from a checkpoint. 204 int32 save_function = 2; 205 int32 restore_function = 3; 206} 207