The engineering behind inference.Contact ↗
Batch & Release/Inference

TorchNeuron brings native PyTorch backend to AWS Trainium

AWS and PyTorch announce TorchNeuron, an open source native backend that runs existing PyTorch code on Trainium2 and Trainium3 with eager, torch.compile, and custom NKI kernels.

TorchNeuron brings native PyTorch backend to AWS Trainium
Image: PyTorch ↗

AWS and PyTorch announced TorchNeuron, an open source native PyTorch backend for AWS Trainium, ahead of its public Beta launch at PyTorch Conference North America on Oct. 20. The backend registers Trainium through PyTorch's PrivateUse1 extension point and the torch.accelerator APIs, so existing model code, libraries, and tools run on the chip with minimal changes. TorchNeuron supports eager execution, including a new adaptive eager mode, torch.compile for production performance, and the Neuron Kernel Interface (NKI) for custom operators, on Trainium2 and Trainium3. The project is released under Apache 2.0 at github.com/aws-neuron/torch-neuronx.

Device switching and execution modes

Running a model on Trainium requires moving tensors to the neuron device with the pointer .to('neuron'). Code written against torch.accelerator, PyTorch's device-agnostic API, runs unmodified. For compiled models, users name the Neuron backend once with torch.compiler.set_default_backend("neuron"), after which torch.compile(model) picks it up, or pass backend="neuron" per call.

Eager mode dispatches operations individually, compiling each operation into a Neuron Executable File Format (NEFF) file, launching it on device, and moving intermediates through HBM. This mode suits research and debugging, with Python control flow, prints, and breakpoints working as usual. The experimental adaptive eager mode reduces launch cost and fuses operations to approach compiled graph performance without code changes.

torch.compile(model, backend="neuron") captures the model into a graph that the Neuron compiler optimizes. TorchDynamo builds an FX graph, AOTAutograd traces the backward graph ahead of time, the Neuron backend lowers it through Torch-MLIR into StableHLO, and the Neuron compiler produces a NEFF file. FlexAttention is supported natively. The Neuron inference stacks, including vLLM Neuron for LLMs and vLLM Omni Neuron for diffusion models, build on the same torch.compile support.

Ops, dtypes, and distributed APIs

The backend covers a broad set of aten operators across text, multimodal, vision language, image and video generation, state space models, and world models. Models can use BF16, FP32, FP16, integer, and boolean types, with torch.autocast and mixed precision code working as written. TorchAO and FP8 are in private Beta and will be generally available in the next release.

Distributed training and inference use standard PyTorch APIs, including DDP, FSDP2, SimpleFSDP, tensor parallelism, and pipeline parallelism, plus compositions like FSDP2 with tensor parallelism and ZeRO. DTensor and DeviceMesh handle sharding and multi-dimensional process groups. Collectives run over Trainium's dedicated collective cores intra-node and over the Elastic Fabric Adapter (EFA) inter-node, with no change to PyTorch APIs.

Streams, custom kernels, and profiling

Torch streams and events map onto Trainium's hardware queues. Within a stream, data movement and computation stay in order automatically; across streams, users make ordering explicit with events. Non-default streams multiplex onto a single hardware queue, preserving ordering, priority, and event semantics without dedicated engines. Errors surface at the next synchronization point, with TorchNeuron tracking the earliest exception and re-raising it with its original context.

NKI lets developers write custom operators for both eager and torch.compile, with the PyTorch recommended register_autograd style for autograd support. NKI-lib provides Trainium-optimized operators for mainstream LLM and multimodal scenarios, including FlashAttention and MoE blockwise kernels.

Profiling integrates with torch.profiler.profile, extended with a NeuronConfig object for Neuron-specific data collection. Traces can be visualized in Neuron Explorer, which links events to source lines, shows call hierarchies, and follows dependency chains. Neuron Explorer also emits a Parquet output with per-op and per-engine metrics for programmatic analysis, and the key_averages table lets users sort by device-side cost to identify hotspots.

Sources & references

PyTorch: Introducing TorchNeuron: Native PyTorch backend for AWS Trainium ↗Source consulted: 2026-10-22

Privacy choices

We remember your answer in this browser for 180 days. Come back here whenever you want to change it.

EssentialSaves your answer in this browser. No cookies, no third parties.Always active