Back to Hardware

Hugging Face's TorchNeuron makes AWS Trainium a first-class PyTorch target

Hugging Face has made AWS Trainium a first-class PyTorch target. The company published details of TorchNeuron on Oct 19, a PyTorch plugin that exposes neuron as a native device. Public beta starts Oct 20, 2026, and the install is a single pip install torch-neuronx.

With the new backend, Trainium gets eager mode, torch.compile, and PyTorch's native distributed APIs, including FSDP2, tensor parallelism, and DTensor. For a developer who has never touched AWS silicon, the practical change is one line: pass device_map="neuron" and the model runs on Trainium.

The authors of the post are Hugging Face staff, not AWS. That matters, because it is the model hub itself recommending its own libraries directly on a rival chip, in the middle of Amazon's running battle with Nvidia's GPU stack.

Replacing the Optimum Neuron path

Until now, running Hugging Face models on Trainium meant going through Optimum Neuron, a PyTorch-XLA-based path that forced lazy tensors, static shapes, and a recompilation at every graph break. Hugging Face now recommends using Transformers, Diffusers, Accelerate, PEFT, and TRL directly, without Optimum Neuron.

The coverage jump is the number to watch. According to Hugging Face's TorchNeuron post, 89% of the top 100 most-used text-generation architectures work out of the box, against 46% with Optimum Neuron v0.4.5.

Inference

The post's inference example runs Qwen/Qwen3.8-27B with tensor parallelism. A static generation cache is recommended on Neuron.

Diffusers models are compatible with tensor parallelism as well: FLUX.1-dev, FLUX.2, Qwen-Image, Qwen-Image-2.1, and H3. For vision transformers, Hugging Face points to a separate package, vit-encoder-neuron-kernels, which it says delivers up to 2.4x speedup on Trainium.

Training without modifications

A standard TRL SFTTrainer script runs unmodified on Trainium. With --torch_compile true, PyTorch selects the Neuron backend on its own. The demo fine-tunes Qwen/Qwen3-8B on HuggingFaceH4/ultrachat_200k in bfloat16, at a learning rate of 2e-5 for one epoch, on 8 Trainium2 chips (32 NeuronCores total, half a trn2.48xlarge instance), with tensor parallelism 4 and FSDP 8 via torchrun --nproc_per_node=32.

The output is a standard Transformers checkpoint. Nothing in it is tied to Neuron, according to the post: it can be pushed to the Hugging Face Hub as is.

The caveats

Hugging Face is upfront about what is still constrained. Shapes are static, and TRL at or above 1.16 pads batches to a multiple of 128 tokens. Async weight loading is off by default (HF_DEACTIVATE_ASYNC_LOAD=1), and dynamo's automatic dynamic shapes are disabled.

Why it matters

CUDA has been the moat in this competition. Every alternative accelerator has had to carry its own toolchain, its own tensor types, its own porting project. A model hub telling its users to point Transformers at neuron straight from stock PyTorch narrows that gap on the side with the most leverage, the users themselves. Trainium stops being a porting exercise and becomes a device string in an existing script.

Source: huggingface.co

More news

Back to Hardware

Have something in mind?

Start a conversation