Browse latest
Tools & PlatformsMarkTechPost · June 2, 2026

How to Speed Up Transformer Training Using NVIDIA Apex (FusedAdam, FusedLayerNorm) and Native torch.amp

This article explores optimizing Transformer training with NVIDIA Apex and torch.amp. It details setting up Apex with CUDA extensions, benchmarking FusedAdam and FusedLayerNorm against native PyTorch, and integrating these into a Transformer for performance gains.

Author: Morein.ai Editorial

Optimizing Transformer training is crucial for efficiency. This guide focuses on leveraging NVIDIA Apex and native torch.amp to accelerate these processes, building upon modern GPU training workflows. We isolate and test the still-useful components of Apex, moving beyond its general mixed-precision library identity. The setup involves checking the CUDA runtime, correctly building Apex with necessary CUDA and C++ extensions, and verifying the availability of fused kernels. This ensures that the high-performance kernels, essential for Apex's utility, are indeed active and not silently missed in a Python-only installation.

We benchmark FusedAdam against PyTorch's AdamW optimizer and compare FusedLayerNorm and FusedRMSNorm with standard normalization layers. The process also includes running examples for both legacy apex.amp and the more modern torch.amp. A key aspect is the preparation of the CUDA environment, confirming GPU availability, and detailing the active PyTorch, CUDA, and GPU configurations. We also define a reusable benchmarking helper for consistent performance evaluation.

The article includes an in-depth comparison of PyTorch AdamW and Apex FusedAdam using a model with multiple linear layers, designed to highlight optimizer overhead. This ensures the comparison accurately reflects update speed. Similarly, FusedLayerNorm and FusedRMSNorm are evaluated against standard normalization layers using a consistent input tensor, allowing for precise measurement of forward and backward pass times and effective speedup assessment.

Read original source

Related articles