Transformer Engine (TE) is a library developed by NVIDIA for accelerating Transformer models on NVIDIA GPUs. It enables the use of 8-bit floating point (FP8) and 4-bit floating point (NVFP4) precision on architectures like Hopper, Ada, and Blackwell, significantly improving performance and reducing memory utilization during both training and inference. TE provides highly optimized building blocks for common Transformer architectures and an automatic mixed-precision-like API that integrates seamlessly with PyTorch and JAX. The library has frequent releases, often aligned with updates to NVIDIA's deep learning software stack.
pip install transformer-engineVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to initialize `transformer_engine.pytorch.Linear` and `transformer_engine.pytorch.TransformerLayer` modules and perform a forward pass using `fp8_autocast` for 8-bit floating point precision. It highlights the use of `torch.bfloat16` as a base precision and includes a basic FP8 recipe configuration. Ensure you have an NVIDIA GPU with CUDA installed.
Update C++ code or custom integrations to use the non-packed fused attention C APIs. Refer to the v2.13 release notes for specific migration details.
Review and invert boolean logic for padding masks in PyTorch code if it was written for versions prior to v1.7. `True` now *excludes* positions.
Update `InferenceParams` initialization and usage according to the v2.2 release notes, ensuring all new required arguments are provided and `pre_step` is called. Replace `swap_key_value_dict` usage with the new automatic reordering in `step`.
Avoid CPU offloading for weight tensors. When installing, always use `pip install transformer-engine --no-build-isolation` to prepare for future releases.
For optimal FP8 performance, use Transformer Engine with larger models and batch sizes where the computational benefits outweigh casting and CPU overheads. Ensure GPU compute can cover CPU overheads by avoiding frequent GPU synchronization.
Ensure your CUDA installation is 12.8 or newer. If not, install `transformer-engine` from source as a temporary workaround until this issue is fully addressed in later releases.
Be aware that FlashAttention may not be used for cross-attention with causal masking. If this specific scenario is critical for performance, consider alternative attention implementations or inspect your FlashAttention version.