TensorFlow’s DataType enum, from types.proto, names the
element type of every tensor and the type attributes of ops (T,
dtype), such as the dtype of each Const node
in a frozen graph. Every
name has the prefix DT_. It is a different list from ONNX’s: DT_FLOAT is 1
in both, but DT_INT32 is 3 here and INT32 is 6 in ONNX.
The data types
| Value | Name | Bytes in tensor_content | Typed field |
|---|---|---|---|
| 0 | DT_INVALID | – | – (not allowed in a tensor) |
| 1 | DT_FLOAT | 4 | float_val |
| 2 | DT_DOUBLE | 8 | double_val |
| 3 | DT_INT32 | 4 | int_val |
| 4 | DT_UINT8 | 1 | int_val |
| 5 | DT_INT16 | 2 | int_val |
| 6 | DT_INT8 | 1 | int_val |
| 7 | DT_STRING | – | string_val |
| 8 | DT_COMPLEX64 | 8 | scomplex_val |
| 9 | DT_INT64 | 8 | int64_val |
| 10 | DT_BOOL | 1 | bool_val |
| 11 | DT_QINT8 | 1 | quantised signed 8-bit |
| 12 | DT_QUINT8 | 1 | quantised unsigned 8-bit |
| 13 | DT_QINT32 | 4 | quantised signed 32-bit |
| 14 | DT_BFLOAT16 | 2 | half_val |
| 15 | DT_QINT16 | 2 | quantised signed 16-bit |
| 16 | DT_QUINT16 | 2 | quantised unsigned 16-bit |
| 17 | DT_UINT16 | 2 | int_val |
| 18 | DT_COMPLEX128 | 16 | dcomplex_val |
| 19 | DT_HALF | 2 | half_val |
| 20 | DT_RESOURCE | – | resource_handle_val |
| 21 | DT_VARIANT | – | variant_val |
| 22 | DT_UINT32 | 4 | uint32_val |
| 23 | DT_UINT64 | 8 | uint64_val |
| 24 | DT_FLOAT8_E5M2 | 1 | float8_val |
| 25 | DT_FLOAT8_E4M3FN | 1 | float8_val |
| 26 | DT_FLOAT8_E4M3FNUZ | 1 | float8_val |
| 27 | DT_FLOAT8_E4M3B11FNUZ | 1 | float8_val |
| 28 | DT_FLOAT8_E5M2FNUZ | 1 | float8_val |
| 29 | DT_INT4 | not confirmed | – |
| 30 | DT_UINT4 | not confirmed | – |
| 31 | DT_INT2 | not confirmed | – |
| 32 | DT_UINT2 | not confirmed | – |
| 33 | DT_FLOAT4_E2M1FN | not confirmed | – |
| 34 | DT_FLOAT8_E8M0FNU | 1 | float8_val |
The typed field is the one tensor.proto’s comments name for that type; for the
quantised types the table gives the meaning instead, since the comments name no field
for them. Whatever the type, tensor_content may be used instead of the
typed field, and the explorer reads it with the sizes above. How TensorFlow packs the
4-bit, 2-bit and FLOAT4 types into tensor_content was not confirmed for
this page, and the explorer shows them as plain bytes.
The float8 types
DT_FLOAT8_E5M2, DT_FLOAT8_E4M3FN, DT_FLOAT8_E4M3FNUZ and DT_FLOAT8_E5M2FNUZ are the same 8-bit float formats as ONNX’s of those names: a sign bit, then 5 and 2 or 4 and 3 exponent and mantissa bits. DT_FLOAT8_E4M3B11FNUZ is the E4M3 layout with an exponent bias of 11 and no negative zero, as its name says. DT_FLOAT8_E8M0FNU is a power of two with no sign and no mantissa, the scale type of the OCP Microscaling formats.
Reference types: 101 to 134
Each type also has a reference form, its number plus 100, named with
_REF at the end: DT_FLOAT_REF is 101, DT_INT32_REF 103 and so on up to
134. types.proto marks them “Do not use!”: they belong to TensorFlow 1’s reference
variables, and appear in the type attributes of old graphs, not as the type of a
stored tensor. The explorer names them.