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