News

日本語 · English · 中文

Hugging Face supports new PyTorch backend "TorchNeuron" for AWS Trainium—Transformers and TRL work as is

Hugging Face introduced on October 19, 2026, that its libraries, including Transformers and Diffusers, now support TorchNeuron, the PyTorch backend developed by AWS for AWS's AI chip Trainium. TorchNeuron will be available in public beta starting October 20. It supports 89% of the architectures of the top 100 most-used text generation models, expanding on the 46% coverage of the previous Optimum Neuron v0.4.5.

Hugging Face blogged on October 19, 2026, that its libraries Transformers, Diffusers, and Kernels are now compatible with TorchNeuron, a new PyTorch backend for AWS AI chips Trainium. TorchNeuron was developed by AWS, and Hugging Face expressed gratitude to the AWS team in its blog post.

What is TorchNeuron?

TorchNeuron is scheduled to be offered as a public beta starting on October 20, 2026. Researchers and developers can install it via pip install torch-neuronx.

TorchNeuron is a plugin directly integrated into PyTorch, allowing Trainium to be treated as a native device. It supports Eager mode, torch.compile, and PyTorch standard distributed APIs (DTensor, FSDP2). Previously, using Hugging Face libraries on Trainium or Inferentia required the dedicated library optimum-neuron, which was PyTorch XLA-based and necessitated compiler-aware usage such as delayed tensors and static shapes. With TorchNeuron, this complexity is eliminated, enabling libraries like Transformers, Diffusers, Accelerate, PEFT, and TRL to run on Trainium using code similar to that used for other accelerators. Hugging Face recommends using these libraries directly rather than through Optimum Neuron from now on.

Inference and Training in Transformers

According to Hugging Face, TorchNeuron enables standard support for 89% of the top 100 architectures in text generation models, compared to 46% with the conventional Optimum Neuron v0.4.5. In code, models can be moved to a Neuron device simply by passing the device_map=neuron argument. An example of text generation using tensor parallelism is also provided, with a recommendation to use static caching to prevent recompilation.

Since Trainium has become a native PyTorch device with TorchNeuron, standard fine-tuning scripts using TRL’s SFTTrainer can now be executed on Trainium as is. Specifying Tensor Parallel (TP) and FSDP sizes in model_init_kwargs will shard the model weights during loading. For execution on Trainium, care must be taken regarding static shape settings, enabling torch.compile, and disabling asynchronous weight loading (HF_DEACTIVATE_ASYNC_LOAD=1).

Hugging Face stated that it ran this script on eight Trainium2 chips (32 NeuronCores). This corresponds to half of a trn2.48xlarge instance. After training, standard Transformers checkpoints are saved via trainer.save_model, and can be pushed to Hugging Face Hub and loaded on other hardware.

Diffusers and Kernels

Many pipelines in the Diffusers library operate in both Eager mode and compiled mode of TorchNeuron. FLUX.1-dev, FLUX.2, Qwen-Image, Qwen-Image-2.1, and H3 also support tensor parallelism, allowing for full utilization of Neuron devices. Execution is performed as follows: NEURON_LOGICAL_NC_CONFIG=2 torchrun --nproc_per_node=8 run.py. The list of supported pipelines is expected to grow, and for unsupported pipelines, additional support can be implemented by following the guide.

Additionally, kernels from the Neuron team are being published on Hugging Face Hub. Using the Neuron Kernel Interface (NKI), custom operations can be defined and shared on the Hub. For example, a kernel is introduced that claims to accelerate vision transformers on Trainium by up to 2.4 times. It is not specified what this value is compared against.

How to View This

The significant change is that using Trainium no longer requires a dedicated library (Optimum Neuron), and scripts for Transformers and TRL used on GPUs can now run as is. The trained models are saved in the standard Transformers format and can be read by other hardware.

On the other hand, the provided figures are limited. They include the percentage of supported architectures (89% of the top 100 text generation models, compared to 46% with Optimum Neuron v0.4.5) and a kernel performance claim of "up to 2.4 times." There are no figures comparing inference or training speeds against GPUs or Optimum Neuron. While the training example reportedly ran to completion on eight Trainium2 chips, the time taken is not mentioned. Limitations as a beta version are also noted, such as the lack of support for dynamic shapes and the inability to use asynchronous weight loading.

This article was translated from the Japanese original. 日本語で読む

← Latest articles