• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1syntax = "proto3";
2
3package tensorflow;
4
5option cc_enable_arenas = true;
6option java_outer_classname = "FullTypeProtos";
7option java_multiple_files = true;
8option java_package = "org.tensorflow.framework";
9option go_package = "github.com/tensorflow/tensorflow/tensorflow/go/core/framework/full_type_go_proto";
10
11// Experimental. Represents the complete type information of a TensorFlow value.
12enum FullTypeId {
13  // The default represents an uninitialized values.
14  TFT_UNSET = 0;
15
16  // Type symbols. Used to construct more complex type expressions like
17  // algebraic data types.
18
19  // Type variables may serve as placeholder for any other type ID in type
20  // templates.
21  //
22  // Examples:
23  //   TFT_DATASET[TFT_VAR["T"]] is a Dataset returning a type indicated by "T".
24  //   TFT_TENSOR[TFT_VAR["T"]] is a Tensor of n element type indicated by "T".
25  //   TFT_TENSOR[TFT_VAR["T"]], TFT_TENSOR[TFT_VAR["T"]] are two tensors of
26  //     identical element types.
27  //   TFT_TENSOR[TFT_VAR["P"]], TFT_TENSOR[TFT_VAR["Q"]] are two tensors of
28  //     potentially different element types.
29  //
30  TFT_VAR = 1;
31
32  // Wildcard type. Describes a parameter of unknown type. In TensorFlow, that
33  // can mean either a "Top" type (accepts any type), or a dynamically typed
34  // object whose type is unknown in context.
35  // Important: "unknown" does not necessarily mean undeterminable!
36  TFT_ANY = 2;
37
38  // The algebraic product type. This is an algebraic type that may be used just
39  // for logical grouping. Not to confused with TFT_TUPLE which describes a
40  // concrete object of several elements.
41  //
42  // Example:
43  //   TFT_DATASET[TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_FLOAT64]]]
44  //     is a Dataset producing two tensors, an integer one and a float one.
45  //
46  TFT_PRODUCT = 3;
47
48  // Callable types describe functions and ops.
49  //
50  // Parametrization:
51  //   TFT_CALLABLE[<arg type>, <return type>]
52  //   * <arg_type> is the type of the arguments; TFT_PRODUCT represents
53  //   multiple
54  //     arguments.
55  //   * <return_type> is the return type; TFT_PRODUCT represents multiple
56  //     return values (that means that callables returning multiple things
57  //     don't necessarily return a single tuple).
58  //
59  // Example:
60  //   TFT_CALLABLE[
61  //     TFT_ANY,
62  //     TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_FLOAT64]],
63  //   ]
64  //     is a callable with unspecified (for now) input arguments, and
65  //     two return values of type tensor.
66  //
67  TFT_CALLABLE = 100;
68
69  // Concrete type IDs, representing "proper" data types that can describe
70  // runtime TensorFlow objects.
71
72  // The usual Tensor. This is a parametric type.
73  //
74  // Parametrization:
75  //   TFT_TENSOR[<element type>, <shape type>]
76  //   * <element_type> is currently limited to one of the element types
77  //     defined below.
78  //   * <shape_type> is not yet defined, and may only be TFT_UNKNOWN for now.
79  //
80  // A TFT_SHAPE type will be defined in the future.
81  //
82  // Example:
83  //   TFT_TENSOR[TFT_INT32, TFT_UNKNOWN]
84  //     is a Tensor of int32 element type and unknown shape.
85  //
86  // TODO(mdan): Define TFT_SHAPE and add more examples.
87  TFT_TENSOR = 1000;
88
89  // Array (or tensorflow::TensorList in the variant type registry).
90  // Note: this is not to be confused with the deprecated `TensorArray*` ops
91  // which are not supported by FullType.
92  // This type represents a random-access list whose elements can be
93  // described by a single type. Although immutable, Array is expected to
94  // support efficient mutation semantics (i.e. element update) in the
95  // user-facing API.
96  // The element type may be generic or even TFT_ANY for a heterogenous list.
97  //
98  // Parametrization:
99  //   TFT_ARRAY[<element type>]
100  //   * <element_type> may be any concrete type.
101  //
102  // Examples:
103  //   TFT_ARRAY[TFT_TENSOR[TFT_INT32]] is a TensorArray holding int32 Tensors
104  //     of any shape.
105  //   TFT_ARRAY[TFT_TENSOR[TFT_UNKNOWN]] is a TensorArray holding Tensors of
106  //     mixed element types.
107  //   TFT_ARRAY[TFT_UNKNOWN] is a TensorArray holding any element type.
108  //   TFT_ARRAY[] is equivalent to TFT_ARRAY[TFT_UNKNOWN].
109  //   TFT_ARRAY[TFT_ARRAY[]] is an array or arrays (of unknown types).
110  TFT_ARRAY = 1001;
111
112  // Optional (or tensorflow::OptionalVariant in the variant type registry).
113  // This type represents a value that may either hold an element of a single
114  // specified type, or nothing at all.
115  //
116  // Parametrization:
117  //   TFT_OPTIONAL[<element type>]
118  //   * <element_type> may be any concrete type.
119  //
120  // Examples:
121  //   TFT_OPTIONAL[TFT_TENSOR[TFT_INT32]] is an Optional holding an int32
122  //     Tensor of any shape.
123  TFT_OPTIONAL = 1002;
124
125  // Datasets created by tf.data ops and APIs. Datasets have generator/iterable
126  // semantics, that is, one can construct an iterator from them. Like
127  // Array, they are considered to return elements that can be described
128  // by a single type. Unlike Array, they do not support random access or
129  // mutation, and can potentially produce an infinite number of elements.
130  // A datasets can produce logical structures (e.g. multiple elements). This
131  // is expressed using TFT_PRODUCT.
132  //
133  //
134  // Parametrization: TFT_ARRAY[<element type>].
135  // <element_type> may be a concrete type or a type symbol. It represents the
136  //   data type of the elements produced by the dataset.
137  //
138  // Examples:
139  //   TFT_DATSET[TFT_TENSOR[TFT_INT32]] is a Dataset producing single int32
140  //     Tensors of unknown shape.
141  //   TFT_DATSET[TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_FLOAT32]] is
142  //   a
143  //     Dataset producing pairs of Tensors, one integer and one float.
144  // Note: The high ID number is to prepare for the eventuality that Datasets
145  // will be supported by user types in the future.
146  TFT_DATASET = 10102;
147
148  // Type attributes. These always appear in the parametrization of a type,
149  // never alone. For example, there is no such thing as a "bool" TensorFlow
150  // object (for now).
151
152  // The bool element type.
153  // TODO(mdan): Quantized types, legacy representations (e.g. ref)
154  TFT_BOOL = 200;
155  // Integer element types.
156  TFT_UINT8 = 201;
157  TFT_UINT16 = 202;
158  TFT_UINT32 = 203;
159  TFT_UINT64 = 204;
160  TFT_INT8 = 205;
161  TFT_INT16 = 206;
162  TFT_INT32 = 207;
163  TFT_INT64 = 208;
164  // Floating-point element types.
165  TFT_HALF = 209;
166  TFT_FLOAT = 210;
167  TFT_DOUBLE = 211;
168  TFT_BFLOAT16 = 215;
169  // Complex element types.
170  // TODO(mdan): Represent as TFT_COMPLEX[TFT_DOUBLE] instead?
171  TFT_COMPLEX64 = 212;
172  TFT_COMPLEX128 = 213;
173  // The string element type.
174  TFT_STRING = 214;
175}
176
177// Highly experimental and very likely to change.
178// This encoding uses tags instead of dedicated messages for regularity. In
179// particular the encoding imposes no restrictions on what the parameters of any
180// type should be, which in particular needs to be true for type symbols.
181message FullTypeDef {
182  // The principal type represented by this object. This may be a concrete type
183  // (Tensor, Dataset) a type variable (used for dependent types) a type
184  // symbol (Any, Union). See FullTypeId for details.
185  FullTypeId type_id = 1;
186
187  repeated FullTypeDef args = 2;
188
189  // Literal values of this type object, if the the type admits one.
190  // For example, a type variable admits a string attribute - its name.
191  // Shape-related types may admit int attributes - their static shape values.
192  // Fields for more data types to be added as needed.
193  oneof attr {
194    string s = 3;
195  }
196}
197