This document is relevant for: Inf1, Inf2, Trn1, Trn2, Trn3

Data Types#

Introduction#

Trainium and Inferentia NeuronDevices include different NeuronCore versions, which support different data types. This page describes the data types that each NeuronCore version supports, starting with the latest platforms, Trn3 (NeuronCore-v4) and Trn2 (NeuronCore-v3). Each NeuronCore version supports all of the data types of the version before it.

Trn3 (NeuronCore v4)#

Trn3 supports all of the data types available on NeuronCore v3, along with automatic type conversion, rounding-mode, and integer type conversion behaviors, including native execution of 64-bit integers via the --native-int64 option.

In addition, Trn3 supports the microscaling formats MXFP8 and MXFP4 for matrix multiplication. The NeuronCore-v4 Vector Engine can quantize BF16 and FP16 data into MXFP8. For more information, see NeuronCore-v4 Architecture and Trainium3 Architecture.

Trn2 (NeuronCore v3)#

Trn2 supports all of the data types available on NeuronCore v2, along with automatic type conversion and rounding-mode behaviors. In addition, Trn2 adds support for native execution of 64-bit integers (INT64 and UINT64).

Integer Type Conversion#

By default (--native-int64=disabled), the compiler downcasts 64-bit integer operations to 32-bit integers, which can lose precision for values outside the signed 32-bit range. To run 64-bit integer operations natively on Trn2 and later and keep their full precision, set --native-int64=enabled. Native int64 execution can be slower than the int32 datapath.

Some operations have no native integer datapath: matrix multiplication, scatter-with-compute, all-reduce, reduce-scatter, and 64-bit integer power. The --implicit-integer-downcast option controls what the compiler does with them. With the default, all, the compiler runs these operations with a lossy downcast (to FP32, or to 32-bit integers for integer power). With none, the compiler stops and reports an error instead.

See the Neuron Compiler CLI Reference Guide for a description of these options.

Trn1 / Inf2 (NeuronCore v2)#

NeuronCore-v2 and later (Trn1, Inf2, Trn2, and Trn3) support the following data types:

  • 32 and 16-bit Floating Point (FP32 / FP16)

  • TensorFloat-32 (TF32)

  • Brain Floating Point (BFloat16)

  • 8-bit Floating point with configurable range and precision (cFP8)

  • Unsigned 8-bit integer (UINT8)

  • 32-bit signed and unsigned integer (INT32 and UINT32)

The layout for these is as follows:

Data Type S Range Precision
FP32 1 8 bits 23 bits
TF32 1 8 bits 10 bits
BF16 1 8 bits 7 bits
FP16 1 5 bits 10 bits
FP8_e5m2 1 5 bits 2 bits
FP8_e4m3 1 4 bits 3 bits
FP8_e3m4 1 3 bits 4 bits
UINT8 8 bits
INT32 1 31 bits
UINT32 32 bits

Automatic type conversion (auto-cast)#

Automatic type conversion means that the Neuron compiler casts FP32 operations in a model to a lower-precision data type, such as BF16, when it compiles the model. Lower precision runs faster and uses less memory, at some cost in accuracy.

By default, the compiler does not cast. It compiles matrix multiplication operations in the data type of the model (--auto-cast=none). This default applies starting with neuronx-cc 2.22.12471.0 (Neuron SDK 2.27.0). Earlier versions cast FP32 matrix multiplications to BF16 by default. To cast FP32 matrix multiplications to BF16, pass --auto-cast=matmult --auto-cast-type=bf16. Accuracy after casting depends on the model, so compare the accuracy of the cast model with the original FP32 model.

The --auto-cast and --auto-cast-type options select which operations to cast and the target data type. See the Neuron Compiler CLI Reference Guide for a description of these options.

See Mixed Precision and Performance-accuracy Tuning for Training for more details on supported data types and their properties.

Rounding Modes#

Because floating point values are represented by a finite number of bits, they cannot represent all real numbers accurately. Floating point calculations that exceed their defined data type size are rounded. NeuronCore-v2 and later perform a Round-to-Nearest (RNE) algorithm with ties to Even by default. It also provides a new Stochastic Rounding mode. When Stochastic Rounding is enabled, the hardware will round the floating point value up or down using a proportional probability. This could lead to improved model convergence. Use the environment variable NEURON_RT_STOCHASTIC_ROUNDING_EN to select a rounding mode. See Neuron Rounding Modes.

Integer Type Conversion#

On NeuronCore-v2 (Trn1 and Inf2), 64-bit integers are always auto-converted to 32-bit integers. Trn2 and Trn3 can run them natively (see the sections above).

Some operations have no native integer datapath: matrix multiplication, scatter-with-compute, all-reduce, reduce-scatter, and 64-bit integer power. With the default --implicit-integer-downcast=all, the compiler runs these operations with a lossy downcast. With --implicit-integer-downcast=none, the compiler stops and reports an error instead.

Inf1 (NeuronCore v1, retired)#

Note

Inf1 is a retired platform. This section is kept for reference. For Inf1 architecture documentation, see Inf1 architecture (archived).

Neuron Data-Types#

Neuron enables developers to choose from multiple data-types. The supported data-types are FP32, FP16, and BF16. Developers can train their models on their platform of choice (e.g. EC2 P3 instances), and then easily move their trained models to EC2 Inf1 for execution.

Data Type S Range Precision
FP32 1 8 bits 23 bits
BF16 1 8 bits 7 bits
FP16 1 5 bits 10 bits

This document is relevant for: Inf1, Inf2, Trn1, Trn2, Trn3