• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  // NOTE: field id 2 deleted on Jan 11, 2017, GraphDef version 21.
34  reserved 2;
35
36  // In both of the following fields, there is the need to specify an
37  // output that is used as either the input to another node (in
38  // `node_def`) or as a return value of the function (in `ret`).
39  // Unlike the NodeDefs in GraphDef, we need to be able to specify a
40  // list in some cases (instead of just single outputs).  Also, we
41  // need to be able to deal with lists of unknown length (so the
42  // output index may not be known at function definition time).  So
43  // we use the following format instead:
44  // * "fun_in" where "fun_in" is the name of a function input arg in
45  //   the `signature` field above.  This represents that input, whether
46  //   it is a single tensor or a list.
47  // * "fun_in:0" gives the first element of a function input arg (a
48  //   non-list input is considered a list of length 1 for these
49  //   purposes).
50  // * "node:out" where "node" is the name of a node in `node_def` and
51  //   "out" is the name one of its op's output arguments (the name
52  //   comes from the OpDef of the node's op). This represents that
53  //   node's output, whether it is a single tensor or a list.
54  //   Note: We enforce that an op's output arguments are never
55  //   renamed in the backwards-compatibility test.
56  // * "node:out:0" gives the first element of a node output arg (a
57  //   non-list output is considered a list of length 1 for these
58  //   purposes).
59  //
60  // NOT CURRENTLY SUPPORTED (but may be in the future):
61  // * "node:out:-1" gives last element in a node output list
62  // * "node:out:1:" gives a list with all but the first element in a
63  //   node output list
64  // * "node:out::-1" gives a list with all but the last element in a
65  //   node output list
66
67  // The body of the function.  Unlike the NodeDefs in a GraphDef, attrs
68  // may have values of type `placeholder` and the `input` field uses
69  // the "output" format above.
70
71  // By convention, "op" in node_def is resolved by consulting with a
72  // user-defined library first. If not resolved, "func" is assumed to
73  // be a builtin op.
74  repeated NodeDef node_def = 3;
75
76  // A mapping from the output arg names from `signature` to the
77  // outputs from `node_def` that should be returned by the function.
78  map<string, string> ret = 4;
79
80  // A mapping from control output names from `signature` to node names in
81  // `node_def` which should be control outputs of this function.
82  map<string, string> control_ret = 6;
83}
84
85// GradientDef defines the gradient function of a function defined in
86// a function library.
87//
88// A gradient function g (specified by gradient_func) for a function f
89// (specified by function_name) must follow the following:
90//
91// The function 'f' must be a numerical function which takes N inputs
92// and produces M outputs. Its gradient function 'g', which is a
93// function taking N + M inputs and produces N outputs.
94//
95// I.e. if we have
96//    (y1, y2, ..., y_M) = f(x1, x2, ..., x_N),
97// then, g is
98//    (dL/dx1, dL/dx2, ..., dL/dx_N) = g(x1, x2, ..., x_N,
99//                                      dL/dy1, dL/dy2, ..., dL/dy_M),
100// where L is a scalar-value function of (x1, x2, ..., xN) (e.g., the
101// loss function). dL/dx_i is the partial derivative of L with respect
102// to x_i.
103message GradientDef {
104  string function_name = 1;  // The function name.
105  string gradient_func = 2;  // The gradient function's name.
106}
107