Skip to main content
Back to timeline
Hugging Face - BlogSource publication:

Trainium stops demanding compiler-style code: a native PyTorch backend runs 89% of top text-generation architectures

Synopsis

Running Hugging Face models on AWS Trainium now rests on a different foundation: TorchNeuron, a native PyTorch backend, exposes Neuron chips as an ordinary device with eager execution, torch.compile and native distributed APIs, replacing the PyTorch XLA-based optimum-neuron. By Hugging Face's comparison, out-of-the-box support among the 100 most-used text-generation architectures rises from 46% with Optimum Neuron v0.4.5 to 89%. The backend enters public beta on October 20, 2026.

Source-provided article image: TorchNeuron: running HF models on AWS Trainium is easier than ever
Hugging Face

Interpretation

Running Hugging Face models on AWS Trainium no longer requires going through a library maintained specifically for Neuron chips; Transformers, Diffusers, Accelerate, PEFT and TRL can treat Trainium as an ordinary accelerator. The earlier path was optimum-neuron, built on the PyTorch XLA-based torch-neuronx, which asked users to think like a compiler: lazy tensors instead of eager execution, static shapes only, and a recompilation for every graph break. Hugging Face's comparison is coverage of text-generation architectures: 89% of the top 100 most-used text-generation model architectures are supported out of the box, against 46% with Optimum Neuron v0.4.5.

Integration means passing neuron as the device, after which the model is moved onto Neuron devices and inference and training reuse the same classes and scripts used on other accelerators. TorchNeuron is a PyTorch plugin that exposes neuron as a native device, supporting eager execution, torch.compile, and PyTorch's own distributed primitives such as DTensor and FSDP2. The training example ran to completion on 8 Trainium2 chips, 32 NeuronCores, half a trn2.48xlarge instance, sharding Qwen3-8B on a 4×8 tensor-parallel and FSDP grid and saving a standard Transformers checkpoint not tied to Neuron.

Perspective

The report covers how TorchNeuron, as a native PyTorch backend, plugs into the Hugging Face libraries, together with three examples: text generation, diffusion inference and TRL fine-tuning. The intended readers are researchers and engineers who need to run or fine-tune open models on AWS Trainium. The training example uses 8 Trainium2 chips, 32 NeuronCores, half a trn2.48xlarge instance.

Several constraints remain when running on Trainium: automatic dynamic shapes in torch.compile are not yet available, so the script disables them; batches are padded to a multiple of 128 tokens to limit the number of input shapes; and Transformers' built-in asynchronous weight loading is not supported on Neuron, so it is turned off with an environment variable. Among diffusion pipelines, only some support tensor parallelism, and others need support added following a guide. The public beta starts October 20, 2026.