Skip to main content
Back to timeline
PyTorchSource publication:

Trainium stops demanding rewrites: TorchNeuron runs existing PyTorch code by changing one device name

Synopsis

AWS released TorchNeuron, a native PyTorch backend for Trainium chips, so model code, libraries and tools run without Neuron-specific adaptation. Previously, using Hugging Face models on Trainium required Neuron-specific software and configuration; now the device is simply pointed at neuron. It registers the device through PyTorch's PrivateUse1 extension point, supports eager, torch.compile and custom NKI kernels across Trainium2 and Trainium3, and ships as an Apache 2.0 public Beta on Oct. 20.

Source-provided article image: Introducing TorchNeuron: Native PyTorch backend for AWS Trainium
PyTorch Blog

Interpretation

Trainium now appears as a standard PyTorch device, so model code, training and serving libraries, and debugging tools run as written instead of needing a separate adaptation layer for the chip. Previously, taking advantage of Trainium required adapting Hugging Face models with Neuron-specific software and configuration; PyTorch had spent several years making its APIs accelerator-agnostic with official extension points for registering custom hardware. Switching devices takes a single .to('neuron') call on the model, and code written against torch.accelerator runs unmodified; compiled models name the backend once through torch.compiler.set_default_backend("neuron").

The backend registers Trainium in PyTorch's device enumeration, so standard interfaces such as torch.nn, torch.tensor, torch.autocast, torch.distributed and torch.profiler act directly on the neuron device. Registration goes through PyTorch's official PrivateUse1 extension point for custom hardware rather than a parallel API. Both execution modes work natively: eager runs operations one at a time for research and debugging, while torch.compile captures the model into a graph, lowers it through Torch-MLIR into StableHLO, and the Neuron compiler produces a NEFF file that executes on hardware.

Performance engineers use the same torch.profiler to trace events across framework, runtime and chip, and to jump back to the exact source line when locating a bottleneck. The profiler collects Neuron-specific data through a NeuronConfig object, and captured traces are viewed in the Neuron Explorer UI. Neuron Explorer also emits Parquet output with per-op and per-engine metrics that can be queried directly or consumed by agents for automated bottleneck analysis.

Perspective

The release targets researchers and engineers doing training and inference in PyTorch, covers Trainium2 and Trainium3, and is available as an Apache 2.0 public Beta on GitHub from Oct. 20, installable via pip. Supported scope includes eager execution, torch.compile, custom NKI kernels, standard distributed interfaces such as DDP, FSDP2, tensor parallelism and pipeline parallelism, and the vLLM and vLLM Omni serving plugins.

The first release explicitly does not support several features, including sparse tensors and sparse ops, NestedTensor, forward-mode autograd, arbitrary attention masks in native multi-head attention, per-channel quantization, and dynamic and symbolic shapes. Of about 154K upstream test outcomes, roughly 69K were skipped, about 22K of them because operators lack a native Neuron lowering, which the announcement says will be closed in sequential releases. TorchAO and FP8 are currently in private Beta.