Imported Upstream version 1.25.0
[platform/core/ml/nnfw.git] / res / TensorFlowLiteSchema / 2.12.1 / schema.fbs
1 // Copyright 2017 The TensorFlow Authors. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //     http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 // Revision History
16 // Version 0: Initial version.
17 // Version 1: Add subgraphs to schema.
18 // Version 2: Rename operators to conform to NN API.
19 // Version 3: Move buffer data from Model.Subgraph.Tensors to Model.Buffers.
20 // Version 3a: Add new builtin op code field. Has backward compatibility with
21 //             version 3.
22 // Version 3b: Rename fields in SignatureDef. Has backward compatibility with
23 //             version 3 and 3a.
24
25 namespace tflite;
26
27 // This corresponds to the version.
28 file_identifier "TFL3";
29 // File extension of any written files.
30 file_extension "tflite";
31
32 // IMPORTANT: All new members of tables, enums and unions must be added at the
33 // end to ensure backwards compatibility.
34
35 // The type of data stored in a tensor.
36 enum TensorType : byte {
37   FLOAT32 = 0,
38   FLOAT16 = 1,
39   INT32 = 2,
40   UINT8 = 3,
41   INT64 = 4,
42   STRING = 5,
43   BOOL = 6,
44   INT16 = 7,
45   COMPLEX64 = 8,
46   INT8 = 9,
47   FLOAT64 = 10,
48   COMPLEX128 = 11,
49   UINT64 = 12,
50   // Experimental: Resource and variant types are experimental, that are subject
51   // to change. Do not implement custom kernels using resource & variant types
52   // now.
53   RESOURCE = 13,
54   VARIANT = 14,
55   UINT32 = 15,
56   UINT16 = 16,
57   INT4 = 17,
58 }
59
60 // Custom quantization parameters for experimenting with new quantization
61 // techniques.
62 table CustomQuantization {
63   custom:[ubyte] (force_align: 16);
64 }
65
66 // Represents a specific quantization technique's parameters.
67 union QuantizationDetails {
68   CustomQuantization,
69 }
70
71 // Parameters for converting a quantized tensor back to float.
72 table QuantizationParameters {
73   // These four parameters are the asymmetric linear quantization parameters.
74   // Given a quantized value q, the corresponding float value f should be:
75   //   f = scale * (q - zero_point)
76   // For other quantization types, the QuantizationDetails below is used.
77   min:[float];  // For importing back into tensorflow.
78   max:[float];  // For importing back into tensorflow.
79   scale:[float];  // For dequantizing the tensor's values.
80   zero_point:[long];
81
82   // If this is not none, the other quantization parameters (i.e. min, max,
83   // scale, zero_point fields above) are ignored and the value of the
84   // QuantizationDetails union should be used.
85   details:QuantizationDetails;
86
87   // Specifies the dimension of the Tensor's shape that the scales and
88   // zero_points correspond to. For example, a tensor t, with dims=[4, 3, 2, 1]
89   // with quantization params:
90   //   scale=[1.0, 2.0, 3.0], zero_point=[1, 2, 3], quantization_dimension=1
91   // will be quantized across the second dimension of t.
92   //   t[:, 0, :, :] will have scale[0]=1.0, zero_point[0]=1
93   //   t[:, 1, :, :] will have scale[1]=2.0, zero_point[0]=2
94   //   t[:, 2, :, :] will have scale[2]=3.0, zero_point[0]=3
95   quantized_dimension:int;
96 }
97
98 // Sparse tensors.
99 // We use a modification of the TACO format.
100 // Reference: http://tensor-compiler.org/kjolstad-oopsla17-tensor-compiler.pdf
101 //
102 // To encode a conceptual n-dimensional dense tensor with dims (d0, ..., dn-1),
103 // potentially with a k-dimensional block (0 <= k <= n) with dims
104 // (dn, ..., dn+k-1), the format needs to specify:
105 //   1. In what order to traverse these dimensions. For example, to store a 2-D
106 //      matrix in row major order, the traversal order would be (d0, d1),
107 //      whereas to store it in column major order, the traversal order would be
108 //      (d1, d0). If the 2-D matrix has a 2-D inner block, the traversal order
109 //      could be (d0, d1, d2, d3).
110 //   2. How each block dimension in (dn, ..., dn+k-1) maps to the original
111 //      tensor dimension in (d0, ..., dn-1).
112 //   3. In the traversal order defined above, the format (dense vs. sparse) and
113 //      index metadata for each dimension. For a dense dimension, this is just
114 //      the size of that dimension. For a sparse dimension, it's the same as
115 //      the compressed index defined in the Compressed Sparse Row (CSR) format.
116 //      (http://scipy-lectures.org/advanced/scipy_sparse/csr_matrix.html)
117
118 // The storage type for a dimension. Currently we support:
119 //   1. DENSE: each coordinate in this dimension is stored implicitly.
120 //   2. SPARSE_CSR: only the coordinates with non-zero elements are stored. The
121 //      compression technique is the same what CSR uses.
122 // More types like a sparse dimension with a different compression technique
123 // could be added to the list in the future.
124 enum DimensionType : byte {
125   DENSE = 0,
126   SPARSE_CSR = 1,
127 }
128
129 table Int32Vector {
130   values:[int];
131 }
132
133 table Uint16Vector {
134   values:[ushort] (force_align: 4);
135 }
136
137 table Uint8Vector {
138   values:[ubyte] (force_align: 4);
139 }
140
141 // Variable-typed buffer to store the index metadata for a sparse dimension.
142 // The widest type is Int32 instead of UInt32 because tensor's shape is a int32
143 // vector. We don't want the per-dimensional index to overflow that range.
144 union SparseIndexVector {
145   Int32Vector,
146   Uint16Vector,
147   Uint8Vector
148 }
149
150 table DimensionMetadata {
151   // Whether a dimension is dense or sparse.
152   format:DimensionType;
153   // Index metadata used for a dimension.
154   //   - If format is DimensionType.DENSE then we use the dense_size field to
155   //     store the size of that dimension. Each index in that dimension is
156   //     stored implicitly.
157   //   - If format is DimensionType.SPARSE_CSR then we use array_segments and
158   //     array_indices to encode that dimension. array_segments represents how
159   //     to segment the indices array, each segment corresponds to one element
160   //     in the previous dimension. array_indices represents the index of the
161   //     non-zero elements within this dimension (as those in the CSR matrix
162   //     format, where the first array is row pointers and the second array is
163   //     column indices).
164   dense_size:int;
165   array_segments:SparseIndexVector;
166   array_indices:SparseIndexVector;
167 }
168
169 // Parameters to encode a sparse TfLite tensor.
170 table SparsityParameters {
171   // The traversal order of the dimensions defined in the `shape` field of the
172   // conceptual dense tensor. For a n-dimensional tensors with dims (d0, d1,
173   // ..., dn-1),
174   //   - if not block sparse, the traversal_order is just a permutation of (d0,
175   //     ..., dn-1). For example, a 2-D matrix stored in row-major order would
176   //     have traversal_order = (d0, d1).
177   //   - if block sparse with a k-dimensional block (0 <= k <= n), the
178   //     traversal_order has n + k elements. The first n elements are still a
179   //     permutation of (d0, ..., dn-1). The lask k elements are a permutation
180   //     of (dn, ..., dn+k-1), defining how to traverse a block internally. For
181   //     example, a 2-D matrix with 2-D blocks, both stored in row-major order
182   //     would have traversal_order = (d0, d1, d2, d3).
183   traversal_order:[int];
184   // For an n-dimensional tensor with a k-dimensional block (0 <= k <= n),
185   // stores how a block dimension in (dn, ..., dn+k-1) maps to the original
186   // tensor dimension in (d0, ..., dn).
187   // It's stored in the order of (dn, ..., dn+k-1).
188   // If not block-sparse, this field is NULL.
189   block_map:[int];
190   // In the traversal order defined above, the metadata needed for
191   // each dimension to locate the non-zero values in the original dense tensor.
192   // The size of the dim_metadata array = the size of the traversal_order array
193   // = n + k.
194   dim_metadata:[DimensionMetadata];
195 }
196
197 // The nested tensor type for VARIANT type.
198 table VariantSubType {
199   // The tensor shape.
200   shape:[int];
201   type:TensorType;
202   // If false, the rank or the number of tensor dimensions is unknown.
203   // If false, "shape" must be [].
204   has_rank: bool = false;
205 }
206
207 table Tensor {
208   // The tensor shape. The meaning of each entry is operator-specific but
209   // builtin ops use: [batch size, height, width, number of channels] (That's
210   // Tensorflow's NHWC).
211   shape:[int];
212   type:TensorType;
213   // An index that refers to the buffers table at the root of the model. Or,
214   // if there is no data buffer associated (i.e. intermediate results), then
215   // this is 0 (which refers to an always existent empty buffer).
216   //
217   // The data_buffer itself is an opaque container, with the assumption that the
218   // target device is little-endian. In addition, all builtin operators assume
219   // the memory is ordered such that if `shape` is [4, 3, 2], then index
220   // [i, j, k] maps to data_buffer[i*3*2 + j*2 + k].
221   buffer:uint;
222   name:string;  // For debugging and importing back into tensorflow.
223   quantization:QuantizationParameters;  // Optional.
224
225   is_variable:bool = false;
226
227   // Parameters to encode a sparse tensor. See the example in
228   // tensorflow/lite/testdata/sparse_tensor.json.
229   sparsity:SparsityParameters;  // Optional.
230
231   // Encodes `shape` with unknown dimensions. Unknown dimensions are
232   // represented with -1.
233   shape_signature:[int]; // Optional.
234
235   // If false, the rank or the number of tensor dimensions is unknown.
236   // If false, "shape" must be [].
237   has_rank: bool = false;
238
239   // The nested Tensor types for VARIANT type. This is always empty for
240   // non-VARIANT types. This is optional because the nested type can be omitted.
241   // Currently only 1 subtype is supported. The field is defined as an array for
242   // flexibility of supporting multiple subtypes in the future.
243   variant_tensors:[VariantSubType];
244 }
245
246 // A list of builtin operators. Builtin operators are slightly faster than custom
247 // ones, but not by much. Moreover, while custom operators accept an opaque
248 // object containing configuration parameters, builtins have a predetermined
249 // set of acceptable options.
250 // LINT.IfChange
251 enum BuiltinOperator : int32 {
252   ADD = 0,
253   AVERAGE_POOL_2D = 1,
254   CONCATENATION = 2,
255   CONV_2D = 3,
256   DEPTHWISE_CONV_2D = 4,
257   DEPTH_TO_SPACE = 5,
258   DEQUANTIZE = 6,
259   EMBEDDING_LOOKUP = 7,
260   FLOOR = 8,
261   FULLY_CONNECTED = 9,
262   HASHTABLE_LOOKUP = 10,
263   L2_NORMALIZATION = 11,
264   L2_POOL_2D = 12,
265   LOCAL_RESPONSE_NORMALIZATION = 13,
266   LOGISTIC = 14,
267   LSH_PROJECTION = 15,
268   LSTM = 16,
269   MAX_POOL_2D = 17,
270   MUL = 18,
271   RELU = 19,
272   // NOTE(aselle): RELU_N1_TO_1 used to be called RELU1, but it was renamed
273   // since different model developers use RELU1 in different ways. Never
274   // create another op called RELU1.
275   RELU_N1_TO_1 = 20,
276   RELU6 = 21,
277   RESHAPE = 22,
278   RESIZE_BILINEAR = 23,
279   RNN = 24,
280   SOFTMAX = 25,
281   SPACE_TO_DEPTH = 26,
282   SVDF = 27,
283   TANH = 28,
284   CONCAT_EMBEDDINGS = 29,
285   SKIP_GRAM = 30,
286   CALL = 31,
287   CUSTOM = 32,
288   EMBEDDING_LOOKUP_SPARSE = 33,
289   PAD = 34,
290   UNIDIRECTIONAL_SEQUENCE_RNN = 35,
291   GATHER = 36,
292   BATCH_TO_SPACE_ND = 37,
293   SPACE_TO_BATCH_ND = 38,
294   TRANSPOSE = 39,
295   MEAN = 40,
296   SUB = 41,
297   DIV = 42,
298   SQUEEZE = 43,
299   UNIDIRECTIONAL_SEQUENCE_LSTM = 44,
300   STRIDED_SLICE = 45,
301   BIDIRECTIONAL_SEQUENCE_RNN = 46,
302   EXP = 47,
303   TOPK_V2 = 48,
304   SPLIT = 49,
305   LOG_SOFTMAX = 50,
306   // DELEGATE is a special op type for the operations which are delegated to
307   // other backends.
308   // WARNING: Experimental interface, subject to change
309   DELEGATE = 51,
310   BIDIRECTIONAL_SEQUENCE_LSTM = 52,
311   CAST = 53,
312   PRELU = 54,
313   MAXIMUM = 55,
314   ARG_MAX = 56,
315   MINIMUM = 57,
316   LESS = 58,
317   NEG = 59,
318   PADV2 = 60,
319   GREATER = 61,
320   GREATER_EQUAL = 62,
321   LESS_EQUAL = 63,
322   SELECT = 64,
323   SLICE = 65,
324   SIN = 66,
325   TRANSPOSE_CONV = 67,
326   SPARSE_TO_DENSE = 68,
327   TILE = 69,
328   EXPAND_DIMS = 70,
329   EQUAL = 71,
330   NOT_EQUAL = 72,
331   LOG = 73,
332   SUM = 74,
333   SQRT = 75,
334   RSQRT = 76,
335   SHAPE = 77,
336   POW = 78,
337   ARG_MIN = 79,
338   FAKE_QUANT = 80,
339   REDUCE_PROD = 81,
340   REDUCE_MAX = 82,
341   PACK = 83,
342   LOGICAL_OR = 84,
343   ONE_HOT = 85,
344   LOGICAL_AND = 86,
345   LOGICAL_NOT = 87,
346   UNPACK = 88,
347   REDUCE_MIN = 89,
348   FLOOR_DIV = 90,
349   REDUCE_ANY = 91,
350   SQUARE = 92,
351   ZEROS_LIKE = 93,
352   FILL = 94,
353   FLOOR_MOD = 95,
354   RANGE = 96,
355   RESIZE_NEAREST_NEIGHBOR = 97,
356   LEAKY_RELU = 98,
357   SQUARED_DIFFERENCE = 99,
358   MIRROR_PAD = 100,
359   ABS = 101,
360   SPLIT_V = 102,
361   UNIQUE = 103,
362   CEIL = 104,
363   REVERSE_V2 = 105,
364   ADD_N = 106,
365   GATHER_ND = 107,
366   COS = 108,
367   WHERE = 109,
368   RANK = 110,
369   ELU = 111,
370   REVERSE_SEQUENCE = 112,
371   MATRIX_DIAG = 113,
372   QUANTIZE = 114,
373   MATRIX_SET_DIAG = 115,
374   ROUND = 116,
375   HARD_SWISH = 117,
376   IF = 118,
377   WHILE = 119,
378   NON_MAX_SUPPRESSION_V4 = 120,
379   NON_MAX_SUPPRESSION_V5 = 121,
380   SCATTER_ND = 122,
381   SELECT_V2 = 123,
382   DENSIFY = 124,
383   SEGMENT_SUM = 125,
384   BATCH_MATMUL = 126,
385   PLACEHOLDER_FOR_GREATER_OP_CODES = 127,
386   CUMSUM = 128,
387   CALL_ONCE = 129,
388   BROADCAST_TO = 130,
389   RFFT2D = 131,
390   CONV_3D = 132,
391   IMAG=133,
392   REAL=134,
393   COMPLEX_ABS=135,
394   HASHTABLE = 136,
395   HASHTABLE_FIND = 137,
396   HASHTABLE_IMPORT = 138,
397   HASHTABLE_SIZE = 139,
398   REDUCE_ALL = 140,
399   CONV_3D_TRANSPOSE = 141,
400   VAR_HANDLE = 142,
401   READ_VARIABLE = 143,
402   ASSIGN_VARIABLE = 144,
403   BROADCAST_ARGS = 145,
404   RANDOM_STANDARD_NORMAL = 146,
405   BUCKETIZE = 147,
406   RANDOM_UNIFORM = 148,
407   MULTINOMIAL = 149,
408   GELU = 150,
409   DYNAMIC_UPDATE_SLICE = 151,
410   RELU_0_TO_1 = 152,
411   UNSORTED_SEGMENT_PROD = 153,
412   UNSORTED_SEGMENT_MAX = 154,
413   UNSORTED_SEGMENT_SUM = 155,
414   ATAN2 = 156,
415   UNSORTED_SEGMENT_MIN = 157,
416   SIGN = 158
417 }
418 // LINT.ThenChange(nnapi_linter/linter.proto)
419
420 // Options for the builtin operators.
421 union BuiltinOptions {
422   Conv2DOptions,
423   DepthwiseConv2DOptions,
424   ConcatEmbeddingsOptions,
425   LSHProjectionOptions,
426   Pool2DOptions,
427   SVDFOptions,
428   RNNOptions,
429   FullyConnectedOptions,
430   SoftmaxOptions,
431   ConcatenationOptions,
432   AddOptions,
433   L2NormOptions,
434   LocalResponseNormalizationOptions,
435   LSTMOptions,
436   ResizeBilinearOptions,
437   CallOptions,
438   ReshapeOptions,
439   SkipGramOptions,
440   SpaceToDepthOptions,
441   EmbeddingLookupSparseOptions,
442   MulOptions,
443   PadOptions,
444   GatherOptions,
445   BatchToSpaceNDOptions,
446   SpaceToBatchNDOptions,
447   TransposeOptions,
448   ReducerOptions,
449   SubOptions,
450   DivOptions,
451   SqueezeOptions,
452   SequenceRNNOptions,
453   StridedSliceOptions,
454   ExpOptions,
455   TopKV2Options,
456   SplitOptions,
457   LogSoftmaxOptions,
458   CastOptions,
459   DequantizeOptions,
460   MaximumMinimumOptions,
461   ArgMaxOptions,
462   LessOptions,
463   NegOptions,
464   PadV2Options,
465   GreaterOptions,
466   GreaterEqualOptions,
467   LessEqualOptions,
468   SelectOptions,
469   SliceOptions,
470   TransposeConvOptions,
471   SparseToDenseOptions,
472   TileOptions,
473   ExpandDimsOptions,
474   EqualOptions,
475   NotEqualOptions,
476   ShapeOptions,
477   PowOptions,
478   ArgMinOptions,
479   FakeQuantOptions,
480   PackOptions,
481   LogicalOrOptions,
482   OneHotOptions,
483   LogicalAndOptions,
484   LogicalNotOptions,
485   UnpackOptions,
486   FloorDivOptions,
487   SquareOptions,
488   ZerosLikeOptions,
489   FillOptions,
490   BidirectionalSequenceLSTMOptions,
491   BidirectionalSequenceRNNOptions,
492   UnidirectionalSequenceLSTMOptions,
493   FloorModOptions,
494   RangeOptions,
495   ResizeNearestNeighborOptions,
496   LeakyReluOptions,
497   SquaredDifferenceOptions,
498   MirrorPadOptions,
499   AbsOptions,
500   SplitVOptions,
501   UniqueOptions,
502   ReverseV2Options,
503   AddNOptions,
504   GatherNdOptions,
505   CosOptions,
506   WhereOptions,
507   RankOptions,
508   ReverseSequenceOptions,
509   MatrixDiagOptions,
510   QuantizeOptions,
511   MatrixSetDiagOptions,
512   HardSwishOptions,
513   IfOptions,
514   WhileOptions,
515   DepthToSpaceOptions,
516   NonMaxSuppressionV4Options,
517   NonMaxSuppressionV5Options,
518   ScatterNdOptions,
519   SelectV2Options,
520   DensifyOptions,
521   SegmentSumOptions,
522   BatchMatMulOptions,
523   CumsumOptions,
524   CallOnceOptions,
525   BroadcastToOptions,
526   Rfft2dOptions,
527   Conv3DOptions,
528   HashtableOptions,
529   HashtableFindOptions,
530   HashtableImportOptions,
531   HashtableSizeOptions,
532   VarHandleOptions,
533   ReadVariableOptions,
534   AssignVariableOptions,
535   RandomOptions,
536   BucketizeOptions,
537   GeluOptions,
538   DynamicUpdateSliceOptions,
539   UnsortedSegmentProdOptions,
540   UnsortedSegmentMaxOptions,
541   UnsortedSegmentMinOptions,
542   UnsortedSegmentSumOptions,
543   ATan2Options,
544   SignOptions
545 }
546
547 // LINT.IfChange
548 enum Padding : byte { SAME, VALID }
549 // LINT.ThenChange(//tensorflow/compiler/mlir/lite/ir/tfl_op_enums.td)
550
551 // LINT.IfChange
552 enum ActivationFunctionType : byte {
553   NONE = 0,
554   RELU = 1,
555   RELU_N1_TO_1 = 2,
556   RELU6 = 3,
557   TANH = 4,
558   SIGN_BIT = 5,
559 }
560 // LINT.ThenChange(//tensorflow/compiler/mlir/lite/ir/tfl_op_enums.td)
561
562 table Conv2DOptions {
563   padding:Padding;
564   stride_w:int;
565   stride_h:int;
566   fused_activation_function:ActivationFunctionType;
567   dilation_w_factor:int = 1;
568   dilation_h_factor:int = 1;
569 }
570
571 // Options for both Conv3D and Conv3DTranspose.
572 table Conv3DOptions {
573   padding:Padding;
574   stride_d:int;
575   stride_w:int;
576   stride_h:int;
577   fused_activation_function:ActivationFunctionType;
578   dilation_d_factor:int = 1;
579   dilation_w_factor:int = 1;
580   dilation_h_factor:int = 1;
581 }
582
583 table Pool2DOptions {
584   padding:Padding;
585   stride_w:int;
586   stride_h:int;
587   filter_width:int;
588   filter_height:int;
589   fused_activation_function:ActivationFunctionType;
590 }
591
592 table DepthwiseConv2DOptions {
593   // Parameters for DepthwiseConv version 1 or above.
594   padding:Padding;
595   stride_w:int;
596   stride_h:int;
597   // `depth_multiplier` is redundant. It's used by CPU kernels in
598   // TensorFlow 2.0 or below, but ignored in versions above.
599   // See comments in lite/c/builtin_op_data.h for more details.
600   depth_multiplier:int;
601   fused_activation_function:ActivationFunctionType;
602   // Parameters for DepthwiseConv version 2 or above.
603   dilation_w_factor:int = 1;
604   dilation_h_factor:int = 1;
605 }
606
607 table ConcatEmbeddingsOptions {
608   num_channels:int;
609   num_columns_per_channel:[int];
610   embedding_dim_per_channel:[int]; // This could be inferred from parameters.
611 }
612
613 enum LSHProjectionType: byte {
614   UNKNOWN = 0,
615   SPARSE = 1,
616   DENSE = 2,
617 }
618
619 table LSHProjectionOptions {
620   type: LSHProjectionType;
621 }
622
623 table SVDFOptions {
624   rank:int;
625   fused_activation_function:ActivationFunctionType;
626   // For weights-only quantization, use asymmetric quantization for non
627   // constant inputs at evaluation time.
628   asymmetric_quantize_inputs:bool;
629 }
630
631 // An implementation of TensorFlow RNNCell.
632 table RNNOptions {
633   fused_activation_function:ActivationFunctionType;
634   asymmetric_quantize_inputs:bool;
635 }
636
637 // An implementation of TensorFlow dynamic_rnn with RNNCell.
638 table SequenceRNNOptions {
639   time_major:bool;
640   fused_activation_function:ActivationFunctionType;
641   asymmetric_quantize_inputs:bool;
642 }
643
644 // An implementation of TensorFlow bidrectional_dynamic_rnn with RNNCell.
645 table BidirectionalSequenceRNNOptions {
646   time_major:bool;
647   fused_activation_function:ActivationFunctionType;
648   merge_outputs: bool;
649   asymmetric_quantize_inputs:bool;
650 }
651
652 // LINT.IfChange
653 enum FullyConnectedOptionsWeightsFormat: byte {
654   DEFAULT = 0,
655   SHUFFLED4x16INT8 = 1,
656 }
657 // LINT.ThenChange(//tensorflow/compiler/mlir/lite/ir/tfl_op_enums.td)
658
659 // An implementation of TensorFlow fully_connected (a.k.a Dense) layer.
660 table FullyConnectedOptions {
661   // Parameters for FullyConnected version 1 or above.
662   fused_activation_function:ActivationFunctionType;
663
664   // Parameters for FullyConnected version 2 or above.
665   weights_format:FullyConnectedOptionsWeightsFormat = DEFAULT;
666
667   // Parameters for FullyConnected version 5 or above.
668   // If set to true, then the number of dimension is preserved. Furthermore,
669   // all but the last dimension of the input and output shapes will be equal.
670   keep_num_dims: bool;
671
672   // Parameters for FullyConnected version 7 or above.
673   // If set to true, then weights-only op will use asymmetric quantization for
674   // inputs.
675   asymmetric_quantize_inputs: bool;
676 }
677
678 table SoftmaxOptions {
679   beta: float;
680 }
681
682 // An implementation of TensorFlow concat.
683 table ConcatenationOptions {
684   axis:int;
685   fused_activation_function:ActivationFunctionType;
686 }
687
688 table AddOptions {
689   fused_activation_function:ActivationFunctionType;
690   // Parameters supported by version 3.
691   pot_scale_int16:bool = true;
692 }
693
694 table MulOptions {
695   fused_activation_function:ActivationFunctionType;
696 }
697
698 table L2NormOptions {
699   // This field is currently ignored in the L2 Norm Op.
700   fused_activation_function:ActivationFunctionType;
701 }
702
703 table LocalResponseNormalizationOptions {
704   radius:int;
705   bias:float;
706   alpha:float;
707   beta:float;
708 }
709
710 // LINT.IfChange
711 enum LSTMKernelType : byte {
712   // Full LSTM kernel which supports peephole and projection.
713   FULL = 0,
714   // Basic LSTM kernels. Equivalent to TensorFlow BasicLSTMCell.
715   BASIC = 1,
716 }
717 // LINT.ThenChange(//tensorflow/compiler/mlir/lite/ir/tfl_op_enums.td)
718
719 // An implementation of TensorFlow LSTMCell and CoupledInputForgetGateLSTMCell
720 table LSTMOptions {
721   // Parameters for LSTM version 1 or above.
722   fused_activation_function:ActivationFunctionType;
723   cell_clip: float; // Optional, 0.0 means no clipping
724   proj_clip: float; // Optional, 0.0 means no clipping
725
726   // Parameters for LSTM version 2 or above.
727   // Basic kernel is only supported in version 2 or above.
728   kernel_type: LSTMKernelType = FULL;
729
730   // Parameters for LSTM version 4 or above.
731   asymmetric_quantize_inputs: bool;
732 }
733
734 // An implementation of TensorFlow dynamic_rnn with LSTMCell.
735 table UnidirectionalSequenceLSTMOptions {
736   fused_activation_function:ActivationFunctionType;
737   cell_clip: float; // Optional, 0.0 means no clipping
738   proj_clip: float; // Optional, 0.0 means no clipping
739
740   // If true then first dimension is sequence, otherwise batch.
741   time_major:bool;
742
743   // Parameter for Unidirectional Sequence LSTM version 3.
744   asymmetric_quantize_inputs:bool;
745
746   // Parameter for unidirectional sequence RNN version 4.
747   diagonal_recurrent_tensors:bool;
748 }
749
750 table BidirectionalSequenceLSTMOptions {
751   // Parameters supported by version 1:
752   fused_activation_function:ActivationFunctionType;
753   cell_clip: float; // Optional, 0.0 means no clipping
754   proj_clip: float; // Optional, 0.0 means no clipping
755
756   // If true, store the outputs of both directions into the first output.
757   merge_outputs: bool;
758
759   // Parameters supported by version 2:
760   // If true then first dimension is sequence, otherwise batch.
761   // Version 1 implementations assumed time_major to be true, so this default
762   // value should never change.
763   time_major: bool = true;
764
765   // Parameters for version 3 or above.
766   asymmetric_quantize_inputs:bool;
767 }
768
769 table ResizeBilinearOptions {
770   new_height: int (deprecated);
771   new_width: int (deprecated);
772   align_corners: bool;
773   half_pixel_centers: bool;
774 }
775
776 table ResizeNearestNeighborOptions {
777   align_corners: bool;
778   half_pixel_centers: bool;
779 }
780
781 // A call operation options
782 table CallOptions {
783   // The subgraph index that needs to be called.
784   subgraph:uint;
785 }
786
787 table PadOptions {
788 }
789
790 table PadV2Options {
791 }
792
793 table ReshapeOptions {
794   new_shape:[int];
795 }
796
797 table SpaceToBatchNDOptions {
798 }
799
800 table BatchToSpaceNDOptions {
801 }
802
803 table SkipGramOptions {
804   ngram_size: int;
805   max_skip_size: int;
806   include_all_ngrams: bool;
807 }
808
809 table SpaceToDepthOptions {
810   block_size: int;
811 }
812
813 table DepthToSpaceOptions {
814   block_size: int;
815 }
816
817 table SubOptions {
818   fused_activation_function:ActivationFunctionType;
819   // Parameters supported by version 5
820   pot_scale_int16:bool = true;
821 }
822
823 table DivOptions {
824   fused_activation_function:ActivationFunctionType;
825 }
826
827 table TopKV2Options {
828 }
829
830 enum CombinerType : byte {
831   SUM = 0,
832   MEAN = 1,
833   SQRTN = 2,
834 }
835
836 table EmbeddingLookupSparseOptions {
837   combiner:CombinerType;
838 }
839
840 table GatherOptions {
841   axis: int;
842   // Parameters for Gather version 5 or above.
843   batch_dims: int = 0;
844 }
845
846 table TransposeOptions {
847 }
848
849 table ExpOptions {
850 }
851
852 table CosOptions {
853 }
854
855 table ReducerOptions {
856   keep_dims: bool;
857 }
858
859 table SqueezeOptions {
860   squeeze_dims:[int];
861 }
862
863 table SplitOptions {
864   num_splits: int;
865 }
866
867 table SplitVOptions {
868   num_splits: int;
869 }
870
871 table StridedSliceOptions {
872   begin_mask: int;
873   end_mask: int;
874   ellipsis_mask: int;
875   new_axis_mask: int;
876   shrink_axis_mask: int;
877 }
878
879 table LogSoftmaxOptions {
880 }
881
882 table CastOptions {
883   in_data_type: TensorType;
884   out_data_type: TensorType;
885 }
886
887 table DequantizeOptions {
888 }
889
890 table MaximumMinimumOptions {
891 }
892
893 table TileOptions {
894 }
895
896 table ArgMaxOptions {
897   output_type : TensorType;
898 }
899
900 table ArgMinOptions {
901   output_type : TensorType;
902 }
903
904 table GreaterOptions {
905 }
906
907 table GreaterEqualOptions {
908 }
909
910 table LessOptions {
911 }
912
913 table LessEqualOptions {
914 }
915
916 table NegOptions {
917 }
918
919 table SelectOptions {
920 }
921
922 table SliceOptions {
923 }
924
925 table TransposeConvOptions {
926   // Parameters supported by version 1, 2, 3:
927   padding:Padding;
928   stride_w:int;
929   stride_h:int;
930
931   // Parameters supported by version 4:
932   fused_activation_function:ActivationFunctionType = NONE;
933 }
934
935 table ExpandDimsOptions {
936 }
937
938 table SparseToDenseOptions {
939   validate_indices:bool;
940 }
941
942 table EqualOptions {
943 }
944
945 table NotEqualOptions {
946 }
947
948 table ShapeOptions {
949   // Optional output type of the operation (int32 or int64). Defaults to int32.
950   out_type : TensorType;
951 }
952
953 table RankOptions {
954 }
955
956 table PowOptions {
957 }
958
959 table FakeQuantOptions {
960   // Parameters supported by version 1:
961   min:float;
962   max:float;
963   num_bits:int;
964
965   // Parameters supported by version 2:
966   narrow_range:bool;
967 }
968
969 table PackOptions {
970   values_count:int;
971   axis:int;
972 }
973
974 table LogicalOrOptions {
975 }
976
977 table OneHotOptions {
978   axis:int;
979 }
980
981 table AbsOptions {
982 }
983
984
985 table HardSwishOptions {
986 }
987
988 table LogicalAndOptions {
989 }
990
991 table LogicalNotOptions {
992 }
993
994 table UnpackOptions {
995   num:int;
996   axis:int;
997 }
998
999 table FloorDivOptions {
1000 }
1001
1002 table SquareOptions {
1003 }
1004
1005 table ZerosLikeOptions {
1006 }
1007
1008 table FillOptions {
1009 }
1010
1011 table FloorModOptions {
1012 }
1013
1014 table RangeOptions {
1015 }
1016
1017 table LeakyReluOptions {
1018   alpha:float;
1019 }
1020
1021 table SquaredDifferenceOptions {
1022 }
1023
1024 // LINT.IfChange
1025 enum MirrorPadMode : byte {
1026   // Doesn't include borders.
1027   REFLECT = 0,
1028   // Includes borders.
1029   SYMMETRIC = 1,
1030 }
1031 // LINT.ThenChange(//tensorflow/compiler/mlir/lite/ir/tfl_op_enums.td)
1032
1033 table MirrorPadOptions {
1034   mode:MirrorPadMode;
1035 }
1036
1037 table UniqueOptions {
1038   idx_out_type:TensorType = INT32;
1039 }
1040
1041 table ReverseV2Options {
1042 }
1043
1044 table AddNOptions {
1045 }
1046
1047 table GatherNdOptions {
1048 }
1049
1050 table WhereOptions {
1051 }
1052
1053 table ReverseSequenceOptions {
1054   seq_dim:int;
1055   batch_dim:int = 0;
1056 }
1057
1058 table MatrixDiagOptions {
1059 }
1060
1061 table QuantizeOptions {
1062 }
1063
1064 table MatrixSetDiagOptions {
1065 }
1066
1067 table IfOptions {
1068   then_subgraph_index:int;
1069   else_subgraph_index:int;
1070 }
1071
1072 table CallOnceOptions {
1073   init_subgraph_index:int;
1074 }
1075
1076 table WhileOptions {
1077   cond_subgraph_index:int;
1078   body_subgraph_index:int;
1079 }
1080
1081 table NonMaxSuppressionV4Options {
1082 }
1083
1084 table NonMaxSuppressionV5Options {
1085 }
1086
1087 table ScatterNdOptions {
1088 }
1089
1090 table SelectV2Options {
1091 }
1092
1093 table DensifyOptions {
1094 }
1095
1096 table SegmentSumOptions {
1097 }
1098
1099 table BatchMatMulOptions {
1100   adj_x:bool;
1101   adj_y:bool;
1102   // Parameters for BatchMatMul version 4 or above.
1103   // If set to true, then weights-only op will use asymmetric quantization for
1104   // inputs.
1105   asymmetric_quantize_inputs: bool;
1106 }
1107
1108 table CumsumOptions {
1109   exclusive:bool;
1110   reverse:bool;
1111 }
1112
1113 table BroadcastToOptions {
1114 }
1115
1116 table Rfft2dOptions {
1117 }
1118
1119 table HashtableOptions {
1120   // The identity of hash tables. This identity will be used across different
1121   // subgraphs in the same interpreter instance.
1122   table_id:int;
1123   key_dtype:TensorType;
1124   value_dtype:TensorType;
1125 }
1126
1127 table HashtableFindOptions {
1128 }
1129
1130 table HashtableImportOptions {
1131 }
1132
1133 table HashtableSizeOptions {
1134 }
1135
1136 table VarHandleOptions {
1137   container:string;
1138   shared_name:string;
1139 }
1140
1141 table ReadVariableOptions {
1142 }
1143
1144 table AssignVariableOptions {
1145 }
1146
1147 table RandomOptions {
1148   seed: long;
1149   seed2: long;
1150 }
1151
1152 table BucketizeOptions {
1153   boundaries: [float];  // The bucket boundaries.
1154 }
1155
1156 table GeluOptions {
1157   approximate: bool;
1158 }
1159
1160 table DynamicUpdateSliceOptions {
1161 }
1162
1163 table UnsortedSegmentProdOptions {
1164 }
1165
1166 table UnsortedSegmentMaxOptions {
1167 }
1168
1169 table UnsortedSegmentSumOptions {
1170 }
1171
1172 table ATan2Options {
1173 }
1174
1175 table UnsortedSegmentMinOptions{
1176 }
1177
1178 table SignOptions {
1179 }
1180
1181
1182 // An OperatorCode can be an enum value (BuiltinOperator) if the operator is a
1183 // builtin, or a string if the operator is custom.
1184 table OperatorCode {
1185   // This field is for backward compatibility. This field will be used when
1186   // the value of the extended builtin_code field has less than
1187   // BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
1188   deprecated_builtin_code:byte;
1189   custom_code:string;
1190
1191   // The version of the operator. The version need to be bumped whenever new
1192   // parameters are introduced into an op.
1193   version:int = 1;
1194
1195   // This field is introduced for resolving op builtin code shortage problem
1196   // (the original BuiltinOperator enum field was represented as a byte).
1197   // This field will be used when the value of the extended builtin_code field
1198   // has greater than BulitinOperator_PLACEHOLDER_FOR_GREATER_OP_CODES.
1199   builtin_code:BuiltinOperator;
1200 }
1201
1202 enum CustomOptionsFormat : byte {
1203   FLEXBUFFERS = 0,
1204 }
1205
1206 // An operator takes tensors as inputs and outputs. The type of operation being
1207 // performed is determined by an index into the list of valid OperatorCodes,
1208 // while the specifics of each operations is configured using builtin_options
1209 // or custom_options.
1210 table Operator {
1211   // Index into the operator_codes array. Using an integer here avoids
1212   // complicate map lookups.
1213   opcode_index:uint;
1214
1215   // Optional input are indicated by -1.
1216   inputs:[int];
1217   outputs:[int];
1218
1219   builtin_options:BuiltinOptions;
1220   custom_options:[ubyte];
1221   custom_options_format:CustomOptionsFormat;
1222
1223   // A list of booleans indicating the input tensors which are being mutated by
1224   // this operator.(e.g. used by RNN and LSTM).
1225   // For example, if the "inputs" array refers to 5 tensors and the second and
1226   // fifth are mutable variables, then this list will contain
1227   // [false, true, false, false, true].
1228   //
1229   // If the list is empty, no variable is mutated in this operator.
1230   // The list either has the same length as `inputs`, or is empty.
1231   mutating_variable_inputs:[bool];
1232
1233   // A list of indices to the subgraph's "tensors" that are internal to an Op.
1234   // Internal tensors are those that do not flow in or out of the operation,
1235   // but instead are part of internal computation. As such, the operation's
1236   // implementation may manage its memory more efficiently. They are needed
1237   // however (i.e. not just an implementation detail) since they are part of the
1238   // computation, which may require relevant metadata such as quantization
1239   // parameters.
1240   intermediates:[int];
1241 }
1242
1243 // The root type, defining a subgraph, which typically represents an entire
1244 // model.
1245 table SubGraph {
1246   // A list of all tensors used in this subgraph.
1247   tensors:[Tensor];
1248
1249   // Indices of the tensors that are inputs into this subgraph. Note this is
1250   // the list of non-static tensors that feed into the subgraph for inference.
1251   inputs:[int];
1252
1253   // Indices of the tensors that are outputs out of this subgraph. Note this is
1254   // the list of output tensors that are considered the product of the
1255   // subgraph's inference.
1256   outputs:[int];
1257
1258   // All operators, in execution order.
1259   operators:[Operator];
1260
1261   // Name of this subgraph (used for debugging).
1262   name:string;
1263 }
1264
1265 // Table of raw data buffers (used for constant tensors). Referenced by tensors
1266 // by index. The generous alignment accommodates mmap-friendly data structures.
1267 table Buffer {
1268   data:[ubyte] (force_align: 16);
1269 }
1270
1271 table Metadata {
1272   // A human readable string to uniquely identify a Metadata.
1273   name:string;
1274   // An index to the buffers table.
1275   buffer:uint;
1276 }
1277
1278 // Map from an alias name of tensor to tensor index in the graph.
1279 // This is used in Signature def.
1280 table TensorMap {
1281   // Represents the alias to use for this tensor.
1282   name:string;
1283
1284   // The actual tensor index in the primary graph, that 'name' corresponds to.
1285   tensor_index:uint;
1286 }
1287
1288 // This corresponds to SignatureDef in Tensorflow SavedModel.
1289 // The SignatureDef will be part of the SavedModel provided for conversion.
1290 table SignatureDef {
1291   // Named inputs for this signature.
1292   inputs:[TensorMap];
1293
1294   // Named outputs for this signature.
1295   outputs:[TensorMap];
1296
1297   // Key value which was in the Tensorflow SavedModel SignatureDef map.
1298   signature_key:string;
1299
1300   // Model tag, deprecated.
1301   deprecated_tag:string (deprecated);
1302
1303   // Index of subgraphs that corresponds to the exported method.
1304   subgraph_index:uint;
1305 }
1306
1307 table Model {
1308   // Version of the schema.
1309   version:uint;
1310
1311   // A list of all operator codes used in this model. This is
1312   // kept in order because operators carry an index into this
1313   // vector.
1314   operator_codes:[OperatorCode];
1315
1316   // All the subgraphs of the model. The 0th is assumed to be the main
1317   // model.
1318   subgraphs:[SubGraph];
1319
1320   // A description of the model.
1321   description:string;
1322
1323   // Buffers of the model.
1324   // Note the 0th entry of this array must be an empty buffer (sentinel).
1325   // This is a convention so that tensors without a buffer can provide 0 as
1326   // their buffer.
1327   buffers:[Buffer];
1328
1329   // Metadata about the model. Indirects into the existings buffers list.
1330   // Deprecated, prefer to use metadata field.
1331   metadata_buffer:[int];
1332
1333   // Metadata about the model.
1334   metadata:[Metadata];
1335
1336   // Optional SignatureDefs for the model.
1337   signature_defs:[SignatureDef];
1338 }
1339
1340 root_type Model;