• 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// LINT.IfChange
12// Experimental. Represents the complete type information of a TensorFlow value.
13enum FullTypeId {
14  // The default represents an uninitialized values.
15  TFT_UNSET = 0;
16
17  // Type symbols. Used to construct more complex type expressions like
18  // algebraic data types.
19
20  // Type variables may serve as placeholder for any other type ID in type
21  // templates.
22  //
23  // Examples:
24  //   TFT_DATASET[TFT_VAR["T"]] is a Dataset returning a type indicated by "T".
25  //   TFT_TENSOR[TFT_VAR["T"]] is a Tensor of n element type indicated by "T".
26  //   TFT_TENSOR[TFT_VAR["T"]], TFT_TENSOR[TFT_VAR["T"]] are two tensors of
27  //     identical element types.
28  //   TFT_TENSOR[TFT_VAR["P"]], TFT_TENSOR[TFT_VAR["Q"]] are two tensors of
29  //     independent element types.
30  //
31  TFT_VAR = 1;
32
33  // Wildcard type. Describes a parameter of unknown type. In TensorFlow, that
34  // can mean either a "Top" type (accepts any type), or a dynamically typed
35  // object whose type is unknown in context.
36  // Important: "unknown" does not necessarily mean undeterminable!
37  TFT_ANY = 2;
38
39  // The algebraic product type. This is an algebraic type that may be used just
40  // for logical grouping. Not to confused with TFT_TUPLE which describes a
41  // concrete object of several elements.
42  //
43  // Example:
44  //   TFT_DATASET[TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_FLOAT64]]]
45  //     is a Dataset producing two tensors, an integer one and a float one.
46  //
47  TFT_PRODUCT = 3;
48
49  // Represents a named field, with the name stored in the attribute.
50  //
51  // Parametrization:
52  //   TFT_NAMED[<type>]{<name>}
53  //   * <type> is the type of the field
54  //   * <name> is the field name, as string (thpugh can theoretically be an int
55  //     as well)
56  //
57  // Example:
58  //   TFT_RECORD[
59  //     TFT_NAMED[TFT_TENSOR[TFT_INT32]]{'foo'},
60  //     TFT_NAMED[TFT_TENSOR[TFT_FLOAT32]]{'bar'},
61  //   ]
62  //     is a structure with two fields, an int tensor "foo" and a float tensor
63  //     "bar".
64  TFT_NAMED = 4;
65
66  // Template definition. Expands the variables by repeating a template as
67  // arguments of container.
68  //
69  // Parametrization:
70  //   TFT_FOR_EACH[<container_type>, <template>, <expansions>]
71  //   * <container_type> is the type of the container that the template will be
72  //     expanded into
73  //   * <template> is any type definition that potentially contains type
74  //     variables
75  //   * <expansions> is a TFT_VAR and may include more types in the future
76  //
77  // Example:
78  //   TFT_FOR_EACH[
79  //         TFT_PRODUCT,
80  //         TFT_TENSOR[TFT_VAR["t"]],
81  //         TFT_VAR["t"]
82  //     ]
83  //     will substitute a T = TFT_INT32 to TFT_PRODUCT[TFT_TENSOR[TFT_INT32]]
84  //     and a T = (TFT_INT32, TFT_INT64) to
85  //     TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_INT64]].
86  TFT_FOR_EACH = 20;
87
88  // Callable types describe functions and ops.
89  //
90  // Parametrization:
91  //   TFT_CALLABLE[<arg type>, <return type>]
92  //   * <arg type> is the type of the arguments; TFT_PRODUCT represents
93  //   multiple
94  //     arguments.
95  //   * <return type> is the return type; TFT_PRODUCT represents multiple
96  //     return values (that means that callables returning multiple things
97  //     don't necessarily return a single tuple).
98  //
99  // Example:
100  //   TFT_CALLABLE[
101  //     TFT_ANY,
102  //     TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_FLOAT64]],
103  //   ]
104  //     is a callable with unspecified (for now) input arguments, and
105  //     two return values of type tensor.
106  //
107  TFT_CALLABLE = 100;
108
109  // Concrete type IDs, representing "proper" data types that can describe
110  // runtime TensorFlow objects.
111
112  // The usual Tensor. This is a parametric type.
113  //
114  // Parametrization:
115  //   TFT_TENSOR[<element type>, <shape type>]
116  //   * <element type> is currently limited to one of the element types
117  //     defined below.
118  //   * <shape type> is not yet defined, and may only be TFT_UNKNOWN for now.
119  //
120  // A TFT_SHAPE type will be defined in the future.
121  //
122  // Example:
123  //   TFT_TENSOR[TFT_INT32, TFT_UNKNOWN]
124  //     is a Tensor of int32 element type and unknown shape.
125  //
126  // TODO(mdan): Define TFT_SHAPE and add more examples.
127  TFT_TENSOR = 1000;
128
129  // Array (or tensorflow::TensorList in the variant type registry).
130  // Note: this is not to be confused with the deprecated `TensorArray*` ops
131  // which are not supported by FullType.
132  // This type represents a random-access list whose elements can be
133  // described by a single type. Although immutable, Array is expected to
134  // support efficient mutation semantics (i.e. element update) in the
135  // user-facing API.
136  // The element type may be generic or even TFT_ANY for a heterogenous list.
137  //
138  // Parametrization:
139  //   TFT_ARRAY[<element type>]
140  //   * <element type> may be any concrete type.
141  //
142  // Examples:
143  //   TFT_ARRAY[TFT_TENSOR[TFT_INT32]] is a TensorArray holding int32 Tensors
144  //     of any shape.
145  //   TFT_ARRAY[TFT_TENSOR[TFT_UNKNOWN]] is a TensorArray holding Tensors of
146  //     mixed element types.
147  //   TFT_ARRAY[TFT_UNKNOWN] is a TensorArray holding any element type.
148  //   TFT_ARRAY[] is equivalent to TFT_ARRAY[TFT_UNKNOWN].
149  //   TFT_ARRAY[TFT_ARRAY[]] is an array or arrays (of unknown types).
150  TFT_ARRAY = 1001;
151
152  // Optional (or tensorflow::OptionalVariant in the variant type registry).
153  // This type represents a value that may either hold an element of a single
154  // specified type, or nothing at all.
155  //
156  // Parametrization:
157  //   TFT_OPTIONAL[<element type>]
158  //   * <element type> may be any concrete type.
159  //
160  // Examples:
161  //   TFT_OPTIONAL[TFT_TENSOR[TFT_INT32]] is an Optional holding an int32
162  //     Tensor of any shape.
163  TFT_OPTIONAL = 1002;
164
165  // Literal types describe compile-time constant values.
166  // Literal types may also participate in dependent types.
167  //
168  // Parametrization:
169  //   TFT_LITERAL[<value type>]{<value>}
170  //   * <value type> may be any concrete type compatible that can hold <value>
171  //   * <value> is the type's attribute, and holds the actual literal value
172  //
173  // Examples:
174  //   TFT_LITERAL[TFT_INT32]{1} is the compile-time constant 1.
175  TFT_LITERAL = 1003;
176
177  // Encoding types describe a value of a certain type, encoded as a different
178  // type.
179  //
180  // Parametrization:
181  //   TFT_ENCODED[<encoded type>, <encoding type>]
182  //   * <encoded type> may be any type
183  //   * <encoding type> may be any type
184  //
185  // Examples:
186  //   TFT_ENCODING[TFT_INT32, TFT_STRING] is an integer encoded as string.
187  TFT_ENCODED = 1004;
188
189  // Type attributes. These always appear in the parametrization of a type,
190  // never alone. For example, there is no such thing as a "bool" TensorFlow
191  // object (for now).
192
193  // The bool element type.
194  // TODO(mdan): Quantized types, legacy representations (e.g. ref)
195  TFT_BOOL = 200;
196  // Integer element types.
197  TFT_UINT8 = 201;
198  TFT_UINT16 = 202;
199  TFT_UINT32 = 203;
200  TFT_UINT64 = 204;
201  TFT_INT8 = 205;
202  TFT_INT16 = 206;
203  TFT_INT32 = 207;
204  TFT_INT64 = 208;
205  // Floating-point element types.
206  TFT_HALF = 209;
207  TFT_FLOAT = 210;
208  TFT_DOUBLE = 211;
209  TFT_BFLOAT16 = 215;
210  // Complex element types.
211  // TODO(mdan): Represent as TFT_COMPLEX[TFT_DOUBLE] instead?
212  TFT_COMPLEX64 = 212;
213  TFT_COMPLEX128 = 213;
214  // The string element type.
215  TFT_STRING = 214;
216
217  // Other types that we don't know yet whether they will become part of the
218  // core type system or be consisdered third-party (and consequently moved to
219  // user-defined type mechanisms). Presently, they are effectively in the core
220  // type system, because key compilation passes like Placer account for their
221  // existence.
222
223  // Datasets created by tf.data ops and APIs. Datasets have generator/iterable
224  // semantics, that is, one can construct an iterator from them. Like
225  // Array, they are considered to return elements that can be described
226  // by a single type. Unlike Array, they do not support random access or
227  // mutation, and can potentially produce an infinite number of elements.
228  // A datasets can produce logical structures (e.g. multiple elements). This
229  // is expressed using TFT_PRODUCT.
230  //
231  //
232  // Parametrization: TFT_DATASET[<element type>].
233  //   * <element type> may be a concrete type or a type symbol. It represents
234  //     the data type of the elements produced by the dataset.
235  //
236  // Examples:
237  //   TFT_DATSET[TFT_TENSOR[TFT_INT32]] is a Dataset producing single int32
238  //     Tensors of unknown shape.
239  //   TFT_DATSET[TFT_PRODUCT[TFT_TENSOR[TFT_INT32], TFT_TENSOR[TFT_FLOAT32]] is
240  //     a Dataset producing pairs of Tensors, one integer and one float.
241  // Note: The high ID number is to prepare for the eventuality that Datasets
242  // will be supported by user types in the future.
243  TFT_DATASET = 10102;
244
245  // A ragged tensor created by tf.ragged ops and APIs.
246  //
247  // Parametrization: TFT_RAGGED[<element_type>].
248  TFT_RAGGED = 10103;
249
250  // Iterators created by tf.data ops and APIs. Very similar to Datasets, except
251  // they are mutable.
252  //
253  //
254  // Parametrization: TFT_ITERATOR[<element type>].
255  //   * <element type> may be a concrete type or a type symbol. It represents
256  //     the data type of the elements produced by the dataset.
257  TFT_ITERATOR = 10104;
258
259  // A mutex lock tensor, produced by tf.raw_ops.MutexLock.
260  // Unlike strict execution models, where ownership of a lock is denoted by
261  // "running after the lock has been acquired", in non-strict mode, lock
262  // ownership is in the true sense: "the op argument representing the lock is
263  // available".
264  // Mutex locks are the dynamic counterpart of control dependencies.
265  // TODO(mdan): Properly document this thing.
266  //
267  // Parametrization: TFT_MUTEX_LOCK[].
268  TFT_MUTEX_LOCK = 10202;
269
270  // The equivalent of a Tensor with DT_VARIANT dtype, kept here to simplify
271  // translation. This type should not normally appear after type inference.
272  // Note that LEGACY_VARIANT != ANY: TENSOR[INT32] is a subtype of ANY, but is
273  // not a subtype of LEGACY_VARIANT.
274  TFT_LEGACY_VARIANT = 10203;
275}
276
277// Highly experimental and very likely to change.
278// This encoding uses tags instead of dedicated messages for regularity. In
279// particular the encoding imposes no restrictions on what the parameters of any
280// type should be, which in particular needs to be true for type symbols.
281message FullTypeDef {
282  // The principal type represented by this object. This may be a concrete type
283  // (Tensor, Dataset) a type variable (used for dependent types) a type
284  // symbol (Any, Union). See FullTypeId for details.
285  FullTypeId type_id = 1;
286
287  repeated FullTypeDef args = 2;
288
289  // Literal values of this type object, if the type admits one.
290  // For example, a type variable admits a string attribute - its name.
291  // Shape-related types may admit int attributes - their static shape values.
292  // Fields for more data types to be added as needed.
293  oneof attr {
294    string s = 3;
295    int64 i = 4;
296    // TODO(mdan): list/tensor, map? Need to reconcile with TFT_RECORD, etc.
297  }
298}
299// LINT.ThenChange(../ir/types/attributes.td)
300