1syntax = "proto3"; 2 3import "tensorflow/core/protobuf/trackable_object_graph.proto"; 4import "tensorflow/core/protobuf/struct.proto"; 5import "tensorflow/core/framework/tensor_shape.proto"; 6import "tensorflow/core/framework/types.proto"; 7import "tensorflow/core/framework/versions.proto"; 8 9option cc_enable_arenas = true; 10 11package tensorflow; 12 13// A SavedObjectGraph is part of object-based SavedModels in TF 2.0. It 14// describes the directed graph of Python objects (or equivalent in other 15// languages) that make up a model, with nodes[0] at the root. 16 17// SavedObjectGraph shares some structure with TrackableObjectGraph, but 18// SavedObjectGraph belongs to the MetaGraph and contains pointers to functions 19// and type information, while TrackableObjectGraph lives in the checkpoint 20// and contains pointers only to variable values. 21 22message SavedObjectGraph { 23 // Flattened list of objects in the object graph. 24 // 25 // The position of the object in this list indicates its id. 26 // Nodes[0] is considered the root node. 27 repeated SavedObject nodes = 1; 28 29 // Information about captures and output structures in concrete functions. 30 // Referenced from SavedBareConcreteFunction and SavedFunction. 31 map<string, SavedConcreteFunction> concrete_functions = 2; 32} 33 34message SavedObject { 35 // Objects which this object depends on: named edges in the dependency 36 // graph. 37 // 38 // Note: currently only valid if kind == "user_object". 39 repeated TrackableObjectGraph.TrackableObject.ObjectReference 40 children = 1; 41 42 // Removed when forking SavedObject from TrackableObjectGraph. 43 reserved "attributes"; 44 reserved 2; 45 46 // Slot variables owned by this object. This describes the three-way 47 // (optimizer, variable, slot variable) relationship; none of the three 48 // depend on the others directly. 49 // 50 // Note: currently only valid if kind == "user_object". 51 repeated TrackableObjectGraph.TrackableObject.SlotVariableReference 52 slot_variables = 3; 53 54 oneof kind { 55 SavedUserObject user_object = 4; 56 SavedAsset asset = 5; 57 SavedFunction function = 6; 58 SavedVariable variable = 7; 59 SavedBareConcreteFunction bare_concrete_function = 8; 60 SavedConstant constant = 9; 61 SavedResource resource = 10; 62 } 63} 64 65// A SavedUserObject is an object (in the object-oriented language of the 66// TensorFlow program) of some user- or framework-defined class other than 67// those handled specifically by the other kinds of SavedObjects. 68// 69// This object cannot be evaluated as a tensor, and therefore cannot be bound 70// to an input of a function. 71message SavedUserObject { 72 // Corresponds to a registration of the type to use in the loading program. 73 string identifier = 1; 74 // Version information from the producer of this SavedUserObject. 75 VersionDef version = 2; 76} 77 78// A SavedAsset points to an asset in the MetaGraph. 79// 80// When bound to a function this object evaluates to a tensor with the absolute 81// filename. Users should not depend on a particular part of the filename to 82// remain stable (e.g. basename could be changed). 83message SavedAsset { 84 // Index into `MetaGraphDef.asset_file_def[]` that describes the Asset. 85 // 86 // Only the field `AssetFileDef.filename` is used. Other fields, such as 87 // `AssetFileDef.tensor_info`, MUST be ignored. 88 int32 asset_file_def_index = 1; 89} 90 91// A function with multiple signatures, possibly with non-Tensor arguments. 92message SavedFunction { 93 repeated string concrete_functions = 1; 94 FunctionSpec function_spec = 2; 95} 96 97// Stores low-level information about a concrete function. Referenced in either 98// a SavedFunction or a SavedBareConcreteFunction. 99message SavedConcreteFunction { 100 // Bound inputs to the function. The SavedObjects identified by the node ids 101 // given here are appended as extra inputs to the caller-supplied inputs. 102 // The only types of SavedObjects valid here are SavedVariable, SavedResource 103 // and SavedAsset. 104 repeated int32 bound_inputs = 2; 105 // Input in canonicalized form that was received to create this concrete 106 // function. 107 StructuredValue canonicalized_input_signature = 3; 108 // Output that was the return value of this function after replacing all 109 // Tensors with TensorSpecs. This can be an arbitrary nested function and will 110 // be used to reconstruct the full structure from pure tensors. 111 StructuredValue output_signature = 4; 112} 113 114message SavedBareConcreteFunction { 115 // Identifies a SavedConcreteFunction. 116 string concrete_function_name = 1; 117 118 // A sequence of unique strings, one per Tensor argument. 119 repeated string argument_keywords = 2; 120 // The prefix of `argument_keywords` which may be identified by position. 121 int64 allowed_positional_arguments = 3; 122} 123 124message SavedConstant { 125 // An Operation name for a ConstantOp in this SavedObjectGraph's MetaGraph. 126 string operation = 1; 127} 128 129// Represents a Variable that is initialized by loading the contents from the 130// checkpoint. 131message SavedVariable { 132 DataType dtype = 1; 133 TensorShapeProto shape = 2; 134 bool trainable = 3; 135} 136 137// Represents `FunctionSpec` used in `Function`. This represents a 138// function that has been wrapped as a TensorFlow `Function`. 139message FunctionSpec { 140 // Full arg spec from inspect.getfullargspec(). 141 StructuredValue fullargspec = 1; 142 // Whether this represents a class method. 143 bool is_method = 2; 144 // Which arguments to always prepend, in case the original function is based 145 // on a functools.partial. 146 StructuredValue args_to_prepend = 3; 147 // Which kwargs to always include, in case the original function is based on a 148 // functools.partial. 149 StructuredValue kwargs_to_include = 4; 150 // The input signature, if specified. 151 StructuredValue input_signature = 5; 152} 153 154// A SavedResource represents a TF object that holds state during its lifetime. 155message SavedResource { 156 // An object of this type can have a reference to a: 157 // create_resource() and an initialize() function. 158} 159