---
title: "TorchNeuron: running HF models on AWS Trainium is easier than ever"
description: "TorchNeuron is a PyTorch plugin that exposes AWS Trainium as a native `neuron` device with eager execution, `torch.compile`, and native distributed APIs (DTensor, FSDP2, TP), replacing the PyTorch XLA–based path that required lazy tensors and static graphs."
url: "https://swe.quest/articles/torchneuron-running-hf-models-on-aws-trainium-is-easier-than-ever-99ae731bb5ca0252"
canonical: "https://huggingface.co/blog/hf-torchneuron"
source: "Hugging Face"
published: "2026-10-19"
difficulty: "medium"
kind: "Announcement"
reading_minutes: 7
tags: ["hardware","model-training","inference","python"]
---

# TorchNeuron: running HF models on AWS Trainium is easier than ever

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2026-10-19, 7 min read, Announcement. Original: [https://huggingface.co/blog/hf-torchneuron](https://huggingface.co/blog/hf-torchneuron)

## Summary

TorchNeuron is a PyTorch plugin that exposes AWS Trainium as a native \`neuron\` device with eager execution, \`torch.compile\`, and native distributed APIs (DTensor, FSDP2, TP), replacing the PyTorch XLA–based path that required lazy tensors and static graphs. As a result, Transformers, Diffusers, Accelerate, PEFT and TRL run directly on Trainium, and Hugging Face now recommends them over Optimum Neuron; 89% of the top 100 text-generation architectures work out of the box versus 46% before. Examples cover tensor-parallel generation with a static KV cache, TRL SFT with a TP×FSDP grid via \`DistributedConfig\`, and TP for Diffusers image pipelines. Practical caveats include keeping shapes static (padding to multiples of 128, disabling Dynamo automatic dynamic shapes) and disabling async weight loading; it enters public beta Oct. 20, 2026.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Hardware](https://swe.quest/tags/hardware.md) (Infrastructure)
- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Inference & serving](https://swe.quest/tags/inference.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)

## Prerequisites

- PyTorch basics
- Hugging Face Transformers
- tensor parallelism and FSDP ([easy posts on Concurrency](https://swe.quest/tags/concurrency.md?difficulty=easy))

## Keywords

TorchNeuron, AWS Trainium, Transformers, Diffusers, TRL, torch.compile, FSDP2, NKI

## Related posts

- [The science behind TorchNeuron, Amazon’s new PyTorch backend for AWS Trainium chips](https://swe.quest/articles/the-science-behind-torchneuron-amazon-s-new-pytorch-backend-for-aws-trainium-c2048563f9b5b6ed.md): Amazon Science · 2026-10-22 · Medium · 5 min read · Compilers, Hardware, Testing, Model training, Python
  TorchNeuron is an open-source PyTorch backend that runs existing PyTorch code on AWS Trainium with little or no change.
- [Does Your Model Run on AWS Trainium? Look It Up](https://swe.quest/articles/does-your-model-run-on-aws-trainium-look-it-up-4ce5c68bb56caf0e.md): Hugging Face · 2026-10-23 · Medium · 3 min read · Inference & serving, Hardware, Machine learning
  A Hugging Face Space reports whether popular Transformers models run unmodified on AWS Trainium via the TorchNeuron PyTorch backend.
- [Accelerating Hugging Face Transformers with AWS Inferentia2](https://swe.quest/articles/accelerating-hugging-face-transformers-with-aws-inferentia2-732d2daf15bc9874.md): Hugging Face · 2023-04-17 · Easy · 5 min read · Inference & serving, Hardware, Performance engineering, Cloud platforms
  Hugging Face benchmarked popular Transformer models on AWS Inferentia2 (inf2.xlarge) against Inferentia1 (inf1.2xlarge) and an NVIDIA A10G GPU (g5.2xlarge), running 144 p95-latency experiments at batch size 1 across six architectures and sequence lengths from 8 to 512.
- [Profiling TorchNeuron (Part 1): System-level profiling on AWS Trainium.](https://swe.quest/articles/profiling-torchneuron-part-1-system-level-profiling-on-aws-trainium-034696b775aee014.md): Hugging Face · 2026-10-21 · Medium · 9 min read · Performance engineering, Inference & serving, Hardware, Python
  A beginner-friendly walkthrough of system-level profiling for PyTorch on AWS Trainium using TorchNeuron.
- [Hugging Face ❤️ TorchTPU: TPUs, Natively](https://swe.quest/articles/hugging-face-torchtpu-tpus-natively-25e58a9bb63cbf24.md): Hugging Face · 2026-10-20 · Medium · 6 min read · Inference & serving, Hardware, Python, Machine learning
  TorchTPU is a native PyTorch backend that makes TPU an ordinary device, replacing the lazy-tensor torch\_xla path and making Optimum TPU unnecessary for running Hugging Face models.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
