A .tflite file is a FlatBuffers buffer with the file identifier
TFL3, defined by
schema.fbs
in the TensorFlow source (the same file is in LiteRT), read 2026-11-12. FlatBuffers
stores tables with offsets and a vtable, little-endian; fields are listed here in
schema order.
Model
| Field | Type | Meaning |
|---|---|---|
version | uint | Schema version, 3 (the schema’s comments list revisions 3a to 3d as compatible with 3). |
operator_codes | [OperatorCode] | Every operator kind used. |
subgraphs | [SubGraph] | The first is the main graph. |
description | string | A description of the model. |
buffers | [Buffer] | Buffer 0 is always empty. |
metadata_buffer | [int] | Deprecated. |
metadata | [Metadata] | Name and buffer index. |
signature_defs | [SignatureDef] | Optional named entry points with their input and output tensors. |
external_buffer_groups, external_buffers | [ExternalBufferGroup], [ExternalBuffer] | Version 3d: weights kept in external files, grouped by file or URI; each external buffer has an id, group index, offset, length and packing. |
Other tables
| Table | Fields |
|---|---|
| OperatorCode | deprecated_builtin_code (byte, used for codes below 127, PLACEHOLDER_FOR_GREATER_OP_CODES), custom_code, version (default 1), builtin_code (used for larger codes). |
| SubGraph | tensors, inputs, outputs (tensor indexes), operators, name, debug_metadata_index (default −1). |
| Tensor | shape, type, buffer (index; 0 means no constant data), name, quantization, is_variable, sparsity, shape_signature (−1 for unknown sizes), has_rank, variant_tensors, external_buffer. |
| Operator | opcode_index, inputs, outputs (−1 for an omitted optional input), builtin_options (a union by operator), custom_options, custom_options_format (FlexBuffers), mutating_variable_inputs, intermediates, large_custom_options_offset, large_custom_options_size, builtin_options_2, debug_metadata_index. |
| Buffer | data (bytes, aligned to 16), or, in a model larger than 2 GB, offset (from the start of the file, valid only if over 1) and size of data stored outside the FlatBuffer. |
| QuantizationParameters | min, max, scale, zero_point (per tensor or per channel), details, quantized_dimension. Real value = scale × (q − zero_point). |
Tensor types
| Code | Type | Code | Type |
|---|---|---|---|
| 0 | FLOAT32 | 10 | FLOAT64 |
| 1 | FLOAT16 | 11 | COMPLEX128 |
| 2 | INT32 | 12 | UINT64 |
| 3 | UINT8 | 13 | RESOURCE |
| 4 | INT64 | 14 | VARIANT |
| 5 | STRING | 15 | UINT32 |
| 6 | BOOL | 16 | UINT16 |
| 7 | INT16 | 17 | INT4 |
| 8 | COMPLEX64 | 18 | BFLOAT16 |
| 9 | INT8 | 19 | INT2 |
| 20 | UINT4 |
Builtin operators
The first codes of BuiltinOperator (0 to 32) are tabulated here; codes 33
to 209 follow in the complete list.
| Code | Operator | Code | Operator |
|---|---|---|---|
| 0 | ADD | 17 | MAX_POOL_2D |
| 1 | AVERAGE_POOL_2D | 18 | MUL |
| 2 | CONCATENATION | 19 | RELU |
| 3 | CONV_2D | 20 | RELU_N1_TO_1 |
| 4 | DEPTHWISE_CONV_2D | 21 | RELU6 |
| 5 | DEPTH_TO_SPACE | 22 | RESHAPE |
| 6 | DEQUANTIZE | 23 | RESIZE_BILINEAR |
| 7 | EMBEDDING_LOOKUP | 24 | RNN |
| 8 | FLOOR | 25 | SOFTMAX |
| 9 | FULLY_CONNECTED | 26 | SPACE_TO_DEPTH |
| 10 | HASHTABLE_LOOKUP | 27 | SVDF |
| 11 | L2_NORMALIZATION | 28 | TANH |
| 12 | L2_POOL_2D | 29 | CONCAT_EMBEDDINGS |
| 13 | LOCAL_RESPONSE_NORMALIZATION | 30 | SKIP_GRAM |
| 14 | LOGISTIC | 31 | CALL |
| 15 | LSH_PROJECTION | 32 | CUSTOM |
| 16 | LSTM |
Every builtin operator
BuiltinOperator (int32) from schema.fbs (the TensorFlow
repository's tensorflow/compiler/mlir/lite/schema/schema.fbs, read
2026-11-13). The schema marks code 127 as a placeholder for codes that do not fit the
old byte-sized field, and 205 as deprecated.
0 ADD, 1 AVERAGE_POOL_2D, 2 CONCATENATION, 3 CONV_2D, 4 DEPTHWISE_CONV_2D, 5 DEPTH_TO_SPACE, 6 DEQUANTIZE, 7 EMBEDDING_LOOKUP, 8 FLOOR, 9 FULLY_CONNECTED, 10 HASHTABLE_LOOKUP, 11 L2_NORMALIZATION, 12 L2_POOL_2D, 13 LOCAL_RESPONSE_NORMALIZATION, 14 LOGISTIC, 15 LSH_PROJECTION, 16 LSTM, 17 MAX_POOL_2D, 18 MUL, 19 RELU, 20 RELU_N1_TO_1, 21 RELU6, 22 RESHAPE, 23 RESIZE_BILINEAR, 24 RNN, 25 SOFTMAX, 26 SPACE_TO_DEPTH, 27 SVDF, 28 TANH, 29 CONCAT_EMBEDDINGS, 30 SKIP_GRAM, 31 CALL, 32 CUSTOM, 33 EMBEDDING_LOOKUP_SPARSE, 34 PAD, 35 UNIDIRECTIONAL_SEQUENCE_RNN, 36 GATHER, 37 BATCH_TO_SPACE_ND, 38 SPACE_TO_BATCH_ND, 39 TRANSPOSE, 40 MEAN, 41 SUB, 42 DIV, 43 SQUEEZE, 44 UNIDIRECTIONAL_SEQUENCE_LSTM, 45 STRIDED_SLICE, 46 BIDIRECTIONAL_SEQUENCE_RNN, 47 EXP, 48 TOPK_V2, 49 SPLIT, 50 LOG_SOFTMAX, 51 DELEGATE, 52 BIDIRECTIONAL_SEQUENCE_LSTM, 53 CAST, 54 PRELU, 55 MAXIMUM, 56 ARG_MAX, 57 MINIMUM, 58 LESS, 59 NEG, 60 PADV2, 61 GREATER, 62 GREATER_EQUAL, 63 LESS_EQUAL, 64 SELECT, 65 SLICE, 66 SIN, 67 TRANSPOSE_CONV, 68 SPARSE_TO_DENSE, 69 TILE, 70 EXPAND_DIMS, 71 EQUAL, 72 NOT_EQUAL, 73 LOG, 74 SUM, 75 SQRT, 76 RSQRT, 77 SHAPE, 78 POW, 79 ARG_MIN, 80 FAKE_QUANT, 81 REDUCE_PROD, 82 REDUCE_MAX, 83 PACK, 84 LOGICAL_OR, 85 ONE_HOT, 86 LOGICAL_AND, 87 LOGICAL_NOT, 88 UNPACK, 89 REDUCE_MIN, 90 FLOOR_DIV, 91 REDUCE_ANY, 92 SQUARE, 93 ZEROS_LIKE, 94 FILL, 95 FLOOR_MOD, 96 RANGE, 97 RESIZE_NEAREST_NEIGHBOR, 98 LEAKY_RELU, 99 SQUARED_DIFFERENCE, 100 MIRROR_PAD, 101 ABS, 102 SPLIT_V, 103 UNIQUE, 104 CEIL, 105 REVERSE_V2, 106 ADD_N, 107 GATHER_ND, 108 COS, 109 WHERE, 110 RANK, 111 ELU, 112 REVERSE_SEQUENCE, 113 MATRIX_DIAG, 114 QUANTIZE, 115 MATRIX_SET_DIAG, 116 ROUND, 117 HARD_SWISH, 118 IF, 119 WHILE, 120 NON_MAX_SUPPRESSION_V4, 121 NON_MAX_SUPPRESSION_V5, 122 SCATTER_ND, 123 SELECT_V2, 124 DENSIFY, 125 SEGMENT_SUM, 126 BATCH_MATMUL, 127 PLACEHOLDER_FOR_GREATER_OP_CODES, 128 CUMSUM, 129 CALL_ONCE, 130 BROADCAST_TO, 131 RFFT2D, 132 CONV_3D, 133 IMAG, 134 REAL, 135 COMPLEX_ABS, 136 HASHTABLE, 137 HASHTABLE_FIND, 138 HASHTABLE_IMPORT, 139 HASHTABLE_SIZE, 140 REDUCE_ALL, 141 CONV_3D_TRANSPOSE, 142 VAR_HANDLE, 143 READ_VARIABLE, 144 ASSIGN_VARIABLE, 145 BROADCAST_ARGS, 146 RANDOM_STANDARD_NORMAL, 147 BUCKETIZE, 148 RANDOM_UNIFORM, 149 MULTINOMIAL, 150 GELU, 151 DYNAMIC_UPDATE_SLICE, 152 RELU_0_TO_1, 153 UNSORTED_SEGMENT_PROD, 154 UNSORTED_SEGMENT_MAX, 155 UNSORTED_SEGMENT_SUM, 156 ATAN2, 157 UNSORTED_SEGMENT_MIN, 158 SIGN, 159 BITCAST, 160 BITWISE_XOR, 161 RIGHT_SHIFT, 162 STABLEHLO_LOGISTIC, 163 STABLEHLO_ADD, 164 STABLEHLO_DIVIDE, 165 STABLEHLO_MULTIPLY, 166 STABLEHLO_MAXIMUM, 167 STABLEHLO_RESHAPE, 168 STABLEHLO_CLAMP, 169 STABLEHLO_CONCATENATE, 170 STABLEHLO_BROADCAST_IN_DIM, 171 STABLEHLO_CONVOLUTION, 172 STABLEHLO_SLICE, 173 STABLEHLO_CUSTOM_CALL, 174 STABLEHLO_REDUCE, 175 STABLEHLO_ABS, 176 STABLEHLO_AND, 177 STABLEHLO_COSINE, 178 STABLEHLO_EXPONENTIAL, 179 STABLEHLO_FLOOR, 180 STABLEHLO_LOG, 181 STABLEHLO_MINIMUM, 182 STABLEHLO_NEGATE, 183 STABLEHLO_OR, 184 STABLEHLO_POWER, 185 STABLEHLO_REMAINDER, 186 STABLEHLO_RSQRT, 187 STABLEHLO_SELECT, 188 STABLEHLO_SUBTRACT, 189 STABLEHLO_TANH, 190 STABLEHLO_SCATTER, 191 STABLEHLO_COMPARE, 192 STABLEHLO_CONVERT, 193 STABLEHLO_DYNAMIC_SLICE, 194 STABLEHLO_DYNAMIC_UPDATE_SLICE, 195 STABLEHLO_PAD, 196 STABLEHLO_IOTA, 197 STABLEHLO_DOT_GENERAL, 198 STABLEHLO_REDUCE_WINDOW, 199 STABLEHLO_SORT, 200 STABLEHLO_WHILE, 201 STABLEHLO_GATHER, 202 STABLEHLO_TRANSPOSE, 203 DILATE, 204 STABLEHLO_RNG_BIT_GENERATOR, 205 REDUCE_WINDOW (deprecated), 206 STABLEHLO_COMPOSITE, 207 STABLEHLO_SHIFT_LEFT, 208 STABLEHLO_CBRT, 209 STABLEHLO_CASE.
BuiltinOptions and BuiltinOptions2
An operator's builtin_options is the BuiltinOptions union and
its builtin_options_2 the BuiltinOptions2 union (used for the
newer StableHLO operators); union members are numbered from 1 in the order below
(0 is NONE). The schema does not tie each operator code to one table in a list; the
table is chosen by the writer. Common enums: Padding (0 SAME, 1 VALID),
ActivationFunctionType (0 NONE, 1 RELU, 2 RELU_N1_TO_1, 3 RELU6, 4 TANH,
5 SIGN_BIT).
BuiltinOptions members, in order: 1 Conv2DOptions, DepthwiseConv2DOptions, ConcatEmbeddingsOptions, LSHProjectionOptions, Pool2DOptions, SVDFOptions, RNNOptions, FullyConnectedOptions, SoftmaxOptions, ConcatenationOptions, AddOptions, L2NormOptions, LocalResponseNormalizationOptions, LSTMOptions, ResizeBilinearOptions, CallOptions, ReshapeOptions, SkipGramOptions, SpaceToDepthOptions, EmbeddingLookupSparseOptions, MulOptions, PadOptions, GatherOptions, BatchToSpaceNDOptions, SpaceToBatchNDOptions, TransposeOptions, ReducerOptions, SubOptions, DivOptions, SqueezeOptions, SequenceRNNOptions, StridedSliceOptions, ExpOptions, TopKV2Options, SplitOptions, LogSoftmaxOptions, CastOptions, DequantizeOptions, MaximumMinimumOptions, ArgMaxOptions, LessOptions, NegOptions, PadV2Options, GreaterOptions, GreaterEqualOptions, LessEqualOptions, SelectOptions, SliceOptions, TransposeConvOptions, SparseToDenseOptions, TileOptions, ExpandDimsOptions, EqualOptions, NotEqualOptions, ShapeOptions, PowOptions, ArgMinOptions, FakeQuantOptions, PackOptions, LogicalOrOptions, OneHotOptions, LogicalAndOptions, LogicalNotOptions, UnpackOptions, FloorDivOptions, SquareOptions, ZerosLikeOptions, FillOptions, BidirectionalSequenceLSTMOptions, BidirectionalSequenceRNNOptions, UnidirectionalSequenceLSTMOptions, FloorModOptions, RangeOptions, ResizeNearestNeighborOptions, LeakyReluOptions, SquaredDifferenceOptions, MirrorPadOptions, AbsOptions, SplitVOptions, UniqueOptions, ReverseV2Options, AddNOptions, GatherNdOptions, CosOptions, WhereOptions, RankOptions, ReverseSequenceOptions, MatrixDiagOptions, QuantizeOptions, MatrixSetDiagOptions, HardSwishOptions, IfOptions, WhileOptions, DepthToSpaceOptions, NonMaxSuppressionV4Options, NonMaxSuppressionV5Options, ScatterNdOptions, SelectV2Options, DensifyOptions, SegmentSumOptions, BatchMatMulOptions, CumsumOptions, CallOnceOptions, BroadcastToOptions, Rfft2dOptions, Conv3DOptions, HashtableOptions, HashtableFindOptions, HashtableImportOptions, HashtableSizeOptions, VarHandleOptions, ReadVariableOptions, AssignVariableOptions, RandomOptions, BucketizeOptions, GeluOptions, DynamicUpdateSliceOptions, UnsortedSegmentProdOptions, UnsortedSegmentMaxOptions, UnsortedSegmentMinOptions, UnsortedSegmentSumOptions, ATan2Options, SignOptions, BitcastOptions, BitwiseXorOptions, RightShiftOptions.
BuiltinOptions2 members, in order: 1 StablehloConcatenateOptions, StablehloBroadcastInDimOptions, StablehloSliceOptions, StablehloConvolutionOptions, StablehloCustomCallOptions, StablehloReduceOptions, StablehloScatterOptions, StablehloCompareOptions, StablehloDynamicSliceOptions, StablehloPadOptions, StablehloIotaOptions, StablehloDotGeneralOptions, StablehloReduceWindowOptions, StablehloSortOptions, StablehloWhileOptions, StablehloGatherOptions, StablehloTransposeOptions, DilateOptions, StablehloRngBitGeneratorOptions, ReduceWindowOptions (deprecated), StableHLOCompositeOptions, StablehloShiftLeftOptions, StablehloCaseOptions.
| Options table | Fields (type, default) |
|---|---|
Conv2DOptions | padding, stride_w, stride_h (int), fused_activation_function, dilation_w_factor = 1, dilation_h_factor = 1, quantized_bias_type (TensorType; version 8 and up: the type of both bias and accumulator). |
Conv3DOptions | padding, stride_d, stride_w, stride_h, fused_activation_function, dilation_d_factor = 1, dilation_w_factor = 1, dilation_h_factor = 1. |
Pool2DOptions | padding, stride_w, stride_h, filter_width, filter_height, fused_activation_function. |
DepthwiseConv2DOptions | padding, stride_w, stride_h, depth_multiplier (redundant; used by CPU kernels in TensorFlow 2.0 and below), fused_activation_function, dilation_w_factor = 1, dilation_h_factor = 1. |
ConcatEmbeddingsOptions | num_channels (int), num_columns_per_channel [int], embedding_dim_per_channel [int]. |
LSHProjectionOptions | type: LSHProjectionType (0 UNKNOWN, 1 SPARSE, 2 DENSE). |
SVDFOptions | rank, fused_activation_function, asymmetric_quantize_inputs (bool). |
RNNOptions | fused_activation_function, asymmetric_quantize_inputs. |
SequenceRNNOptions | time_major, fused_activation_function, asymmetric_quantize_inputs. |
BidirectionalSequenceRNNOptions | time_major, fused_activation_function, merge_outputs, asymmetric_quantize_inputs. |
FullyConnectedOptions | fused_activation_function, weights_format (FullyConnectedOptionsWeightsFormat: 0 DEFAULT, 1 SHUFFLED4x16INT8), keep_num_dims (bool: preserve the number of dimensions), asymmetric_quantize_inputs, quantized_bias_type, quant_spec [ubyte]; the schema's comments say which version added each. |
SoftmaxOptions | beta (float). |
ConcatenationOptions | axis, fused_activation_function. |
AddOptions, SubOptions | fused_activation_function, pot_scale_int16 (bool, default true; Add from version 3, Sub from version 5). |
MulOptions, DivOptions | fused_activation_function. |
L2NormOptions | fused_activation_function (currently ignored). |
LocalResponseNormalizationOptions | radius (int), bias, alpha, beta (float). |
LSTMOptions | fused_activation_function, cell_clip, proj_clip (float), kernel_type (LSTMKernelType: 0 FULL, 1 BASIC; version 2 and up), asymmetric_quantize_inputs. |
UnidirectionalSequenceLSTMOptions | fused_activation_function, cell_clip, proj_clip, time_major (first dimension is sequence rather than batch), asymmetric_quantize_inputs, diagonal_recurrent_tensors. |
BidirectionalSequenceLSTMOptions | fused_activation_function, cell_clip, proj_clip, merge_outputs (both directions into the first output), time_major (default true: the first dimension is the sequence), asymmetric_quantize_inputs. |
ResizeBilinearOptions | new_height, new_width (deprecated), align_corners, half_pixel_centers. |
ResizeNearestNeighborOptions | align_corners, half_pixel_centers. |
CallOptions | subgraph (uint index of the subgraph to call). |
ReshapeOptions | new_shape [int]. |
SkipGramOptions | ngram_size, max_skip_size, include_all_ngrams. |
SpaceToDepthOptions, DepthToSpaceOptions | block_size. |
EmbeddingLookupSparseOptions | combiner: CombinerType (0 SUM, 1 MEAN, 2 SQRTN). |
GatherOptions | axis, batch_dims = 0 (version 5 and up). |
ReducerOptions | keep_dims. |
SqueezeOptions | squeeze_dims [int]. |
SplitOptions, SplitVOptions | num_splits. |
StridedSliceOptions | begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask, offset (bool: the end tensor is an offset from the begin tensor). |
CastOptions | in_data_type, out_data_type (TensorType). |
ArgMaxOptions, ArgMinOptions | output_type (TensorType). |
TransposeConvOptions | padding, stride_w, stride_h, fused_activation_function = NONE (version 4), quantized_bias_type (version 5). |
SparseToDenseOptions | validate_indices. |
ShapeOptions | out_type (TensorType, default int32). |
FakeQuantOptions | min, max (float), num_bits, narrow_range (version 2). |
PackOptions | values_count, axis. |
OneHotOptions | axis. |
UnpackOptions | num, axis. |
LeakyReluOptions | alpha (float). |
MirrorPadOptions | mode: MirrorPadMode (0 REFLECT, 1 SYMMETRIC). |
UniqueOptions | idx_out_type (TensorType, default INT32). |
ReverseSequenceOptions | seq_dim, batch_dim = 0. |
IfOptions | then_subgraph_index, else_subgraph_index. |
WhileOptions | cond_subgraph_index, body_subgraph_index. |
CallOnceOptions | init_subgraph_index. |
BatchMatMulOptions | adj_x, adj_y, asymmetric_quantize_inputs (version 4 and up). |
CumsumOptions | exclusive, reverse. |
HashtableOptions | table_id (identity across subgraphs of one interpreter), key_dtype, value_dtype. |
VarHandleOptions | container, shared_name (strings). |
RandomOptions | seed, seed2 (long). |
BucketizeOptions | boundaries [float]. |
GeluOptions | approximate (bool). |
| No fields | PadOptions, PadV2Options, SpaceToBatchNDOptions, BatchToSpaceNDOptions, TopKV2Options, TransposeOptions, ExpOptions, CosOptions, LogSoftmaxOptions, DequantizeOptions, MaximumMinimumOptions, TileOptions, GreaterOptions, GreaterEqualOptions, LessOptions, LessEqualOptions, EqualOptions, NotEqualOptions, NegOptions, SelectOptions, SelectV2Options, SliceOptions, ExpandDimsOptions, RankOptions, PowOptions, LogicalOrOptions, LogicalAndOptions, LogicalNotOptions, AbsOptions, HardSwishOptions, FloorDivOptions, FloorModOptions, SquareOptions, ZerosLikeOptions, FillOptions, RangeOptions, SquaredDifferenceOptions, ReverseV2Options, AddNOptions, GatherNdOptions, WhereOptions, MatrixDiagOptions, QuantizeOptions, MatrixSetDiagOptions, NonMaxSuppressionV4Options, NonMaxSuppressionV5Options, ScatterNdOptions, DensifyOptions, SegmentSumOptions, BroadcastToOptions, Rfft2dOptions, HashtableFindOptions, HashtableImportOptions, HashtableSizeOptions, ReadVariableOptions, AssignVariableOptions, DynamicUpdateSliceOptions, UnsortedSegmentProdOptions, UnsortedSegmentMaxOptions, UnsortedSegmentMinOptions, UnsortedSegmentSumOptions, ATan2Options, SignOptions, BitcastOptions, BitwiseXorOptions, RightShiftOptions, DilateOptions, StablehloShiftLeftOptions. |
| StableHLO tables | StablehloConcatenateOptions (dimension); StablehloBroadcastInDimOptions (broadcast_dimensions); StablehloSliceOptions (start_indices, limit_indices, strides); StablehloConvolutionOptions (window_strides, padding, lhs_dilation, rhs_dilation, window_reversal, input and kernel and output batch/feature/spatial dimension numbers, feature_group_count, batch_group_count, precision_config); StablehloCustomCallOptions (call_target_name, has_side_effect, backend_config, api_version, called_computations, custom_attributes); StablehloReduceOptions (dimensions, body_subgraph_index); StablehloScatterOptions (indices_are_sorted, update_window_dims, inserted_window_dims, scatter_dims_to_operand_dims, index_vector_dim, unique_indices, update_computation_subgraph_index); StablehloCompareOptions (comparison_direction EQ, NE, GE, GT, LE, LT; compare_type NOTYPE, FLOAT, FLOAT_TOTAL_ORDER, SIGNED, UNSIGNED); StablehloDynamicSliceOptions (slice_sizes); StablehloPadOptions (edge_padding_low, edge_padding_high, interior_padding); StablehloIotaOptions (iota_dimension); StablehloDotGeneralOptions (lhs/rhs batching and contracting dimensions, precision_config: DEFAULT, HIGH, HIGHEST); StablehloReduceWindowOptions (window_dimensions, window_strides, base_dilations, window_dilations, padding, body_subgraph_index); StablehloSortOptions (dimension, is_stable, comparator_subgraph_index); StablehloWhileOptions (cond_subgraph_index, body_subgraph_index); StablehloGatherOptions (offset_dims, collapsed_slice_dims, start_index_map, index_vector_dim, slice_sizes, indices_are_sorted); StablehloTransposeOptions (permutation); StablehloRngBitGeneratorOptions (algorithm: 0 DEFAULT, 1 PHILOX, 2 THREEFRY); ReduceWindowOptions (reduce_function: UNSUPPORTED, ADD, MUL, MINIMUM, MAXIMUM, ALL, ANY; deprecated); StableHLOCompositeOptions (name, decomposition_subgraph_index, composite_attributes, composite_attributes_format = FLEXBUFFERS, version); StablehloCaseOptions (branch_subgraph_indices). The long arrays are 64-bit integers. |
SparsityParameters, SignatureDef and external buffers
- SparsityParameters:
traversal_order[int] (a permutation of the tensor's dimensions; for a block-sparse tensor with a k-dimensional block, n + k entries, the last k giving how to walk inside a block),block_map[int] (how each block dimension maps to an original dimension; null when not block-sparse),dim_metadata[DimensionMetadata] (one per traversal entry). DimensionMetadata:format(DimensionType: 0 DENSE, 1 SPARSE_CSR),dense_size(for a dense dimension),array_segmentsandarray_indices(aSparseIndexVectorunion ofInt32Vector,Uint16VectororUint8Vector, each holdingvalues): for CSR, the segments are like CSR row pointers (one segment per element of the previous dimension) and the indices the positions of the non-zero elements, like CSR column indices. - SignatureDef:
inputsandoutputs(each a list ofTensorMap: an aliasnameand thetensor_indexin the primary graph),signature_key(the key in the TensorFlow SavedModel signature map),deprecated_tag,subgraph_index(the subgraph of the exported method). - Metadata:
name(a human-readable unique string) andbuffer(an index into the buffers table). ExternalBufferGroup:name. ExternalBuffer:id(uint, unique),group(index into the groups),offsetandlength(ulong),packing(string). - VariantSubType (for
VARIANTtensors):shape[int],type(TensorType),has_rank(bool, default false; if false the shape must be empty and the rank is unknown).
FlexBuffers: custom_options and composite attributes
An operator's custom_options (a [ubyte]) and a
StableHLOCompositeOptions table's composite_attributes hold a
schema-less FlexBuffers value when
custom_options_format (or composite_attributes_format) is
FLEXBUFFERS (0, the only member of CustomOptionsFormat). The
encoding below is from the FlatBuffers internals document and
include/flatbuffers/flexbuffers.h.
- General: little-endian, every scalar aligned to its own size. Unlike FlatBuffers, a FlexBuffer is built front to back, so children come before parents and the root is at the last byte. Scalars have 8, 16, 32 or 64 bits; the width in force is chosen by the parent (a vector gives one width to all its elements and to its size field), and the encoder picks the smallest that fits.
- Offsets: only one kind, an unsigned integer giving the number of bytes to count back from the address where the offset itself is stored.
- Root: the last byte is the width in bytes of the root value; the byte before it is the root's type byte; the bytes before that are the root value, of the width given by the last byte. The integer 13 as root is
0D 04 01(value, type byte 4, root width 1). - Type byte: the two low bits are the bit width of the child (0 = 8, 1 = 16, 2 = 32, 3 = 64 bits), used only when the child is reached over an offset and ignored for inline types; the upper six bits are the type. The example type byte 4 is width 8 (0) and type 1 (
FBT_INT).
| Value | Name | Meaning |
|---|---|---|
| 0 | FBT_NULL | Null, stored inline (as an unsigned integer). |
| 1 | FBT_INT | Signed integer, inline. |
| 2 | FBT_UINT | Unsigned integer, inline. |
| 3 | FBT_FLOAT | Float, inline (the header says only types up to here and FBT_BOOL are inline). |
| 4 | FBT_KEY | Like a string without the size field: bytes then a 0, so it cannot contain a 0 byte; used for map keys. |
| 5 | FBT_STRING | Size, bytes, a 0 terminator; must be UTF-8. |
| 6, 7, 8 | FBT_INDIRECT_INT, _UINT, _FLOAT | The scalar is stored elsewhere and reached over an offset, so a wide value in a vector of narrow ones costs only an offset, and a value can be shared. |
| 9 | FBT_MAP | A vector with a keys vector before the size field (below). |
| 10 | FBT_VECTOR | Untyped vector: size, elements, then one type byte per element (always one byte, whatever the element width). |
| 11, 12, 13, 14 | FBT_VECTOR_INT, _UINT, _FLOAT, _KEY | Typed vectors: size and elements, no type bytes. |
| 15 | FBT_VECTOR_STRING_DEPRECATED | Deprecated; the header says to use FBT_VECTOR or FBT_VECTOR_KEY. |
| 16, 17, 18 | FBT_VECTOR_INT2, UINT2, FLOAT2 | Fixed tuple of 2: no size field and no type bytes. |
| 19, 20, 21 | FBT_VECTOR_INT3, UINT3, FLOAT3 | Fixed triple. |
| 22, 23, 24 | FBT_VECTOR_INT4, UINT4, FLOAT4 | Fixed quad. |
| 25 | FBT_BLOB | Like a vector whose elements are always bytes; the parent width applies only to the size field. |
| 26 | FBT_BOOL | Boolean, stored inline as an unsigned integer. |
| 36 | FBT_VECTOR_BOOL | Typed vector of booleans (the value 36 is explained in the header only as allowing the same type-to-vector-type conversion). |
| 37 | FBT_MAX_TYPE | Upper bound, not a type. |
- Vector: an offset to a vector points at its first element; the size field is at index −1. The vector 1, 2, 3 with 8-bit width is
03 01 02 03 04 04 04: size 3, three elements, three type bytes (4 = width 8, typeFBT_INT). - Map: a vector with two more fields before the size: index −3 an offset to the keys vector (it may be shared between maps), −2 the byte width of the keys vector, −1 the size; then the elements and the type bytes. The keys vector is a typed vector of keys. Keys and their values must both be in sorted order (by
strcmp), so lookup can use binary search. - Map example
{ foo: 13, bar: 14 }, from the document: offset 0'b' 'a' 'r' 0; 4'f' 'o' 'o' 0; 802(key vector size); 909 06(offsets to bar and foo, counted back from their own positions); 1102 01(offset to the key vector, its byte width); 1302(value vector size); 140E 0D(14, 13); 1604 04(types).
Source: FlatBuffers docs "FlatBuffers Internals", section FlexBuffers; flexbuffers.h on the master branch of google/flatbuffers.
Model metadata (TFLITE_METADATA)
Descriptions of what the model does can be stored in the model itself, as a second
FlatBuffers buffer with its own schema. It is attached through the model's
metadata list, and files it names are appended to the .tflite file as a ZIP
archive. Sources: metadata_schema.fbs (schema version 1.5.0) and
python/metadata.py of the tflite-support repository.
- Attachment: a
Metadataentry in the Model withname=TFLITE_METADATAwhosebufferindex selects aBufferholding the metadata FlatBuffers bytes. The populator replaces an existing entry of that name or appends a new buffer and entry. - Identifier and root: the metadata buffer's file identifier is
M001(the model's isTFL3), file extensiontflitemeta, root typeModelMetadata. The identifier changes only on a break in compatibility. - Associated files: after the FlatBuffer the populator appends a ZIP archive (
zipfileappend mode on a copy of the model), so the file is a TFLite buffer followed by ZIP entries; each entry's name is theAssociatedFile.name. Several populate runs add more entries after the earlier ones. It refuses a file already packed and a file named in the metadata but not loaded; a packed file the metadata does not name is allowed with a warning. A reader recognises the archive withzipfile.is_zipfile. - Versioning: semantic version MAJOR.MINOR.PATCH, 1.5.0 now. History: 1.0.1 VOCABULARY file type; 1.1.0 BertTokenizerOptions, SentencePieceTokenizerOptions, input and output process units; 1.2.0 tensor groups; 1.2.1 RegexTokenizerOptions; 1.3.0 AudioProperties; 1.4.0 SCANN_INDEX_FILE; 1.4.1 version in AssociatedFile; 1.5.0 CustomMetadata.
ModelMetadata.min_parser_versionis filled in by the populator: the largest version among the populated fields and the smallest compatible one indicated by the identifier.
| Table or enum | Fields and values |
|---|---|
ModelMetadata (root) | name, description, version (set by the model's creators), subgraph_metadata [SubGraphMetadata] (the 0th is the main subgraph), author, license, associated_files [AssociatedFile], min_parser_version. |
SubGraphMetadata | name, description, input_tensor_metadata and output_tensor_metadata [TensorMetadata] (one per index of SubGraph.inputs and outputs, same count), associated_files, input_process_units and output_process_units [ProcessUnit] (1.1.0, for processing that does not work on one tensor at a time, such as the MobileBert example), input_tensor_groups and output_tensor_groups [TensorGroup] (1.2.0), custom_metadata [CustomMetadata] (1.5.0). |
TensorMetadata | name, description, dimension_names [string] (one per dimension), content (Content), process_units [ProcessUnit], stats (Stats), associated_files. |
Content | content_properties (union ContentProperties: FeatureProperties, ImageProperties, BoundingBoxProperties, AudioProperties (1.3.0); FlatBuffers numbers union members from 1 in this order, 0 being NONE) and range (ValueRange with int min, max: the dimensions the content covers; null means all dimensions except a batch axis; the schema's examples are the image classifier [1, 224, 224, 3] with null, detection boxes [1, 10, 4] with {2, 2}, and heatmaps [1, 9, 9, 17] with {1, 2}). |
FeatureProperties | No fields. Default input pipeline [Normalize, Quantize], output [Dequantize]. |
ImageProperties | color_space (ColorSpaceType: 0 UNKNOWN, 1 RGB, 2 GRAYSCALE) and default_size (ImageSize: uint width, height; used when the tensor shape is dynamic). Default input pipeline [Resize, Normalize, Quantize]. |
BoundingBoxProperties | index [uint] (order of the four elements; empty means the default order; {0, 2, 1, 3} for left, right, top, bottom), type (BoundingBoxType: 0 UNKNOWN, 1 BOUNDARIES {left, top, right, bottom}, 2 UPPER_LEFT {x, y, width, height}, 3 CENTER {center_x, center_y, width, height}), coordinate_type (CoordinateType: 0 RATIO, floats 0 to 1; 1 PIXEL, integers). |
AudioProperties | uint sample_rate (Hz) and channels. |
ProcessUnit | options (union ProcessUnitOptions: NormalizationOptions, ScoreCalibrationOptions, ScoreThresholdingOptions, BertTokenizerOptions, SentencePieceTokenizerOptions, RegexTokenizerOptions, numbered from 1 in that order). |
NormalizationOptions | mean [float] and std [float], per channel; the value is (x − mean) / std; a single value applies to all channels. Quantised models share the float model's parameters (127.5 and 127.5 map [0, 255] to [−1, 1]); the data is then quantised with the tensor's quantisation parameters. |
ScoreCalibrationOptions | score_transformation (ScoreTransformationType: 0 IDENTITY g(x) = x, 1 LOG, 2 INVERSE_LOGISTIC g(x) = log(x) − log(1 − x)) and float default_score. For each output index f(x) = scale / (1 + e−(slope·g(x) + offset)) when x > min_score (or no min_score is given); otherwise default_score. The per-index scale, slope, offset and optional min_score come from an associated file of type TENSOR_AXIS_SCORE_CALIBRATION: CSV, one line per index, 0, 3 or 4 comma-separated values in strtof format in that order, scale non-negative, an empty line meaning default_score. |
ScoreThresholdingOptions | float global_score_threshold. |
| Tokenizer options | BertTokenizerOptions: vocab_file [AssociatedFile] (as tf.text.BertTokenizer). SentencePieceTokenizerOptions: sentencePiece_model [AssociatedFile] and optional vocab_file. RegexTokenizerOptions: string delim_regex_pattern (split at matches, then map tokens to ids with the vocabulary) and vocab_file. |
Stats | max [float] and min [float], per channel; references for users, not used by the code generator. |
TensorGroup | name and tensor_names [string] (matching TensorMetadata.name; all tensors in a group have the same number of elements as given by Content.range). |
CustomMetadata | name and data [ubyte] with force_align: 16. |
AssociatedFile | name (must equal the ZIP entry's name), description, type (AssociatedFileType: 0 UNKNOWN, 1 DESCRIPTIONS, 2 TENSOR_AXIS_LABELS (one label per line, annotating an axis of the tensor), 3 TENSOR_VALUE_LABELS (values in the tensor are indices into the labels), 4 TENSOR_AXIS_SCORE_CALIBRATION, 5 VOCABULARY (1.0.1), 6 SCANN_INDEX_FILE (1.4.0, a ScaNN index in LevelDB format)), locale (ISO 639-1 code, optionally with a region such as en-US; when several files have the same type the first is the default), version (1.4.1). |
Which options table an operator reads
The schema declares the tables but not which operator uses which. This list is what the
reference interpreter's parser (tensorflow/lite/core/api/flatbuffer_conversions.cc,
ParseOpDataTfLite and the Parse… functions, master branch) reads from
the operator for each builtin code. It reads builtin_options unless
marked builtin_options_2.
| Options table | Operators |
|---|---|
AddOptions, SubOptions, MulOptions, DivOptions | ADD, SUB, MUL, DIV. |
ArgMaxOptions, ArgMinOptions | ARG_MAX, ARG_MIN. |
Pool2DOptions | AVERAGE_POOL_2D, L2_POOL_2D, MAX_POOL_2D. |
BatchMatMulOptions, CallOnceOptions, CastOptions, ConcatenationOptions, CumsumOptions, DepthToSpaceOptions | BATCH_MATMUL, CALL_ONCE, CAST, CONCATENATION, CUMSUM, DEPTH_TO_SPACE. |
Conv2DOptions, DepthwiseConv2DOptions, TransposeConvOptions, FullyConnectedOptions | CONV_2D, DEPTHWISE_CONV_2D, TRANSPOSE_CONV, FULLY_CONNECTED. |
Conv3DOptions | CONV_3D and CONV_3D_TRANSPOSE (the same table, one parameter struct). |
GatherOptions, IfOptions, WhileOptions, L2NormOptions, LeakyReluOptions, MirrorPadOptions | GATHER, IF, WHILE, L2_NORMALIZATION, LEAKY_RELU, MIRROR_PAD. |
LSTMOptions, UnidirectionalSequenceLSTMOptions, BidirectionalSequenceLSTMOptions | LSTM, UNIDIRECTIONAL_SEQUENCE_LSTM, BIDIRECTIONAL_SEQUENCE_LSTM. |
RNNOptions, SequenceRNNOptions, BidirectionalSequenceRNNOptions, SVDFOptions | RNN, UNIDIRECTIONAL_SEQUENCE_RNN, BIDIRECTIONAL_SEQUENCE_RNN, SVDF. |
PackOptions, UnpackOptions, SplitOptions, SplitVOptions, SqueezeOptions, StridedSliceOptions | PACK, UNPACK, SPLIT, SPLIT_V, SQUEEZE, STRIDED_SLICE. |
ReducerOptions | MEAN, SUM, REDUCE_ANY, REDUCE_ALL, REDUCE_MAX, REDUCE_MIN, REDUCE_PROD. |
ReshapeOptions, ResizeBilinearOptions, ResizeNearestNeighborOptions, ShapeOptions, SoftmaxOptions, SpaceToDepthOptions | RESHAPE, RESIZE_BILINEAR, RESIZE_NEAREST_NEIGHBOR, SHAPE, SOFTMAX, SPACE_TO_DEPTH. |
LSHProjectionOptions, EmbeddingLookupSparseOptions, LocalResponseNormalizationOptions, SkipGramOptions, SparseToDenseOptions, FakeQuantOptions, OneHotOptions, UniqueOptions, ReverseSequenceOptions, HashtableOptions, BucketizeOptions, GeluOptions, VarHandleOptions | LSH_PROJECTION, EMBEDDING_LOOKUP_SPARSE, LOCAL_RESPONSE_NORMALIZATION, SKIP_GRAM, SPARSE_TO_DENSE, FAKE_QUANT, ONE_HOT, UNIQUE, REVERSE_SEQUENCE, HASHTABLE, BUCKETIZE, GELU, VAR_HANDLE. |
RandomOptions | MULTINOMIAL, RANDOM_STANDARD_NORMAL, RANDOM_UNIFORM (the fields seed, seed2). |
builtin_options_2 | REDUCE_WINDOW reads ReduceWindowOptions; STABLEHLO_SCATTER, STABLEHLO_RNG_BIT_GENERATOR, STABLEHLO_GATHER, STABLEHLO_REDUCE_WINDOW, STABLEHLO_PAD, STABLEHLO_COMPOSITE and STABLEHLO_CASE read the matching Stablehlo…Options or StableHLOCompositeOptions table. |
| No options read | ABS, ADD_N, ASSIGN_VARIABLE, BATCH_TO_SPACE_ND, BROADCAST_ARGS, BROADCAST_TO, CEIL, COS, DEQUANTIZE, DYNAMIC_UPDATE_SLICE, ELU, EMBEDDING_LOOKUP, EQUAL, EXP, EXPAND_DIMS, FILL, FLOOR, FLOOR_DIV, FLOOR_MOD, GATHER_ND, GREATER, GREATER_EQUAL, HARD_SWISH, HASHTABLE_LOOKUP, LESS, LESS_EQUAL, LOG, LOGICAL_AND, LOGICAL_NOT, LOGICAL_OR, LOGISTIC, LOG_SOFTMAX, MAXIMUM, MINIMUM, NEG, NOT_EQUAL, PAD, PADV2, POW, PRELU, QUANTIZE, READ_VARIABLE, RELU, RELU6, RELU_N1_TO_1, RELU_0_TO_1, REVERSE_V2, ROUND, RSQRT, SELECT, SELECT_V2, SIN, SPACE_TO_BATCH_ND, SQRT, SQUARE, SQUARED_DIFFERENCE, TANH, TRANSPOSE, ZEROS_LIKE, BITWISE_XOR, RIGHT_SHIFT, CALL, COMPLEX_ABS, CONCAT_EMBEDDINGS, CUSTOM, DENSIFY, HASHTABLE_FIND, HASHTABLE_IMPORT, HASHTABLE_SIZE, IMAG, MATRIX_DIAG, MATRIX_SET_DIAG, NON_MAX_SUPPRESSION_V4, NON_MAX_SUPPRESSION_V5, SCATTER_ND, SLICE, TILE, TOPK_V2, RANGE, RANK, REAL, RFFT2D, SEGMENT_SUM, UNSORTED_SEGMENT_MAX, MIN, PROD, SUM, ATAN2, SIGN, BITCAST, WHERE, DILATE, STABLEHLO_SHIFT_LEFT and the other STABLEHLO_* operators (the source skips their parameters for now because they have no kernels). The parser returns an error for DELEGATE (it must not appear in a model) and PLACEHOLDER_FOR_GREATER_OP_CODES. Operators in the schema's list that this parser does not name (for example ones with no interpreter kernel) are not covered here. |