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