Transformer Engine

Also known as: NVIDIA Transformer Engine

On this page 7

Transformer Engine is NVIDIA’s combination of tensor core hardware and a software library that automatically runs the matrix operations of transformer models in 8-bit and, on newer chips, 4-bit floating-point formats, while keeping accuracy close to 16-bit training. In AI hardware, it is the feature that turns low-precision arithmetic from a research technique into a routine production setting for large language models.

The NVIDIA Transformer Engine first appeared with the NVIDIA Hopper architecture in the H100 GPU in 2022. A second generation arrived with NVIDIA Blackwell, adding FP4 and FP6 support and finer-grained scaling. The name covers both the silicon features and the open-source library that frameworks such as PyTorch and JAX call.

How Transformer Engine manages precision

Transformer Engine works by choosing a numeric format per tensor and per layer and by rescaling values so that they fit the narrow range of low-precision formats. The heavy matrix multiplications in attention and feed-forward layers run in FP8 or FP4, while sensitive operations such as softmax, normalization and weight updates stay in bfloat16 or FP32.

An 8-bit floating-point number has very few exponent bits, so values outside a small window overflow or underflow to zero. To prevent this, the library tracks the absolute maximum (amax) of each tensor and computes a scaling factor that maps the tensor into the representable range. The first generation uses per-tensor scaling with delayed updates: scale factors come from an amax history collected over recent training steps.

The second generation on Blackwell adds micro-tensor scaling, in which small blocks of values share their own scale factor. This follows the microscaling formats idea and makes FP4 usable, because a single outlier no longer forces an entire tensor into a coarse scale.

Formats supported by Transformer Engine

Transformer Engine relies on two FP8 encodings with different trade-offs between range and precision, plus 4-bit and 6-bit formats on Blackwell. The table summarizes the formats it uses and where each typically applies.

FormatBit layoutStrengthTypical use
FP8 E4M34 exponent, 3 mantissa bitsHigher precision, max about 448Forward pass weights and activations
FP8 E5M25 exponent, 2 mantissa bitsWider range, max about 57,344Gradients in the backward pass
FP6Block-scaled 6-bit valuesMiddle ground in size and accuracySelected inference workloads
FP4 (NVFP4, MXFP4)Block-scaled 4-bit valuesSmallest memory footprintInference and experimental training
bfloat168 exponent, 7 mantissa bitsFP32-like rangeSensitive layers and master copies
Numeric formats used by Transformer Engine

A common configuration, called the hybrid recipe, uses E4M3 for forward tensors and E5M2 for gradients, because gradients span a wider dynamic range than weights and activations.

Hardware generations and what changed

Each GPU generation expanded the formats and the scaling granularity of Transformer Engine. The comparison below shows the main differences between generations and the earlier Ampere baseline.

ArchitectureLowest tensor core precisionScaling approachPractical effect
Ampere (A100)TF32, FP16, bfloat16, INT8Manual loss scaling onlyNo Transformer Engine
Hopper (H100, H200)FP8Per-tensor, delayed scalingAbout 2x FP16 matrix throughput
Blackwell (B200, GB200)FP4 and FP6Micro-tensor block scalingFurther 2x over FP8 for inference
Transformer Engine across NVIDIA data-center GPU generations

The gain comes from two sources: tensor cores process twice as many FP8 operations per cycle as FP16 ones, and halving the bytes per value cuts memory traffic and capacity needs. Because large transformer workloads are often limited by the memory wall, the bandwidth saving can matter as much as the raw compute increase.

Using the Transformer Engine library

Developers use Transformer Engine through drop-in replacement modules such as te.Linear, te.LayerNormLinear and te.TransformerLayer, and wrap the forward pass in an FP8 autocast context that applies a chosen scaling recipe. Training frameworks such as Megatron-LM and NeMo, and inference stacks such as TensorRT-LLM, integrate it directly.

SituationRecommended choiceReason
Pretraining a large model on H100FP8 with delayed scalingMature recipe, near-bfloat16 accuracy
Serving a model on BlackwellFP4 or FP8 weightsLower memory, higher token throughput
Small model, short trainingbfloat16 onlyFP8 overhead outweighs gains
Unstable loss with FP8Keep first and last layers in bfloat16These layers are most sensitive
Non-NVIDIA acceleratorVendor equivalentLibrary targets NVIDIA tensor cores
Deciding where Transformer Engine fits

Gains depend on model size. Small layers spend proportionally more time on casting, scaling and kernel launches, so speedups grow with hidden dimension and are most visible for models with billions of parameters.

Two recipe choices deserve attention. The amax history length controls how quickly scale factors react to changing value ranges: a short history adapts fast but reacts to noise, while a long history is stable but lags behind sudden spikes. The margin setting deliberately reserves headroom below the format maximum, trading a little precision for protection against overflow. Teams usually validate a recipe on a shorter run, compare loss curves against a bfloat16 reference, and only then commit a full training budget. Checkpoints keep FP32 master weights, so a run can fall back to higher precision if FP8 proves unstable.

Limitations and common misconceptions

Transformer Engine is not a separate chip and not a transformer model; it is a set of tensor core capabilities plus software. It also does not make every operation low precision. The accuracy of FP8 training is close to bfloat16 in published large-model runs, but it is not guaranteed for every architecture or hyperparameter setting.

  • Vendor lock-in: the library and formats target NVIDIA GPUs, although AMD Instinct and Intel Gaudi offer comparable FP8 paths.
  • Outlier sensitivity: activation outliers can still cause underflow with per-tensor scaling.
  • Debugging cost: divergence in FP8 runs is harder to diagnose than in bfloat16.
  • Advertised peak figures: quoted throughput often assumes structured sparsity, which real models rarely exploit.
  • FP4 training maturity: 4-bit training remains less proven than 4-bit inference.

In everyday language

Think of numbers in a computer as boxes. Bigger boxes hold more detail but take more space and time to move. Most AI models used 16-bit boxes. Transformer Engine lets the chip use 8-bit or 4-bit boxes for most of the work.

Small boxes can overflow. So the system keeps checking how big the numbers are. It then shrinks or stretches them to fit, a bit like zooming a photo to fit a frame. Sensitive steps still use the bigger boxes.

The key takeaway: the same model trains and answers faster, with almost no loss in quality.

Seen in the real world

A research group pretrains a 13-billion-parameter language model on a cluster of 256 H100 GPUs. With bfloat16, one training step takes a fixed amount of time and the planned run needs about four weeks. The team switches the linear layers to Transformer Engine modules with the FP8 hybrid recipe, keeping embeddings and the output layer in bfloat16.

After a short comparison run, the loss curves of the FP8 and bfloat16 versions overlap within normal run-to-run noise. Step time drops by roughly 30 to 40 percent, mostly in the attention and feed-forward matrix multiplications.

The full pretraining finishes about ten days earlier than planned, and the saved GPU hours fund an additional fine-tuning experiment. Later, the team serves the model on Blackwell GPUs with FP4 weights, which lets one GPU hold a model that previously needed two.