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