1syntax = "proto3"; 2 3package tensorflow; 4 5import "tensorflow/core/framework/attr_value.proto"; 6import "tensorflow/core/framework/node_def.proto"; 7import "tensorflow/core/framework/op_def.proto"; 8 9option cc_enable_arenas = true; 10option java_outer_classname = "FunctionProtos"; 11option java_multiple_files = true; 12option java_package = "org.tensorflow.framework"; 13option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/framework/function_go_proto"; 14 15// A library is a set of named functions. 16message FunctionDefLibrary { 17 repeated FunctionDef function = 1; 18 repeated GradientDef gradient = 2; 19 repeated RegisteredGradient registered_gradients = 3; 20} 21 22// A function can be instantiated when the runtime can bind every attr 23// with a value. When a GraphDef has a call to a function, it must 24// have binding for every attr defined in the signature. 25// 26// TODO(zhifengc): 27// * device spec, etc. 28message FunctionDef { 29 // The definition of the function's name, arguments, return values, 30 // attrs etc. 31 OpDef signature = 1; 32 33 // Attributes specific to this function definition. 34 map<string, AttrValue> attr = 5; 35 36 // Attributes for function arguments. These attributes are the same set of 37 // valid attributes as to _Arg nodes. 38 message ArgAttrs { 39 map<string, AttrValue> attr = 1; 40 } 41 map<uint32, ArgAttrs> arg_attr = 7; 42 43 // Unique IDs for each resource argument, used to track aliasing resources. If 44 // Argument A and Argument B alias each other, then 45 // resource_arg_unique_ids[A.index] == resource_arg_unique_ids[B.index]. 46 // 47 // If this field is empty, none of the arguments could alias; otherwise, every 48 // resource argument should have an entry in this field. 49 // 50 // When instantiated, the unique IDs will be attached to the _Arg nodes' 51 // "_resource_arg_unique_id" attribute. 52 map<uint32, uint32> resource_arg_unique_id = 8; 53 54 // NOTE: field id 2 deleted on Jan 11, 2017, GraphDef version 21. 55 reserved 2; 56 57 // In both of the following fields, there is the need to specify an 58 // output that is used as either the input to another node (in 59 // `node_def`) or as a return value of the function (in `ret`). 60 // Unlike the NodeDefs in GraphDef, we need to be able to specify a 61 // list in some cases (instead of just single outputs). Also, we 62 // need to be able to deal with lists of unknown length (so the 63 // output index may not be known at function definition time). So 64 // we use the following format instead: 65 // * "fun_in" where "fun_in" is the name of a function input arg in 66 // the `signature` field above. This represents that input, whether 67 // it is a single tensor or a list. 68 // * "fun_in:0" gives the first element of a function input arg (a 69 // non-list input is considered a list of length 1 for these 70 // purposes). 71 // * "node:out" where "node" is the name of a node in `node_def` and 72 // "out" is the name one of its op's output arguments (the name 73 // comes from the OpDef of the node's op). This represents that 74 // node's output, whether it is a single tensor or a list. 75 // Note: We enforce that an op's output arguments are never 76 // renamed in the backwards-compatibility test. 77 // * "node:out:0" gives the first element of a node output arg (a 78 // non-list output is considered a list of length 1 for these 79 // purposes). 80 // 81 // NOT CURRENTLY SUPPORTED (but may be in the future): 82 // * "node:out:-1" gives last element in a node output list 83 // * "node:out:1:" gives a list with all but the first element in a 84 // node output list 85 // * "node:out::-1" gives a list with all but the last element in a 86 // node output list 87 88 // The body of the function. Unlike the NodeDefs in a GraphDef, attrs 89 // may have values of type `placeholder` and the `input` field uses 90 // the "output" format above. 91 92 // By convention, "op" in node_def is resolved by consulting with a 93 // user-defined library first. If not resolved, "func" is assumed to 94 // be a builtin op. 95 repeated NodeDef node_def = 3; 96 97 // A mapping from the output arg names from `signature` to the 98 // outputs from `node_def` that should be returned by the function. 99 map<string, string> ret = 4; 100 101 // A mapping from control output names from `signature` to node names in 102 // `node_def` which should be control outputs of this function. 103 map<string, string> control_ret = 6; 104} 105 106// GradientDef defines the gradient function of a function defined in 107// a function library. 108// 109// A gradient function g (specified by gradient_func) for a function f 110// (specified by function_name) must follow the following: 111// 112// The function 'f' must be a numerical function which takes N inputs 113// and produces M outputs. Its gradient function 'g', which is a 114// function taking N + M inputs and produces N outputs. 115// 116// I.e. if we have 117// (y1, y2, ..., y_M) = f(x1, x2, ..., x_N), 118// then, g is 119// (dL/dx1, dL/dx2, ..., dL/dx_N) = g(x1, x2, ..., x_N, 120// dL/dy1, dL/dy2, ..., dL/dy_M), 121// where L is a scalar-value function of (x1, x2, ..., xN) (e.g., the 122// loss function). dL/dx_i is the partial derivative of L with respect 123// to x_i. 124message GradientDef { 125 string function_name = 1; // The function name. 126 string gradient_func = 2; // The gradient function's name. 127} 128 129// RegisteredGradient stores a gradient function that is registered in the 130// gradients library and used in the ops of a function in the function library. 131// Unlike GradientDef, these gradients are identified by op type, and not 132// directly linked to any function. 133message RegisteredGradient { 134 string gradient_func = 1; // The gradient function's name. 135 string registered_op_type = 2; // The gradient function's registered op type. 136} 137