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