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