####### ############# ### #### #### ### ### ### ### ### ### ### #### #### ### ### ### ### ### ###### ### ### ### ### ### #### ### ### ### ### ##### ### ####### #### ### ### ### ### ### ######### ### ### ### ### ### #### ### #### ### ######## ### ### ### ####### ### ######## #### #### ### ##### ### ############# #######
README
A guide to AWS Trainium and Inferentia chips and the software that runs on them.
AWS builds two families of machine learning chips. Inferentia and Inferentia2 are designed for inference: running a trained model. Trainium, Trainium2, and Trainium3 support both training and inference. AWS calls each chip a Neuron device. An EC2 instance such as Trn2 provides the host CPU, host memory, and one or more of those devices.
From PyTorch to a chip#
- Choose a software path. On Trn2 or Trn3, TorchNeuron lets supported PyTorch code use the
neurondevice. The same entry links to examples for Hugging Face inference and fine-tuning. For serving a supported language model behind an API, start with vLLM Neuron. See the Neuron SDK for other workloads and older instance families. - Compile and run. The compiler turns operations into a NEFF, the executable that the runtime loads and runs on the device.
- Follow the data. A modern NeuronCore brings small blocks of data called tiles from device memory into a fast scratchpad, SBUF. The Tensor Engine reads those tiles for matrix multiplication and accumulates results in PSUM. The compiler handles these transfers for framework code. When you write a custom NKI kernel, you can control them directly.
If you already know GPUs#
These comparisons map familiar roles. NeuronCore-v2 and later execute instructions on specialized engines that work on blocks of data called tiles.
| CUDA / NVIDIA | Neuron | How it maps |
|---|---|---|
| Streaming Multiprocessor | NeuronCore | A core on the accelerator with separate compute engines on v2 and later |
| Tensor Core | Tensor Engine | Runs matrix multiplication using a systolic array |
| CUDA Core | Vector and Scalar Engines | Handle operations such as reductions and element-wise math |
| Thread, warp, thread block | — | NKI programs express work as operations on tiles |
| Shared memory | SBUF | A scratchpad that the compiler or kernel manages. The Tensor Engine writes its results to PSUM |
| VRAM | HBM | Device memory on Inferentia2 and Trainium. First-generation Inferentia uses DDR4 |
| L2 cache | — | Neuron uses software-managed memory. The program schedules the transfers between device memory and on-chip scratchpads |
| CUDA C++ | NKI | Write custom kernels in Python |
| PTX / SASS | NISA | Low-level operations exposed through NKI's nki.isa module |
cubin | NEFF | Device executable, often specialized to input shapes |
nvcc | neuronx-cc | Compiles graphs and schedules device data movement |
| CUDA runtime | Neuron Runtime | Loads and runs device executables |
nvidia.ko | Neuron driver | Connects the host runtime to devices |
nvidia-smi | neuron-ls, neuron-top | List devices and inspect live utilization |
| Nsight Systems | Neuron Explorer | Profiles host and device activity, including individual engines |
| NCCL | Neuron Collectives | Coordinates group communication using dedicated cores on supported chips |
| NVLink | NeuronLink | Connects chips within an instance or an UltraServer |
| Occupancy | Latency hiding | Use independent work and pipeline depth to keep engines busy |
| Shared-memory bank conflict | PSUM bank conflict | Engines can contend for access to the same PSUM bank |
PyTorch eager and torch.compile | TorchNeuron | On-demand operator execution or compiled graphs on Trn2 and Trn3 |
For the CUDA side of the comparison, see Modal's GPU Glossary.
98 terms across 4 sections.
Device Hardware
This section covers the chips AWS designs for machine learning, the compute engines and memory inside them, and the links that let chips work together.
Start with Neuron device for the whole chip and NeuronCore for the part that runs model operations.
To see how chips connect across servers, compare the Trn2 UltraServer with Trn3 UltraServers and their NeuronSwitch.
- Collective Communication EngineCCE
- Descriptor Generation EngineDGE
- Device memoryHBM
- DMA engine
- Elastic Fabric AdapterEFA
- GpSimd Engine
- Inf1
- Inf2
- Inferentia
- Inferentia2
- Neuron deviceND
- NeuronCoreNC
- NeuronCore-v1
- NeuronCore-v2
- NeuronCore-v3
- NeuronCore-v4
- NeuronLink
- NeuronSwitch
- Partial Sum BufferPSUM
- Scalar Engine
- State BufferSBUF
- Sync Engine
- Systolic array
- Tensor Engine
- Trainium
- Trainium2
- Trainium3
- Trn1
- Trn2
- Trn2 UltraServer
- Trn3 UltraServer
- UltraCluster
- Vector Engine
Device Software
This section covers the code that runs on a Neuron device. It explains how kernels lay out data in on-chip memory, which instructions they can use, and what the compiler puts in the device executable.
If you are writing kernels, this is your section. Start with NKI and tiles.
- cFP8
- Collectives
- Custom C++ operators
- Data types
- DMA transpose
- Free dimension
- Logical NeuronCoreLNC
- MXFP8 / MXFP4
- Neuron Executable FormatNEFF
- Neuron Instruction SetNISA
- Neuron Kernel InterfaceNKI
- NKI CPU simulator
- NKI Library
- nki.language
- Partition dimension
- Rounding mode
- Software-managed memory
- Stationary & moving
- Structured sparsity
- Tile
- Tiling
Host Software
The software on the host CPU connects your application to the Neuron accelerator. A framework or serving engine asks the compiler to build an executable. The runtime loads it and works with the driver to run it on the accelerator.
Start with the Neuron SDK to find the framework for your workload. Use neuron-ls to see which devices your instance exposes and Neuron Explorer to see where a workload spends its time.
- JAX NeuronX
- nccom-test
- Neuron compilerneuronx-cc
- Neuron device plugin (K8s)
- Neuron DLAMI & containersDLC
- Neuron DRADRA
- Neuron driver
- Neuron Explorer
- Neuron Observer
- Neuron persistent cache
- Neuron Runtimelibnrt
- Neuron SDK
- neuron-ls
- neuron-monitor
- neuron-top
- NxD Core
- NxD InferenceNxDI
- NxD TrainingNxDT
- SGLang-Neuron
- torch-neuronx
- TorchNeuron
- TorchTitan Neuron
- transformers-neuronxTNx
- vLLM Neuron
- vLLM Omni Neuron
- XLA and HLOXLA
Performance
Start with arithmetic intensity and the roofline model to estimate whether data movement or arithmetic sets the limit. Use Neuron Explorer to see which engines are busy and what they are waiting for.
Device Hardware
This section covers the chips AWS designs for machine learning, the compute engines and memory inside them, and the links that let chips work together.
Start with Neuron device for the whole chip and NeuronCore for the part that runs model operations.
To see how chips connect across servers, compare the Trn2 UltraServer with Trn3 UltraServers and their NeuronSwitch.
- Collective Communication EngineCCE
- Descriptor Generation EngineDGE
- Device memoryHBM
- DMA engine
- Elastic Fabric AdapterEFA
- GpSimd Engine
- Inf1
- Inf2
- Inferentia
- Inferentia2
- Neuron deviceND
- NeuronCoreNC
- NeuronCore-v1
- NeuronCore-v2
- NeuronCore-v3
- NeuronCore-v4
- NeuronLink
- NeuronSwitch
- Partial Sum BufferPSUM
- Scalar Engine
- State BufferSBUF
- Sync Engine
- Systolic array
- Tensor Engine
- Trainium
- Trainium2
- Trainium3
- Trn1
- Trn2
- Trn2 UltraServer
- Trn3 UltraServer
- UltraCluster
- Vector Engine
Device Software
This section covers the code that runs on a Neuron device. It explains how kernels lay out data in on-chip memory, which instructions they can use, and what the compiler puts in the device executable.
If you are writing kernels, this is your section. Start with NKI and tiles.
- cFP8
- Collectives
- Custom C++ operators
- Data types
- DMA transpose
- Free dimension
- Logical NeuronCoreLNC
- MXFP8 / MXFP4
- Neuron Executable FormatNEFF
- Neuron Instruction SetNISA
- Neuron Kernel InterfaceNKI
- NKI CPU simulator
- NKI Library
- nki.language
- Partition dimension
- Rounding mode
- Software-managed memory
- Stationary & moving
- Structured sparsity
- Tile
- Tiling
Host Software
The software on the host CPU connects your application to the Neuron accelerator. A framework or serving engine asks the compiler to build an executable. The runtime loads it and works with the driver to run it on the accelerator.
Start with the Neuron SDK to find the framework for your workload. Use neuron-ls to see which devices your instance exposes and Neuron Explorer to see where a workload spends its time.
- JAX NeuronX
- nccom-test
- Neuron compilerneuronx-cc
- Neuron device plugin (K8s)
- Neuron DLAMI & containersDLC
- Neuron DRADRA
- Neuron driver
- Neuron Explorer
- Neuron Observer
- Neuron persistent cache
- Neuron Runtimelibnrt
- Neuron SDK
- neuron-ls
- neuron-monitor
- neuron-top
- NxD Core
- NxD InferenceNxDI
- NxD TrainingNxDT
- SGLang-Neuron
- torch-neuronx
- TorchNeuron
- TorchTitan Neuron
- transformers-neuronxTNx
- vLLM Neuron
- vLLM Omni Neuron
- XLA and HLOXLA
Performance
Start with arithmetic intensity and the roofline model to estimate whether data movement or arithmetic sets the limit. Use Neuron Explorer to see which engines are busy and what they are waiting for.
What is the Collective Communication Engine?CCE
The Collective Communication Engine (CCE) uses dedicated CC-Cores to handle collectives. These are operations in which a group of NeuronCores exchange or combine data, such as all-reduce, all-gather, reduce-scatter and all-to-all.
Dedicated hardware lets communication overlap with computation. For example, each replica in data-parallel training computes gradients for its batch. CC-Cores can combine the gradients for layers that have finished while the Tensor, Vector, and Scalar engines work on other layers.
If computation needs the result of a collective, it still has to wait for communication to finish.
CC-Cores drive traffic over NeuronLink within a scale-up domain. A domain can span multiple servers in an UltraServer. Across scale-up domains, collectives use EFA.
Counts per chip:
| Chip | CC-Cores |
|---|---|
| Trainium / Inferentia2 | 6 |
| Trainium2 | 16 in the chip architecture, 20 in the NKI guide |
| Trainium3 | 16 in the chip architecture, 20 in the NKI guide |
You do not program CC-Cores directly in normal use. Collectives are invoked through frameworks and libraries such as TorchNeuron and NxD Inference, and executed by the Neuron runtime. NKI kernels on Trn2 and Trn3 can request collective operations through nki.collectives. NKI collectives reference
To measure what the hardware actually achieves, use nccom-test, the Neuron equivalent of NCCL's benchmark tools.
What is the Descriptor Generation Engine?DGE
The Descriptor Generation Engine (DGE) is dedicated hardware, introduced in NeuronCore-v3, that generates DMA descriptors on demand. Each NeuronCore-v3 has two DGE instances.
A DMA descriptor tells a DMA engine what to move. It records where to read, where to write, how much data to copy, and how far to step between elements. A kernel that processes data in tiles can need many descriptors. Before v3, Neuron generated them in two ways.
- Static generation. The host computed every descriptor when loading the NEFF, and stored them all in HBM, using space that could otherwise hold model parameters or activations.
- Software DGE. Descriptors were generated during execution by custom kernels running on the GpSimd Engine, stored in a slice of SBUF. This saved HBM space and kept a compute engine busy calculating addresses.
Hardware DGE generates descriptors as each transfer needs them and leaves GpSimd free for computation. AWS recommends using it wherever possible on Trainium2.
Programming it#
In an NKI kernel, set dge_mode on the transfer instruction.
import nki.isa as nisa
nisa.dma_copy(dst, src, dge_mode=nisa.dge_mode.hwdge)
nisa.dma_transpose(dst=sbuf_dst, src=hbm_src, dge_mode=nisa.dge_mode.hwdge)
Hardware DGE transpose has specific tile shape and data type requirements. NKI dma_transpose reference
The Sync Engine or Scalar Engine issues the command. The compiler can choose the engine, and nisa.dma_copy also accepts an explicit engine argument for hardware DGE. NKI dma_copy reference
Performance notes#
A DGE-based DMA instruction takes about 600 ns on NeuronCore-v3.
When the Scalar Engine issues it, DGE can run alongside earlier Scalar Engine compute such as nisa.activate(). The descriptor hardware and the compute pipeline can work independently.
Limitation#
On NeuronCore-v3, indirect DMA operations such as gather and scatter use software DGE. They take an array of indices to determine which rows to read or write. Trainium2 NKI architecture guide
What is HBM on a Neuron device?HBM
HBM stands for High Bandwidth Memory. On Trainium and Inferentia2, it is the main memory attached to the Neuron device, similar to a GPU's VRAM. It holds model weights, intermediate activations, optimizer state, and the KV cache.
| Chip | Capacity | Bandwidth |
|---|---|---|
| Inferentia | 8 GiB (DRAM, not HBM) | 50 GiB/s |
| Trainium / Inferentia2 | 32 GiB | 820 GiB/s |
| Trainium2 | 96 GiB | 2.9 TB/s |
| Trainium3 | 144 GiB | 4.9 TB/s in the chip architecture, 4.7 TB/s in the NKI guide |
AWS uses "device memory" for both HBM and the DDR memory on first-generation Inferentia. The chip architecture documents list 820 GiB/s for Trainium and Inferentia2, where the NKI architecture guide writes 820 GB/s. Trainium architecture, Trainium/Inferentia2 NKI architecture guide
Where it sits#
On a v2 or later system, data moves through these memories.
| Level | Memory | Scope |
|---|---|---|
| Fastest | PSUM | per NeuronCore, on-chip |
| SBUF | per NeuronCore, on-chip | |
| HBM | per device, off-core | |
| Slowest | Host DRAM | per instance, over PCIe |
HBM and host memory store tensors in a linear address space. SBUF and PSUM split data across 128 partitions. A plain DMA copy can distribute tensor rows from HBM across SBUF partitions. A DMA transpose can map a different tensor axis to the partition dimension.
At the model boundary, a typical NKI kernel takes device-memory tensors, loads tiles into SBUF, computes on them and stores the result back to HBM. The host framework moves tensors between host and device memory.
How bandwidth affects token generation#
In a batch-one decode step for a dense language model, each large weight matrix is typically read from HBM and used once. That is little work per byte moved, so decoding is often memory-bound.
A weight-only ceiling for token throughput is:
tokens/sec ≈ HBM bandwidth / bytes of model weights
A 70B model has about 140 GB of BF16 weights and needs more than one 96 GiB Trainium2 chip. If two chips stream a balanced share of the weights at their combined peak of 5.8 TB/s, the idealized bandwidth ceiling is about 41 tokens/s at batch one. That estimate excludes KV-cache traffic and inter-chip communication. FP8 approximately halves the bytes needed for the weights.
Note that the bandwidth figures above are per chip, shared across all of its NeuronCores — 2.9 TB/s serves eight cores on Trainium2.
Pooling#
NeuronLink makes the HBM of multiple chips directly addressable from any chip in the pool: up to 16 chips on Trn1, 64 on a Trn2 UltraServer and 64 or 144 on a Trn3 UltraServer. The memory is still physically distributed, so remote and local accesses use different paths.
Data movement between HBM and SBUF is done by DMA engines, which run in parallel with computation and support inline compression and decompression.
What is a DMA engine?
Direct memory access (DMA) engines move data independently of the hardware that performs computations. On a Neuron device they carry tensors between HBM and SBUF, between SBUF and SBUF, and between chips.
These counts and peak DMA bandwidths are per chip.
| Chip | DMA engines | DMA bandwidth |
|---|---|---|
| Trainium / Inferentia2 | 32 | 1 TB/s |
| Trainium2 | 128 | 3.5 TB/s |
| Trainium3 | 128 | 4.9 TB/s |
Trainium3 NKI architecture guide, Trainium3 chip architecture
On Trainium2, each NeuronCore-v3 is typically uses 16 DMA engines in parallel to make use of its SBUF bandwidth.
DMA transfers run in parallel with computation. This is the mechanism behind latency hiding: while the Tensor Engine works on tile n, DMA engines can fetch tile n+1. If the next tile arrives in time, computation can continue without waiting for the load.
A sequencer starts a transfer with a control instruction. The Sync Engine can issue that instruction on a separate stream from the compute engines.
Inline compression#
Neuron DMA engines perform inline memory compression and decompression as data moves, from Trainium and Inferentia2 onward. The benefit depends on how well the data compresses. Trainium3 also introduces operations such as adding incoming values to an existing SBUF tensor during a transfer.
DMA transpose#
From Trainium2, DMA engines can swap tensor axes during a transfer from HBM to SBUF or between SBUF tensors. This lets a transfer place the axis the Tensor Engine needs across the partitions in SBUF.
For example, attention may store keys as [seqlen, d_head] in the KV cache. When the Tensor Engine computes attention scores, it sums over d_head. A DMA transpose puts that axis in the SBUF partition dimension during the load.
For Trainium2, AWS reports up to 90% DMA throughput utilization for an HBM-to-SBUF transpose with suitable access patterns, up to 100% for a plain copy, and up to 50% for an SBUF-to-SBUF transpose. Trainium2 NKI architecture guide
Descriptors#
A DMA transfer uses descriptors that give the source and destination addresses, sizes and strides. Neuron can generate them in several ways.
- Static. Descriptors generated on the host when the NEFF is loaded, and stored in HBM.
- Software DGE. Generated at runtime by custom kernels on the GpSimd Engine, using SBUF for storage.
- Hardware DGE. From NeuronCore-v3, a dedicated Descriptor Generation Engine generates them on demand without using the GpSimd Engine or reserving descriptor space in HBM or SBUF.
Ordering#
Trainium used write-after-write DMA barriers. Trainium2 uses strong-order-write, which is generally faster, by an amount that depends on transfer size.
Separately, each of the eight processors in a NeuronCore-v3 GpSimd Engine has its own integrated DMA engine — 307 GB/s across all eight — running in parallel with both GpSimd compute and the main DMA engines.
What is EFA?EFA
EFA, the Elastic Fabric Adapter, is AWS's high-performance EC2 network interface. On supported Neuron instances it carries collective communication across NeuronLink domains, including between standalone instances or between UltraServers. With EFA's OS bypass, a userspace application can send and receive data through the Libfabric networking library without going through the operating system's network stack. AWS EC2 EFA documentation
| Platform | EFA bandwidth and scope |
|---|---|
| Inf1 | 100 Gbps on inf1.24xlarge only |
| Inf2 | Unsupported |
| Trn1 | EFAv2, 800 Gbps on trn1.32xlarge and 1,600 Gbps on trn1n.32xlarge |
| Trn2 | EFAv3, 3,200 Gbps per 48xlarge instance |
| Trn3 UltraServer | 12,800 Gbps aggregate on Gen1 and 57,600 Gbps aggregate on Gen2 |
EC2 network specifications, EC2 Trn1 product details, EC2 Trn2 product details, AWS Neuron Trn3 specifications
For the one-chip trn2.3xlarge, EC2 lists EFA support and 200 Gbps of network bandwidth. The Trn2 architecture entry explains where the Neuron guide differs.
Bandwidth in perspective#
On a standalone Trn2 48xlarge, 3,200 Gbps is 400 GB/s for the instance. If all 16 chips split the bandwidth evenly, that would be 25 GB/s per chip. Within the instance, NeuronLink-v3 is rated at 1,024 GiB/s per chip. The figures describe different paths and scopes, but illustrate why frequent tensor-parallel collectives often stay on NeuronLink. The rate you measure depends on the collective and where its participants run.
EFA is the scale-out fabric of an UltraCluster. To measure collective bandwidth, use nccom-test.
What is the GpSimd Engine?
The GpSimd Engine (GpSimdE) is a group of eight programmable 512-bit vector processors in each NeuronCore starting with v2. They can run C/C++ programs and read and write SBUF directly.
Where the Tensor, Vector, and Scalar engines are specialized for particular operations, GpSimd can run general-purpose code. For example, a kernel can use it to apply a triangle-shaped mask to a tensor without sending the tensor back to the host CPU.
Custom operators#
The legacy Neuron Custom C++ Operators library exposes GpSimd for custom operators on NeuronCore-v2. AWS directs developers writing new operators to NKI, which can use the specialized engines directly.
Generation notes#
On NeuronCore-v3, each of the eight processors gains its own integrated DMA engine. These run in parallel with GpSimd computation and in parallel with the device's main DMA engines, and they can reach SBUF or HBM on chips in the same Trn2 instance. All eight together provide 307 GB/s, split as 153 GB/s per direction.
Also on v3, the Vector and GpSimd engines can access SBUF in parallel, which was disallowed on v2. The two share a memory bus that the Vector Engine's performance mode also uses, with the hardware arbitrating between them.
GpSimd can also generate DMA descriptors at runtime. On v3 and later, the dedicated Descriptor Generation Engine can handle supported transfers and leave GpSimd available for other work.
NeuronCore-v4 keeps the same eight-processor structure and programmable C/C++ hardware. The legacy aws-neuronx-gpsimd-customop-lib package is documented for v2 (Trn1 and Inf2) and entered maintenance in Neuron 2.33.0. The v4 architecture guide describes the programmable hardware. NeuronCore-v4 architecture, Custom C++ library release notes, Maintenance announcement
In AWS's abbreviations this appears as GpSimdE.
What is an Inf1 instance?
Inf1 is the EC2 instance family powered by first-generation Inferentia chips. AWS launched it in 2019 for model inference.
| Size | Chips | vCPUs | Host memory | FP16/BF16 TFLOPS | INT8 TOPS | Device memory | Device bandwidth | NeuronLink | EFA |
|---|---|---|---|---|---|---|---|---|---|
inf1.xlarge | 1 | 4 | 8 GiB | 64 | 128 | 8 GiB | 50 GiB/s | — | — |
inf1.2xlarge | 1 | 8 | 16 GiB | 64 | 128 | 8 GiB | 50 GiB/s | — | — |
inf1.6xlarge | 4 | 24 | 48 GiB | 256 | 512 | 32 GiB | 200 GiB/s | 32 GiB/s | — |
inf1.24xlarge | 16 | 96 | 192 GiB | 1,024 | 2,048 | 128 GiB | 800 GiB/s | 32 GiB/s | 100 Gbps |
The smaller sizes have up to 25 Gbps of general network bandwidth. The Neuron Inf1 table labels that column EFA, but EC2's network table and EFA support list identify inf1.24xlarge as the only Inf1 size with EFA. AWS Neuron Inf1 architecture, EC2 network specifications, EC2 EFA support
Each chip carries four NeuronCore-v1 cores, so a full inf1.24xlarge exposes 64 NeuronCores.
Inf1 supports NeuronCore Pipeline over NeuronLink-v1: a model is split by layer across several cores. The cores pass intermediate results along the chain and can keep their own weights in on-chip memory when those weights fit.
Model fit#
AWS's Inf1 examples include convolutional networks such as ResNet-50 and encoders such as BERT-base. For large language models, each chip's 8 GiB limits how many weights it can hold, and 50 GiB/s limits how fast it can read them during memory-bound decoding.
The 128 GiB on inf1.24xlarge is the sum of 16 separate 8 GiB memories. Directly addressable memory pooling arrived with NeuronLink-v2.
Software#
Inf1 uses the legacy neuron-cc compiler and archived framework integrations, including torch-neuron for older PyTorch and tensorflow-neuron for TensorFlow. Modern TorchNeuron, PyTorch NeuronX and NKI target newer hardware. Moving an Inf1 model to a newer accelerator requires compiling for the new target with its supported framework. AWS Inf1 installation archive, Neuron Graph Compiler documentation
What is an Inf2 instance?
Inf2 is the EC2 instance family powered by Inferentia2 chips. It is AWS's inference-optimized family for the NeuronCore-v2 generation.
| Size | Chips | vCPUs | Host memory | FP8/FP16/BF16/TF32 TFLOPS | FP32 TFLOPS | Device memory | Device bandwidth | NeuronLink-v2 |
|---|---|---|---|---|---|---|---|---|
inf2.xlarge | 1 | 4 | 16 GiB | 190 | 47.5 | 32 GiB | 820 GiB/s | — |
inf2.8xlarge | 1 | 32 | 128 GiB | 190 | 47.5 | 32 GiB | 820 GiB/s | — |
inf2.24xlarge | 6 | 96 | 384 GiB | 1,140 | 285 | 192 GiB | 4,920 GiB/s | 192 GiB/s |
inf2.48xlarge | 12 | 192 | 768 GiB | 2,280 | 570 | 384 GiB | 9,840 GiB/s | 192 GiB/s |
Each chip carries two NeuronCore-v2 cores, so inf2.48xlarge exposes 24 NeuronCores and 384 GiB of device memory.
Both single-chip sizes have the same accelerator. inf2.8xlarge provides more host CPU and RAM, which can help when compiling models on the instance. AWS Neuron Inf2 architecture
Inf2 versus Trn1#
Both families use NeuronCore-v2, with different instance configurations.
Inf2 uses NeuronLink for multi-chip inference within one instance.
Serving models#
Inf2 serves models that fit within one instance. On a 48xlarge, tensor parallelism can use up to 384 GiB of total device memory across 12 chips. The model must support splitting its tensors across the participating cores, and weights, KV cache and other working data must fit on each chip.
The PyTorch/XLA serving path for Inf2 is in maintenance mode as of Neuron 2.31, based on PyTorch 2.9. The current vLLM Neuron plugin targets Trn2 and Trn3. AWS inference maintenance announcement, vLLM Neuron documentation
What is Inferentia?
Inferentia is AWS's first machine learning chip, announced in 2018 and shipped in 2019. The chip powers the inference-only Inf1 instance family.
Each Inferentia chip holds:
- Four NeuronCore-v1 cores, together delivering 128 INT8 TOPS and 64 FP16/BF16 TFLOPS.
- 8 GiB of DDR device memory at 50 GiB/s. AWS switched to HBM in the second generation.
- NeuronLink-v1, used for NeuronCore Pipeline.
Inferentia introduced the Neuron software stack. The first compiler, neuron-cc, compiled the model ahead of time, and the Neuron runtime loaded and ran it on the chip. Later chips use neuronx-cc.
AWS's Inf1 examples include convolutional models such as ResNet-50 and encoders such as BERT-base. A dense 7-billion-parameter model needs about 14 GB for BF16 weights alone, more than a single Inferentia chip's 8 GiB.
The later Inferentia2 shares its NeuronCore-v2 design with Trainium. That generation added programmable processors for custom operators, device-side control flow, dynamic shapes and FP8. AWS Inferentia architecture
What is Inferentia2?
Inferentia2 is AWS's second-generation inference chip, powering the Inf2 instance family.
Inferentia2 and Trainium share the NeuronCore-v2 design and have the same published compute and memory specifications. Inferentia2 has two chip-to-chip links, and Trainium has four.
Each Inferentia2 chip holds:
- Two NeuronCore-v2 cores, together delivering 380 INT8 TOPS, 190 FP16/BF16/cFP8/TF32 TFLOPS, and 47.5 FP32 TFLOPS.
- 32 GiB of HBM at 820 GiB/s.
- 1 TB/s of DMA bandwidth, with inline memory compression and decompression.
- NeuronLink-v2 for chip-to-chip collectives.
Compared with the first Inferentia: 4× the device memory, 16× the memory bandwidth, and roughly 3× the FP16 throughput. The faster memory helps during token generation, when the chip repeatedly reads the model weights.
Because it is a v2 core, it inherits the whole v2 feature set: dynamic shapes, control flow, programmable rounding, cFP8, and custom operators on the GpSimd Engine.
Inf2 and Trn1 instances#
| Inf2 | Trn1 | |
|---|---|---|
| Max chips | 12 | 16 |
| NeuronLink-v2 per chip | 2 | 4 |
| EFA networking | no | yes |
| Smallest size | 1 chip | 1 chip |
Inf2 uses NeuronLink for collectives within one instance. The larger Trn1 sizes also use EFA to carry collectives between instances. Trainium2 and Trainium3 support both training and inference. AWS Inferentia2 architecture, AWS Trainium/Inferentia2 NKI architecture guide
What is a Neuron device?ND
A Neuron device is one AWS-designed machine learning chip. In AWS's own documentation the word covers both product lines: Inferentia chips, which only run inference, and Trainium chips, which run both training and inference.
An EC2 instance can contain one or more Neuron devices. Each device has its own device memory and multiple NeuronCores, which perform the computation. Use neuron-ls to see the devices and cores available on an instance.
AWS groups the chips by NeuronCore generation.
| Generation | Chip | NeuronCore | Cores per chip | Instance |
|---|---|---|---|---|
| First | Inferentia | v1 | 4 | Inf1 |
| Second | Trainium and Inferentia2 | v2 | 2 | Trn1, Inf2 |
| Third | Trainium2 | v3 | 8 | Trn2 |
| Fourth | Trainium3 | v4 | 8 | Trn3 UltraServer |
Trainium and Inferentia2 share the second-generation core design. Both chips have 32 GiB of high-bandwidth memory (HBM) and a peak BF16 rate of 190 TFLOPS. Trainium2 is the second chip in the Trainium line and the third Neuron hardware generation.
Core counts describe how the work is divided within a chip. For example, first-generation Inferentia has twice as many cores as Trainium, while Trainium has about three times the peak BF16 performance per chip. Compare per-chip performance in the format your model uses, along with memory capacity and bandwidth.
In the SDK and in AWS's abbreviations you will see ND for Neuron device and NC for NeuronCore.
What is a NeuronCore?NC
A NeuronCore is the independent compute unit inside a Neuron device. It is the closest thing Neuron has to an NVIDIA Streaming Multiprocessor in the sense that both are compute units within a larger chip.
A NeuronCore combines several engines that specialize in different operations and share on-chip memory.
- The Tensor Engine multiplies matrices on a systolic array.
- The Vector Engine handles operations such as sums and normalization that combine multiple values.
- The Scalar Engine handles element-wise operations such as applying an activation to each input value.
- The GpSimd Engine contains programmable C/C++ processors for operations that do not map well to the specialized engines. It first appeared in v2.
- The Sync Engine can schedule DMA transfers independently of the compute engines on v2 and later.
The main working memory on the core is SBUF. The Tensor Engine reads its inputs from SBUF and writes its results to PSUM, a smaller buffer where it can add successive partial results.
How engines work together#
Each engine has its own sequencer, the hardware that fetches, decodes and issues instructions. That lets the engines run different operations at the same time. In an NKI kernel, you choose which engines act on each tile, or block of data.
When one engine needs another engine's result, hardware semaphores enforce the ordering. The Neuron compiler works out those dependencies and inserts the semaphore operations, including for hand-written NKI kernels.
For example, the Tensor Engine can multiply one pair of tiles while the Vector Engine moves a finished result out of PSUM and the DMA engines load the next tile. See engine parallelism.
Generations#
| v1 | v2 | v3 | v4 | |
|---|---|---|---|---|
| In chip | Inferentia | Trainium, Inferentia2 | Trainium2 | Trainium3 |
| Cores per chip | 4 | 2 | 8 | 8 |
| Compute engines | 3 | 4 | 4 | 4 |
| SBUF | — | 24 MiB | 28 MiB | 32 MiB |
| Tensor Engine BF16 | 16 TFLOPS | 92 TFLOPS | 79 TFLOPS | 79 TFLOPS |
Trainium2 has eight v3 cores per chip. Although each core's published BF16 peak is lower than v2's, the published chip peak rose from 190 TFLOPS on Trainium to 667 TFLOPS on Trainium2. AWS reports core and chip peaks separately. Use the figure that matches the scope of your work.
On Trainium2 and Trainium3, a Logical NeuronCore configuration can combine the resources of several physical cores into one unit visible to software.
In AWS's abbreviations, NC means NeuronCore.
What is NeuronCore-v1?
NeuronCore-v1 is the first-generation NeuronCore, the core inside the original Inferentia chip. Each chip has four v1 cores, so the largest Inf1 instance has 64 cores across 16 chips.
It has three compute engines.
- Tensor Engine — 16 TFLOPS of FP16/BF16, on a systolic array. Mixed precision, with FP16/BF16/INT8 inputs and FP32/INT32 outputs.
- Vector Engine — 256 floating-point operations per cycle.
- Scalar Engine — 512 floating-point operations per cycle.
The programmable GpSimd Engine and its custom operator support arrived in v2, along with device-side control flow, dynamic shapes and programmable rounding.
Supported data types are FP16, BF16, FP32, INT8, INT16, and INT32. There is no FP8 and no TF32.
The four cores share 8 GiB of DDR device memory with 50 GiB/s of bandwidth. The later Trainium and Inferentia2 chips use HBM.
Software#
Inf1 uses the legacy torch-neuron integration and neuron-cc compiler. NKI support starts with v2. For the frameworks and migration path, see Inf1. AWS NeuronCore-v1 architecture
What is NeuronCore-v2?
NeuronCore-v2 is the second-generation NeuronCore. It powers both Trainium and Inferentia2, with two cores per chip in both cases.
Compute engines#
| Engine | Throughput | Purpose |
|---|---|---|
| Tensor | 92 TFLOPS BF16/FP16, 23 TFLOPS FP32 | Matrix multiplication, convolution, transpose |
| Vector | 2.3 TFLOPS FP32 | Layer norm, pooling, reductions |
| Scalar | 2.9 TFLOPS FP32 | GELU, sigmoid, exp, reciprocal |
| GpSimd | 8 × 512-bit processors | Arbitrary C/C++ |
Relative to v1, the Tensor Engine has about 6× the throughput, the Scalar Engine 3×, and the Vector Engine 10× in AWS's comparison.
The data-path width is how many elements an engine can accept or return per clock cycle. These figures matter when tuning an NKI kernel.
| Engine | Data path (elements/cycle) | Clock |
|---|---|---|
| Tensor | 2×128 in, 1×128 out | 2.8 GHz |
| Vector | 128 in/out | 1.12 GHz |
| Scalar | 128 in/out | 1.4 GHz |
| GpSimd | — | 1.4 GHz |
Memory#
Each core has two software-managed memories, both organized into 128 partitions.
The two cores on the chip share 32 GiB of HBM at 820 GiB/s in the chip architecture specifications.
The systolic array is 128×128, which is where the 128-partition figure comes from and why tile shapes are capped at 128 in the partition dimension.
What v2 introduced#
- The GpSimd Engine, and with it custom operators.
- Control flow and dynamic shapes, via ISA extensions. A model with a data-dependent branch no longer has to round-trip to the host.
- Programmable rounding. You can select round-to-nearest-even or stochastic rounding. Stochastic rounding can help preserve small updates in BF16 training.
- cFP8 and TF32 data types.
On Trn1 and Inf2, software sees each physical core individually. Logical NeuronCore configuration starts with v3.
Two engine-parallelism restrictions also apply on v2 and were lifted in v3: the Vector and GpSimd engines cannot access SBUF at the same time, and the Vector and Scalar engines cannot access PSUM at the same time. AWS Trainium/Inferentia2 NKI architecture guide, NeuronCore-v2 architecture
What is NeuronCore-v3?
NeuronCore-v3 is the third-generation NeuronCore and the core inside Trainium2. Each chip has eight physical cores, up from two on chips with v2.
Engines#
| Engine | Throughput |
|---|---|
| Tensor | 158 TFLOPS FP8, 79 TFLOPS BF16/FP16/TF32, 20 TFLOPS FP32, up to 316 TFLOPS with structured sparsity |
| Vector | 1.0 TFLOPS FP32 |
| Scalar | 1.2 TFLOPS FP32 |
| GpSimd | 8 × 512-bit processors |
The data-path width tells you how many elements an engine can accept or return per clock cycle.
| Engine | Data path (elements/cycle) | Clock |
|---|---|---|
| Tensor | 4×128 dense FP8, 2×128 dense BF16/FP16, 5×128 sparse; 1×128 out | 2.4 GHz |
| Vector | 512 BF16/FP16, 256 other types | 0.96 GHz |
| Scalar | 128 in/out | 1.2 GHz |
| GpSimd | — | 1.2 GHz |
On-chip memory is 28 MiB of SBUF (128 partitions × 224 KiB), up from 24 MiB on v2. PSUM stays at 2 MiB.
What v3 introduced#
Double-rate FP8 matmul. Each element of the 128×128 array can perform two FP8_E4 or FP8_E5 multiply-accumulates per cycle. A packed FP8 instruction can therefore cover 256 values along the contraction dimension, the axis the matmul sums over. The sum stays in FP32. FP8_E3 runs at the BF16 rate.
Structured sparsity. Up to 316 TFLOPS for FP8, BF16, FP16 or TF32 when one input matrix has a supported pattern of zeros. The patterns are 4:16, 4:12, 4:8, 2:8, 2:4, 1:4, and 1:2, where M of each N values can be nonzero.
Bit-accurate transpose. The v2 Tensor Engine transposed by multiplying by an identity matrix, which could propagate NaN or Inf to other positions. The v3 transpose mode preserves the input bits, runs twice as fast for FP32, and can write FP16 or BF16 to PSUM so the result is cheaper to copy to SBUF.
The Descriptor Generation Engine. Dedicated hardware, two instances per core, that generates DMA descriptors on demand. Previously the host generated them when loading the NEFF and stored them in HBM, or the GpSimd Engine generated them while the program ran and stored them in SBUF.
DMA transpose. The DMA engines can transpose while moving, HBM→SBUF or SBUF→SBUF, without involving a compute engine at all.
More engine parallelism. Two v2 restrictions are gone: Vector and GpSimd can now access SBUF in parallel, and Vector and Scalar can access PSUM in parallel at full bandwidth, as long as they do not collide on the same PSUM bank.
Per-processor DMA in GpSimd. Each of the eight GpSimd processors gets an integrated DMA engine, 307 GB/s in total across all eight, able to reach any SBUF or HBM in the instance.
Adjustable exponent bias for the cFP8 data type.
v3 is also the first core where Logical NeuronCore configuration exists, letting two physical v3 cores be addressed as one. AWS Trainium2 NKI architecture guide
What is NeuronCore-v4?
NeuronCore-v4 is the compute core in Trainium3, with eight physical cores per chip. Each has 32 MiB of software-managed SBUF and 2 MiB of PSUM.
| Engine | Peak throughput or configuration |
|---|---|
| Tensor | 315 MXFP8/MXFP4 TFLOPS, 79 BF16/FP16/TF32 TFLOPS, 20 FP32 TFLOPS |
| Vector | 1.2 TFLOPS FP32 |
| Scalar | 1.2 TFLOPS FP32 |
| GpSimd | Eight 512-bit programmable processors |
Changes from v3#
- MXFP8 and MXFP4. The Tensor Engine handles both microscaling inputs at up to four times its BF16 throughput. FP8 without microscaling remains supported by
nc_matmul, including OCPfloat8_e4m3fnon v4. - Wider matmul outputs. An output tile from
nc_matmulcan span eight PSUM banks, with up to 4,096 elements per partition for FP32 or 8,192 for BF16. The Tensor Engine still adds the products in FP32 and casts the result before writing a BF16 output. - DMA accumulation into SBUF. A DMA transfer can add to existing SBUF data in a single read-add-write operation. The Trainium3 architecture guide documents this hardware feature as having no
nki.isaAPI in Neuron 2.33.1. - Vector Engine quantization and exponential. The Vector Engine can quantize BF16/FP16 tensors to MXFP8 and evaluate exponential at four times the Scalar Engine's exponential rate.
The NKI guide identifies FP8, FP16, BF16, TF32, FP32, INT8, INT16 and INT32 as supported input/output data types for the v4 Vector and Scalar engines. Check the specific instruction for its supported data types. Trainium3 NKI architecture guide, NKI nc_matmul reference, NeuronCore-v4 architecture
What is NeuronLink?
NeuronLink is AWS's high-speed connection between Neuron chips. It carries collective communication and, starting with NeuronLink-v2, makes other chips' device memory directly addressable on systems that support memory pooling. The chips connected this way form a scale-up domain.
| Version | Chip | Published bandwidth per chip |
|---|---|---|
| v1 | Inferentia | 32 GiB/s |
| v2 | Trainium, Inferentia2 | 384 GB/s for Trainium in the chip comparison, 192 GiB/s for multi-chip Inf2 in the instance guide |
| v3 | Trainium2 | 1,280 GB/s in the chip specification |
| v4 | Trainium3 | 2,560 GB/s total across links, both directions |
Memory pooling and chip connections#
| Platform | Scale-up domain | Topology | Directly addressable HBM |
|---|---|---|---|
| Trn1 | 16 chips | 2D torus | 512 GiB |
| Trn2 | 16 chips | 4×4 2D torus | 1,536 GiB |
| Trn2 UltraServer | 64 chips | Four tori with matching chip positions linked in rings | 6,144 GiB |
| Trn3 UltraServer, Gen1 | 64 chips | NeuronSwitch-v1 and direct links | 9,216 GiB |
| Trn3 UltraServer, Gen2 | 144 chips | NeuronSwitch-v1 and direct links | 20,736 GiB |
The connection layout affects where it makes sense to split a model. For a Trn2 UltraServer, the instance architecture guide labels the rates in GiB/s and lists four times as much NeuronLink-v3 bandwidth per chip within an instance as between its instances. On Trn3, NeuronSwitch-v1 routes DMA traffic within the UltraServer. Within-server, within-rack and cross-rack paths have different bandwidths. Trainium2 chip comparison, Inf2 architecture, Trn2 architecture, Trn3 architecture
EFA carries traffic beyond the NeuronLink domain, including between UltraServers and between standalone instances. See tensor parallelism for the implications of placing a group across those boundaries.
What is NeuronSwitch?
NeuronSwitch-v1 is the switch used in Trn3 UltraServers. NeuronLink-v4 carries chip-to-chip traffic over switched and direct links. Each chip has a range of addresses in the UltraServer's shared address space. A DMA engine can request a transfer to another chip by using an address in that chip's range. Switches along the path forward the request to its destination.
| Trn3 configuration | Connections inside each server | Switches linking servers in each rack |
|---|---|---|
| Gen1, 64 chips | Chips connect in direct pairs | One 32-port switch |
| Gen2, 144 chips | One four-port switch | Two 36-port switches |
Direct NeuronLink-v4 links connect corresponding chips across the two racks within each UltraServer. Any two chips can reach each other, and the bandwidth depends on the path between them. Source: AWS Neuron Trn3 connectivity
NeuronSwitch serves the scale-up domain within one UltraServer. Traffic between UltraServers uses EFA.
What is PSUM?PSUM
PSUM, the Partial Sum Buffer, is a small on-chip memory in a NeuronCore, dedicated to holding Tensor Engine matrix multiplication results and partial sums.
It is 2 MiB on NeuronCore-v2, v3 and NeuronCore-v4. It has 128 partitions of 16 KiB each. Each partition has eight 2 KiB banks. Trainium3 NKI architecture guide
How it accumulates partial results#
In a standard, unpacked matrix multiplication, the Tensor Engine can handle up to 128 values along the contraction dimension K, the axis it sums over. For K = 4096, computing one output tile takes 32 nc_matmul calls whose results add up to the final tile.
The Tensor Engine can add each partial result to the running total in PSUM. That is near-memory accumulation. It saves a separate reduction pass and avoids copying the partial results through SBUF.
PSUM banks and matmul tile width#
On NeuronCore-v3, one nc_matmul output fits in one bank per partition, which holds 512 FP32 elements. On NeuronCore-v4, one output can span all eight banks for up to 4,096 FP32 or 8,192 BF16 elements per partition. A wide output can leave fewer banks available for other tiles. NKI nc_matmul reference
Getting data back out#
The Tensor Engine writes all matmul results to PSUM. The Vector or Scalar Engine typically copies a finished result to SBUF so the next matmul can reuse the space.
On NeuronCore-v3, the Vector and Scalar engines can access PSUM in parallel at full bandwidth, as long as they do not target the same bank — a restriction on v2, where those accesses had to serialize.
Orientation#
Input streams into the systolic array along one axis and results come out along the other. In stationary.T @ moving, the free dimension of stationary becomes the partition dimension of the PSUM output.
Floating-point matmul accumulates in FP32 inside the Tensor Engine. On v4 it can write a BF16 destination in PSUM. When adding to a BF16 partial sum, it upcasts the stored value, adds in FP32 and rounds back to BF16 on each write. The v3 transpose mode also supports FP16/BF16 destinations. Trainium3 NKI architecture guide
What is the Scalar Engine?
The Scalar Engine (ScalarE) handles operations where each output element depends on one input element. Examples include GELU, ReLU, sigmoid, exponential, reciprocal, and square root.
In y[i] = gelu(x[i]), each output uses one input value. The Scalar Engine evaluates many of these independent operations in parallel. In layer normalization, an output needs a mean and variance computed across many inputs. The Vector Engine handles reductions such as those sums.
Throughput by generation:
The Trainium3 NKI guide lists FP8, FP16, BF16, TF32, FP32, INT8, INT16 and INT32 for v4 Scalar Engine inputs and outputs. Individual instructions have their own data type requirements. Trainium3 NKI architecture guide
Like the Vector Engine, it can read and write both SBUF and PSUM, so it can also be used to drain PSUM after a matmul. On NeuronCore-v3 the Vector and Scalar engines can access PSUM in parallel at full bandwidth, provided they target different PSUM banks. On v2, those accesses serialize.
v3 also added bit-accurate tensor copies without an intermediate cast through FP32.
Exponential in attention#
In a fused attention kernel, the next matrix multiplication can wait on the softmax exponential. On Trainium2, the Scalar Engine can be the bottleneck for that step. NeuronCore-v4 adds a Vector Engine exponential instruction with 4× the Scalar Engine's exponential throughput.
What is SBUF?SBUF
SBUF, the State Buffer, is the main on-chip working memory in a NeuronCore. The compiler or kernel loads data into SBUF from device memory so the compute engines can use it. Like GPU shared memory, the program controls what goes into it and when.
Partitions and capacity#
SBUF has 128 partitions, each a region of memory. The partitions line up with the 128 rows of the systolic array in the Tensor Engine.
| Core | Total SBUF | Per partition |
|---|---|---|
| NeuronCore-v2 | 24 MiB | 192 KiB |
| NeuronCore-v3 | 28 MiB | 224 KiB |
| NeuronCore-v4 | 32 MiB | — |
Per chip that is 48 MiB on Trainium, 224 MiB on Trainium2, and 256 MiB on Trainium3.
Access rules#
- The Vector, Scalar and GpSimd engines can read and write SBUF.
- The Tensor Engine reads its inputs only from SBUF, and writes its outputs only to PSUM.
- Data moves between SBUF and HBM by DMA only.
- Data moves between SBUF and PSUM by compute-engine instructions, not DMA.
Reusing data in SBUF reduces the bytes read from HBM and raises arithmetic intensity.
Who moves data#
An NKI kernel or the Neuron compiler schedules transfers into and out of SBUF. Keeping data there for reuse depends on the schedule and available capacity. See software-managed memory.
If the live data in a kernel exceeds SBUF capacity, the compiler inserts spills and refills to HBM. This is called spilling and adds HBM traffic. Tiling helps keep the working set small enough to fit.
Layouts#
On Trainium, SBUF was row-major only. Trainium2 added Col-major-2B and Col-major-4B layouts, which removes some transposes that previously had to be done explicitly.
NeuronCore-v4 adds near-memory accumulation: DMA engines can do a read-add-write into existing SBUF contents in a single transfer. AWS documents the hardware feature without an nki.isa API in Neuron 2.33.1. Trainium3 NKI architecture guide
What is the Sync Engine?
The Sync Engine (SyncE, sometimes SP) is a control unit in NeuronCore-v2 and later. It can start DMA transfers and synchronize operations independently of the compute engines.
A compute engine's sequencer directs its own stream of instructions. It can issue two kinds of instruction.
- Control instructions run on the sequencer itself. They can branch, compute an address in private 32-bit registers, or start a DMA transfer.
- Data path instructions perform tensor operations using SBUF and PSUM.
The Sync Engine is a separate sequencer that runs control instructions. It can start loading the next tile while the Tensor Engine works on the current one. See latency hiding.
Synchronization#
The compute engines run asynchronously and in parallel, so data dependencies between them need enforcement. That is done with atomic hardware semaphores.
The Neuron compiler analyzes the data dependencies in your graph or NKI kernel and inserts the semaphore operations so a consumer waits until its input is ready.
On NeuronCore-v3, the Sync Engine is one of the two sequencers that can drive the Descriptor Generation Engine; the Scalar Engine is the other. The compiler can choose a sequencer, and nisa.dma_copy also allows the caller to select it.
The Sync Engine appears in AWS's glossary as "the SP engine".
What is a systolic array?
A systolic array is a grid of simple processing elements, each doing a multiply-accumulate, which multiplies two numbers and adds the product to a running sum. The elements pass data to their neighbors, reusing it as it moves through the grid. The Tensor Engine uses a 128 × 128 array in the NeuronCore generations covered by NKI.
How the array reuses data#
In a systolic array, each input element is read from SBUF once, then reused across an entire row or column of processing elements. With a full row or column, one read can feed up to 128 multiply-accumulates.
Why 128 is everywhere#
The shape of the array determines how standard matmul instructions lay out their inputs.
- SBUF and PSUM have 128 partitions, one per row of processing elements.
- An on-chip tile can use up to 128 partitions.
- The contraction dimension of a matmul must map to the partition dimension, because that is the axis the array accumulates along.
- The
stationarymatrix's free axis is capped at 128, the number of columns.
See tiling for how NKI breaks larger matrices into blocks that fit these limits.
The tradeoffs#
Tile shape and data layout affect how much of the array is useful.
- Small matrices use less of the array. A narrow tile can leave rows or columns idle. The cost also depends on which input is stationary and whether hardware tiling mode is enabled.
- Sparsity does not help unless it is structured in a pattern the hardware recognizes — hence the 4:16 through 1:2 patterns on v3 and later.
- There is a pipeline fill and drain cost. Data has to propagate across the grid before the first result emerges. For a long stream of matmuls, the rate depends on how often the engine can accept a new instruction.
The 128×128 shape is also why FP8 doubling works the way it does on NeuronCore-v3: the grid stays 128×128 physically, but each processing element performs two FP8 multiply-accumulates per cycle, which the programmer sees as a 256×128 array.
What is the Tensor Engine?
The Tensor Engine (TensorE) is the matrix multiplication unit in a NeuronCore. Its peak rate depends on the input format. On NeuronCore-v3, for example, it can reach 79 TFLOPS for BF16 matrix multiplication if data arrives fast enough to keep the array busy.
It uses a systolic array, a grid of 128 × 128 processing elements on NeuronCore-v2 through v4. It handles general matrix multiplication (GEMM), convolution, and transpose. It plays a role similar to NVIDIA's Tensor Cores.
Where inputs and outputs go#
The Tensor Engine reads only from SBUF and writes only to PSUM. A typical matmul kernel loads a tile from HBM into SBUF, computes into PSUM, then uses the Vector or Scalar engine to copy the finished result back to SBUF and make room for the next output.
Floating-point matmul accumulates in FP32 inside the Tensor Engine. The ordinary matmul destination is FP32 on NeuronCore-v3. NeuronCore-v4 also supports a BF16 destination, rounding on each write to PSUM. The v3 transpose mode supports 16-bit destinations. Trainium3 NKI architecture guide
Stationary and moving#
One NKI matmul call typically appears as two hardware instructions.
LoadStationaryloads one matrix from SBUF and caches it inside the array.MultiplyMovingstreams the second matrix across it, producing output into PSUM.
So nki.isa.nc_matmul(dst, stationary, moving) computes stationary.T @ moving. The free axis of stationary becomes the output's partition axis, while the free axis of moving becomes the output's free axis. Choosing the order that the next operation expects can save a transpose. See stationary and moving.
Tile size limits#
For a standard nc_matmul tile with hardware tiling mode off, the limits are:
| Constraint | Limit | Why |
|---|---|---|
stationary free axis | 128 | columns of processing elements |
| Partition axis, both inputs | 128 | rows of PEs, and SBUF partitions |
moving free axis, v2 and v3 | 512 | one FP32 PSUM bank per partition |
moving free axis, v4 | 4,096 (FP32 output) or 8,192 (BF16 output) | up to eight PSUM banks per partition |
Anything larger must be tiled into multiple nc_matmul calls. Splitting either output axis gives independent output tiles. Splitting the contraction dimension K, the axis that gets summed over, yields partial results that accumulate in the same PSUM location.
Large tiles generally make better use of the array. Choosing the widest moving tile trades PSUM capacity for work per call. NKI nc_matmul reference
Using it for data movement#
Because the array multiplies by whatever you load, you can construct matrices of zeros and ones to rearrange or combine data.
- Transpose. On v2, multiplying by an identity matrix transposes the input but can propagate
NaNorInfto other positions. Starting with v3, Tensor Engine transpose preserves the input bits. - Broadcast. Multiplying by a vector of ones repeats values across partitions.
- Cross-partition sum. A single column of the array can sum values along the partition axis.
These operations occupy the Tensor Engine. A DMA transpose can move data and transpose it at the same time, leaving the Tensor Engine available for matrix multiplication. NKI nc_transpose reference
Per-generation throughput#
| v1 | v2 | v3 | v4 | |
|---|---|---|---|---|
| BF16/FP16 | 16 TFLOPS | 92 | 79 | 79 |
| FP8-class support | — | cFP8 | 158 TFLOPS FP8 | 315 TFLOPS MXFP8/MXFP4 |
| FP32 | — | 23 | 20 | 20 |
| Structured sparsity | — | — | up to 316 TFLOPS (FP8/FP16/BF16/TF32) | up to 315 TFLOPS (FP16/BF16/TF32) |
Trainium2 NKI architecture guide, NeuronCore-v4 architecture
Several instruction pairs can be in flight at once. For a stream of matmuls, throughput depends on the initiation interval, the time between issuing successive instructions.
What is Trainium?
Trainium, also called Trainium1, is AWS's first purpose-built chip for model training. It is the second Neuron hardware generation and powers the Trn1 and Trn1n instances.
Each Trainium chip has the following hardware.
- Two NeuronCore-v2 cores, together delivering 380 INT8 TOPS, 190 FP16/BF16/cFP8/TF32 TFLOPS, and 47.5 FP32 TFLOPS.
- 32 GiB of HBM at 820 GiB/s.
- 1 TB/s of DMA bandwidth, with inline memory compression and decompression.
- NeuronLink-v2, four links per chip, for collectives and memory pooling across chips.
Trainium and Inferentia2 both use NeuronCore-v2. A full Trn1 instance has 16 chips, four NeuronLink-v2 links per chip, and EFA for scaling across instances.
What made it a training chip#
Three additions in NeuronCore-v2 help with training.
- Stochastic rounding. Round-to-nearest can repeatedly lose small updates to BF16 weights. Stochastic rounding chooses between nearby representable values so the update is preserved on average. This can enable BF16 training without keeping a separate FP32 copy of the weights.
- Control flow and dynamic shapes, so a training loop's data-dependent branches stay on device.
- The GpSimd Engine, so a novel loss or optimizer can be written as a custom operator rather than falling back to the host.
On a 16-chip Trn1 instance, NeuronLink-v2 lets any chip directly address another chip's HBM. EFA lets Trn1 instances communicate across an UltraCluster, which AWS describes as designed to scale to over 100,000 chips.
Software and newer chips#
Trainium2 has three times the HBM capacity and about 3.5× the BF16 throughput per chip. Current TorchNeuron and vLLM Neuron target Trainium2 and Trainium3. See Trn1 for the older serving path. AWS Trainium architecture, AWS Trn1 architecture
What is Trainium2?
Trainium2 is AWS's third-generation ML chip. It powers Trn2 instances and the Trn2 UltraServer.
Each Trainium2 chip has the following hardware.
- Eight NeuronCore-v3 cores, together delivering 1,299 FP8 TFLOPS, 667 BF16/FP16/TF32 TFLOPS, up to 2,563 sparse TFLOPS (FP8/FP16/BF16/TF32), and 181 FP32 TFLOPS.
- 96 GiB of HBM at 2.9 TB/s, across four stacks.
- 3.5 TB/s of DMA bandwidth from 128 DMA engines, with inline compression and decompression.
- NeuronLink-v3, four links giving 1.28 TB/s per chip, and memory pooling across up to 64 chips.
- CC-Cores dedicated to collective communication.
Comparison with Trainium#
| Trainium | Trainium2 | Factor | |
|---|---|---|---|
| FP8 TFLOPS | 190 | 1,299 | about 6.8× |
| BF16/FP16/TF32 TFLOPS | 190 | 667 | about 3.5× |
| FP32 TFLOPS | 47.5 | 181 | about 3.8× |
| Sparse TFLOPS | — | 2,563 | new |
| HBM capacity | 32 GiB | 96 GiB | 3× |
| HBM bandwidth | 820 GiB/s | 2.9 TB/s | |
| SBUF | 48 MiB | 224 MiB | 4.7× |
| Interconnect per chip | 384 GB/s | 1,280 GB/s | 3.3× |
| Memory pool | 16 chips | 64 chips | 4× |
Trainium2 has four times as many cores as Trainium, and its NeuronCore-v3 Tensor Engine can multiply matrices in select FP8 formats at twice the BF16 rate. The extra SBUF can keep more tiles on the chip for reuse. Across a Trn2 UltraServer, each chip can address HBM on all 64 chips, for a combined 6,144 GiB.
Trainium2 also changed DMA ordering guarantees from write-after-write barriers to strong-order-write, and added column-major SBUF layouts (Col-major-2B and Col-major-4B) alongside row-major.
New capabilities#
Trainium2 is the first chip with Logical NeuronCore configuration, which controls how many physical cores software treats as one logical core. The Trn2 default, LNC=2, groups the eight physical cores into four logical ones per chip.
It also brings structured sparsity, hardware DMA descriptor generation, DMA transpose, and a bit-accurate Tensor Engine transpose mode.
AWS's chip architecture lists 16 CC-Cores, and the NKI architecture guide lists 20. The NKI guide gives 3 TB/s for HBM bandwidth. The table uses the chip architecture's 2.9 TB/s. Trainium2 architecture, Trainium2 NKI architecture guide
What is Trainium3?
Trainium3 is AWS's fourth-generation ML chip. Each chip has eight NeuronCore-v4 cores and 144 GiB of HBM. AWS uses the same chip in the Gen1 and Gen2 configurations of the Trn3 UltraServer.
Per-chip specifications#
| Metric | Trainium2 | Trainium3 |
|---|---|---|
| Peak 8-bit matmul | 1,299 TFLOPS (FP8) | 2,517 TFLOPS (MXFP8) |
| Peak MXFP4 matmul | — | 2,517 TFLOPS |
| Peak BF16/FP16/TF32 | 667 TFLOPS | 671 TFLOPS |
| Peak FP32 | 181 TFLOPS | 183 TFLOPS |
| HBM capacity | 96 GiB | 144 GiB |
| HBM bandwidth | 2.9 TB/s | 4.9 TB/s in the chip and UltraServer specifications |
| SBUF | 224 MiB | 256 MiB |
| NeuronLink bandwidth | 1,280 GB/s | 2,560 GB/s |
| DMA bandwidth | 3.5 TB/s | 4.9 TB/s |
AWS's chip architecture lists 4.9 TB/s of HBM bandwidth and 16 CC-Cores. The NKI architecture guide lists 4.7 TB/s and 20 CC-Cores for the same chip. The aggregate bandwidths in the Trn3 UltraServer table are based on 4.9 TB/s per chip. Trainium3 architecture, Trainium3 NKI architecture guide, Trn3 specifications
For large-model inference, more HBM can hold more weights and KV cache, and higher bandwidth can read them faster. The peak MXFP8 and MXFP4 rates apply when the model and kernels use those formats.
NeuronCore-v4 adds DMA accumulation into SBUF, direct BF16 matmul output in PSUM, and dedicated MXFP8 quantization and fast exponential instructions on the Vector Engine.
For models, see TorchNeuron for native PyTorch, TorchTitan Neuron for distributed training, and vLLM Neuron for serving.
What is a Trn1 instance?
Trn1 is the EC2 family powered by first-generation Trainium chips. It supports model training and inference.
| Size | Chips | NeuronCores | NeuronLink-v2 | EFAv2 |
|---|---|---|---|---|
trn1.2xlarge | 1 | 2 | — | — |
trn1.32xlarge | 16 | 32 | 2D torus | 800 Gbps |
trn1n.32xlarge | 16 | 32 | 2D torus | 1,600 Gbps |
The 2xlarge has one chip for workloads that fit within 32 GiB of device memory. Each 32xlarge has 512 GiB across 16 chips. The chips can address each other's HBM through NeuronLink-v2. EFA carries traffic between instances. The trn1n variant doubles EFA bandwidth for jobs with high inter-node communication. Trn1 architecture, EC2 Trn1 specifications
Software and serving#
Trn1 uses NeuronCore-v2. Each physical core is individually addressable. Logical NeuronCore configuration starts with Trainium2.
For inference, Trn1 supports the PyTorch/XLA-based PyTorch NeuronX inference path. AWS has kept it on PyTorch 2.9 in maintenance mode for critical fixes since Neuron 2.31. Native TorchNeuron or the current vLLM Neuron plugin target Trn2 and Trn3. AWS inference maintenance announcement, Neuron 2.33.1 documentation
What is a Trn2 instance?
Trn2 is the EC2 instance family powered by Trainium2. It supports training, inference and NKI kernel development.
| Specification | trn2.3xlarge | trn2.48xlarge / trn2u.48xlarge | Trn2 UltraServer |
|---|---|---|---|
| Trainium2 chips | 1 | 16 | 64 |
| vCPUs | 12 | 192 | 768 |
| Host memory | 128 GiB | 2,048 GiB | 8,192 GiB |
| Device memory | 96 GiB | 1,536 GiB | 6,144 GiB |
| Device memory bandwidth | 2.9 TB/s | 46.4 TB/s | 185.6 TB/s |
| FP8 PFLOPS | 1.3 | 20.8 | 83.2 |
| FP16/BF16/TF32 PFLOPS | 0.67 | 10.7 | 42.8 |
| Sparse PFLOPS | 2.6 | 41 | 164 |
| FP32 PFLOPS | 0.18 | 2.9 | 11.6 |
| Intra-instance NeuronLink-v3 per chip | — | 1,024 GiB/s | 1,024 GiB/s |
| NeuronLink-v3 between members of one UltraServer, per chip | — | — | 256 GiB/s |
The single-chip size has 96 GiB for development, inference or fine-tuning that fits on one chip. The 16-chip sizes link chips in a 4×4 grid with wrap-around connections. This is a torus. Each chip can address all 1,536 GiB of HBM through NeuronLink-v3. A trn2.48xlarge runs on its own. Four trn2u.48xlarge instances join over NeuronLink-v3 to make a 64-chip UltraServer. Source: AWS Neuron Trn2 architecture
Physical and logical cores#
A 48xlarge has 128 physical cores (16 chips × 8 NeuronCore-v3 cores). The default Logical NeuronCore configuration for model workloads is LNC=2, so software sees 64 logical cores, four per chip. Use the logical count and the model's sharding constraints when choosing a tensor-parallel degree.
Differences between AWS specifications#
The EC2 instance-type table lists 512 GiB per Trainium2 chip. The Neuron architecture gives 96 GiB per chip and 1,536 GiB per 16-chip instance, which the table above uses. The EC2 Trn2 product page likewise shows 96 GB for the one-chip size and 1.5 TB for the 16-chip sizes, using different units.
For trn2.3xlarge, the Neuron architecture says EFA is unavailable. The EC2 network specification and EFA support list both show EFA support, and the EC2 network table gives 200 Gbps of network bandwidth. EC2 lists 3,200 Gbps of EFAv3 per 48xlarge instance. The Neuron architecture table labels that value in GB/s, while the EC2 product page gives 3.2 Tbps. AWS Neuron Trn2 architecture, EC2 instance-type specifications, EC2 EFA support, EC2 Trn2 product details
What is a Trn2 UltraServer?
A Trn2 UltraServer is four trn2u.48xlarge instances joined by NeuronLink-v3. Each of its 64 chips can address the HBM on the other chips, giving a combined 6,144 GiB of device memory.
| Specification | One Trn2 48xlarge | Trn2 UltraServer |
|---|---|---|
| Trainium2 chips | 16 | 64 |
| vCPUs | 192 | 768 |
| Host memory | 2,048 GiB | 8,192 GiB |
| Device memory | 1,536 GiB | 6,144 GiB |
| Aggregate device memory bandwidth | 46.4 TB/s | 185.6 TB/s |
| FP8 PFLOPS | 20.8 | 83.2 |
| BF16 PFLOPS | 10.7 | 42.8 |
How the chips connect#
Each instance connects its 16 chips in a 4×4 grid with wrap-around links, called a torus. Chips at the same position in the four grids form a ring across the instances. AWS lists 1,024 GiB/s of NeuronLink bandwidth per chip within an instance and 256 GiB/s per chip between instances of the same UltraServer. That 4× difference can favor keeping communication-heavy tensor parallelism within each instance and placing pipeline stages across them. Source: AWS Neuron Trn2 architecture
NeuronLink carries device-to-device traffic within the 64-chip UltraServer. EFA provides network transport between UltraServers and for workflows that use host networking. Trn3 UltraServers use a switched fabric and have 64-chip and 144-chip configurations.
What is a Trn3 UltraServer?
A Trn3 UltraServer joins Trainium3 chips across servers so they can work together. Gen1 connects 64 chips and Gen2 connects 144 chips, all using the same Trainium3 chip. Both use NeuronLink-v4 and NeuronSwitch-v1 to give each chip access to every other chip's HBM through device DMA.
| Specification | Gen1 | Gen2 |
|---|---|---|
| Servers × chips per server | 4 × 16 | 36 × 4 |
| Chips per UltraServer | 64 | 144 |
| Host vCPUs | 768 | 3,456 |
| Host memory | 8,192 GiB | 27,648 GiB |
| Device memory | 9,216 GiB | 20,736 GiB |
| Aggregate device memory bandwidth | 313.6 TB/s | 705.6 TB/s |
| Peak MXFP8/MXFP4 | 161.1 PFLOPS | 362.4 PFLOPS |
| Peak FP16/BF16/TF32 | 42.9 PFLOPS | 96.6 PFLOPS |
| Peak FP32 | 11.7 PFLOPS | 26.4 PFLOPS |
| NeuronLink-v4 total per chip, both directions | 2,560 GB/s | 2,560 GB/s |
| Aggregate EFA | 12,800 Gbps | 57,600 Gbps |
Source: AWS Neuron Trn3 architecture and specifications
How the chips connect#
- Gen1 has two racks of two servers. Within a server, chips are paired by direct links. One 32-port NeuronSwitch-v1 in each rack connects all chips from both servers. Direct links connect corresponding chips across racks.
- Gen2 has two racks of 18 servers. A four-port NeuronSwitch-v1 connects the chips inside each server. Two 36-port switches per rack connect the servers in that rack. Direct links connect corresponding chips across racks.
The bandwidth depends on which path the data takes. AWS reports the following totals per chip, summed over both directions.
| NeuronLink-v4 path | Gen1 | Gen2 |
|---|---|---|
| Within a server | 1,024 GB/s | 1,024 GB/s |
| To a rack switch | 1,024 GB/s | 1,280 GB/s |
| Direct cross-rack link | 512 GB/s | 256 GB/s |
Source: AWS Neuron Trn3 connectivity
Traffic between UltraServers uses EFA. The switched links help with workloads that exchange a lot of data. In expert parallelism, chips send tokens to the chips running the selected experts through all-to-all collectives. The previous Trn2 UltraServer connects 64 chips using NeuronLink-v3 tori and rings.
What is an EC2 UltraCluster?
An EC2 UltraCluster is a group of accelerated EC2 instances connected by a petabit-scale EFA network. For Trainium, EFA lets jobs run collectives across multiple standalone instances or UltraServers. Inside each multi-chip instance or UltraServer, its connected chips can use NeuronLink.
| Scale | Example | Fabric |
|---|---|---|
| Within an instance | 16 chips in a Trn2 48xlarge | NeuronLink-v3 torus |
| Within a Trn2 UltraServer | Four hosts, 64 chips | NeuronLink-v3 tori and rings |
| Within a Trn3 UltraServer | Gen1 64 chips or Gen2 144 chips | NeuronLink-v4 and NeuronSwitch-v1 |
| Across scale-up domains in an UltraCluster | Multiple instances or UltraServers | EFA |
AWS describes the Trn1 UltraCluster EFA network as non-blocking and documents a design that scales past 100,000 Trainium chips. Non-blocking describes the network's ability to carry simultaneous traffic without an oversubscribed shared link. Each job can use the resources allocated to it. AWS Neuron Trn1 architecture, AWS EC2 Trn3 UltraServers
Where you place a collective changes which fabric carries it. A group that communicates on every layer, such as a tensor-parallel group, often benefits from staying within a NeuronLink domain.
What is the Vector Engine?
The Vector Engine (VectorE) handles operations that combine values, such as summing a row for softmax or adding two tensors element by element.
Reductions in normalization and softmax do little arithmetic per byte moved. They can limit a kernel's throughput even when the Tensor Engine has capacity to spare. See arithmetic intensity.
It can read and write both SBUF and PSUM. After the Tensor Engine writes a matrix multiplication result to PSUM, the Vector Engine can move it to SBUF and make room for the next result.
Throughput by generation:
AWS reports about 10× higher throughput from v1 to v2. The table shows per-core figures. A v3 chip has four times as many cores as a v2 chip.
The Trainium3 NKI guide lists FP8, FP16, BF16, TF32, FP32, INT8, INT16 and INT32 for v4 Vector Engine inputs and outputs. Individual instructions have their own data type requirements. Trainium3 NKI architecture guide
Performance mode#
On NeuronCore-v3 the Vector Engine has a BF16/FP16 performance mode that gives up to 4× the v2 instruction throughput for selected instructions. The engine still does the arithmetic in FP32.
The hardware selects the mode automatically based on the instruction, where its inputs and outputs live, their types and their layout.
- 4× for
tensor_copyandtensor_scalarwhen both input and output are in SBUF, both are BF16 or FP16, and the innermost free dimension is physically contiguous. - 2× for
tensor_copyandtensor_scalarwhen either side is in PSUM with the same type and layout conditions, or when both are in SBUF and BF16/FP16 with a noncontiguous innermost free dimension. - 2× for
tensor_tensorwhen both inputs are in SBUF and everything is BF16/FP16.
This mode uses a memory bus shared by the Vector and GpSimd engines, with the hardware deciding which engine can use it.
On NeuronCore-v4 the Vector Engine gains two more capabilities: quantizing BF16/FP16 down to MXFP8, useful between MLP layers, and a fast exponential at 4× the throughput of exp on the Scalar Engine for operations such as attention softmax. Trainium2 NKI architecture guide
What is cFP8?
cFP8 stands for configurable FP8, a family of 8-bit floating-point formats introduced on NeuronCore-v2. Each format makes a different tradeoff between exponent bits (range) and mantissa bits (precision).
| Format | Sign | Exponent | Mantissa | Character |
|---|---|---|---|---|
FP8_e5m2 | 1 | 5 | 2 | Widest range, least precision |
FP8_e4m3 | 1 | 4 | 3 | Middle ground |
FP8_e3m4 | 1 | 3 | 4 | Narrowest range, most precision |
A common training recipe uses e4m3 for weights and activations and e5m2 for gradients, where the wider range can help.
NeuronCore-v3 adds adjustable exponent biasing, which lets software shift the range toward the magnitudes in a tensor. AWS NeuronCore-v3 architecture
Trainium2 throughput#
On Trainium2, the Tensor Engine can do twice as much dense matmul work per cycle with E4M3 or E5M2 as with BF16. AWS publishes these chip and engine peaks separately.
| Scope | BF16 TFLOPS | FP8 TFLOPS |
|---|---|---|
| Per chip | 667 | 1,299 |
| Per Tensor Engine | 79 | 158 |
An FP8 tensor also takes half as many bytes as a BF16 tensor of the same shape. Keeping weights in FP8 in HBM can therefore help memory-bound decoding. The end-to-end gain depends on how much time the model spends reading those weights and what it costs to convert them. AWS Trainium2 chip specifications
How the doubling works#
NeuronCore-v3 doubles the maximum contraction length of a matmul from 128 to 256 in this mode. Each processing element in the 128×128 systolic array multiplies two pairs of FP8 values per cycle and adds both products in FP32.
The NKI nc_matmul API lists E4M3 and E5M2 as its FP8 inputs on v3. The Trainium2 architecture guide also documents E3M4 hardware support at the BF16 rate, but the API's supported input list omits it. Trainium2 NKI architecture guide, NKI nc_matmul reference
Invoking it from NKI:
# stationary: [128, 2, 128] moving: [128, 2, 512]
nisa.nc_matmul(dst, stationary, moving, perf_mode=nisa.matmul_perf_mode.double_row)
Both operands need a middle axis of exactly 2. Zero-pad an odd contraction length before packing the operands. On v3, this mode is incompatible with column tiling, sparse matmul, or transpose mode. See stationary and moving.
FP8 on Trainium3#
NeuronCore-v4 adds the Open Compute Project format float8_e4m3fn to nc_matmul. Both inputs can use it, or one can pair it with float8_e5m2. Legacy float8_e4m3 and float8_e4m3fn are incompatible in the same call. MXFP8 and MXFP4 use block scales and a different matmul instruction. NKI nc_matmul reference
What are collectives on Neuron?
Collective operations move or combine data across a group of workers, each identified by its rank. Neuron runs them on dedicated CC-Cores, which allows communication to overlap with compute when dependencies and scheduling permit. AWS compute-communication overlap guide
| Operation | What it does |
|---|---|
| All-reduce | Combine corresponding values, for example by summing, and return the result to every rank |
| All-gather | Concatenate all ranks' data and return the result to every rank |
| Reduce-scatter | Reduce values across ranks and give each rank a slice |
| All-to-all | Redistribute one piece from each source rank to each destination rank |
| Collective-permute | Send each rank's data to a specified destination rank |
Tensor parallelism often reduces partial activations across shards. Data parallelism synchronizes gradients. Mixture-of-experts routing can use all-to-all.
Where they run#
NeuronLink carries traffic within a connected set of chips. The 16 chips of a trn2.48xlarge form a 4×4 grid with links that wrap around its edges. A Trn2 UltraServer adds NeuronLink rings connecting matching positions across four hosts. EFA carries traffic between NeuronLink domains. The cost depends on the SKU, rank placement, message size and collective algorithm. Use nccom-test to measure the paths and group sizes your workload uses. AWS Trn2 architecture · AWS inter-node collectives guide · AWS intra-node collectives guide
Issuing collectives#
Frameworks and libraries such as TorchTitan Neuron and vLLM Neuron use collectives to implement sharding. The Neuron Runtime executes them on hardware.
Hand-written NKI kernels can use nki.collectives directly. A ReplicaGroup identifies which ranks act together. This fragment sums one tensor per rank and writes the same sum to every rank. Inside the kernel, world_size is the total number of ranks, supplied as a Python integer at specialization. Allocate matching tensors src and dst in private HBM before calling it.
import nki.collectives as ncc
import nki.language as nl
replica_group = ncc.ReplicaGroup.from_partition_op(
world_size, ncc.rg_partition_op.bitwise_and, 0
)
ncc.all_reduce(srcs=[src], dsts=[dst], replica_group=replica_group, op=nl.add)
The source and destination are lists so one call can reduce several HBM tensors together. The allowed buffers and layouts vary by operation and LNC setting. AWS all-reduce API · AWS ReplicaGroup API
What are Neuron custom C++ operators?
The legacy Custom C++ operators feature runs PyTorch operators written in C++ on a Neuron GpSimd Engine. It applies to the PyTorch/XLA path on Inf2 and Trn1. AWS archived feature overview · AWS archive index
Starting with Neuron 2.33.0, AWS maintains aws-neuronx-gpsimd-customop-lib with critical security and bug fixes only. AWS recommends NKI for new custom kernels. NKI can target specialized engines such as the Tensor Engine. The native TorchNeuron integration can register an NKI kernel as a PyTorch operator with torch_neuronx.nki_op. AWS maintenance announcement · AWS TorchNeuron NKI guide
What data types does Neuron support?
Data types determine how Neuron stores and computes with numbers. The formats in this table depend on the NeuronCore generation. For a particular operation, check what its engine, instruction, and framework accept. AWS data type guide
By generation#
| Type | Sign bits | Exponent bits | Mantissa bits | v1 | v2 | v3 | v4 |
|---|---|---|---|---|---|---|---|
| FP32 | 1 | 8 | 23 | yes | yes | yes | yes |
| TF32 | 1 | 8 | 10 | — | yes | yes | yes |
| BF16 | 1 | 8 | 7 | yes | yes | yes | yes |
| FP16 | 1 | 5 | 10 | yes | yes | yes | yes |
| FP8_e5m2 | 1 | 5 | 2 | — | yes | yes | yes |
| FP8_e4m3 | 1 | 4 | 3 | — | yes | yes | yes |
| FP8_e3m4 | 1 | 3 | 4 | — | yes | yes | yes |
| UINT8 | — | — | — | — | yes | yes | yes |
| INT32 / UINT32 | 1 / 0 | — | — | — | yes | yes | yes |
| INT64 / UINT64 | 1 / 0 | — | — | — | — | yes | yes |
float8_e4m3fn (OCP FP8) | 1 | 4 | 3 | — | — | — | yes |
| MXFP8 / MXFP4 | — | — | — | yes |
The first three FP8 rows are cFP8, or configurable FP8. The v4 Tensor Engine also accepts the OCP format float8_e4m3fn, which has a different encoding from legacy E4M3 despite having the same bit counts. NKI nc_matmul reference
Automatic casting#
Since Neuron SDK 2.27, neuronx-cc keeps the input type of matrix multiplications by default (--auto-cast=none). Older releases cast FP32 matrix multiplications to BF16 by default. To request that behavior, pass --auto-cast=matmult --auto-cast-type=bf16 and check model accuracy. AWS compiler guide
This compiler default is distinct from the dtype chosen by the model and from framework mixed precision, such as torch.autocast(device_type="neuron") in TorchNeuron. The legacy Inf1 compiler has its own precision defaults.
Integer conversions#
Matrix multiplication, scatter that accumulates into its destination, all-reduce and reduce-scatter lack a native integer datapath. When the compiler permits downcasting, these can run in FP32 and lose precision; integer power can narrow int64 to int32.
In Neuron 2.33.1 the compiler still defaults to narrowing int64 for execution. On Trn2 and later, --native-int64=enabled preserves 64-bit integers where supported. Earlier targets narrow them. Use --implicit-integer-downcast=none to reject lossy conversions for operations without the required integer datapath. Check the CLI reference and compiler release notes for the exact rules and the planned default change.
Which to use#
For inference, lower precision can reduce weight and KV traffic when serving is memory-bound. It can also raise peak compute throughput on a supported engine. Check the model recipe and measure the accuracy and throughput of the complete workload.
For training, BF16 is a common starting point. Accumulation precision, optimizer state, and stochastic rounding are separate decisions. Keep higher precision where the workload requires it.
What is DMA transpose?
DMA transpose swaps tensor axes during a transfer to SBUF. The DMA engines can read from HBM or from SBUF without occupying a compute engine. On Trainium2, AWS documents bit-accurate transposes for 2-byte and 4-byte types. Trainium2 NKI architecture guide
import nki.language as nl
import nki.isa as nisa
# hbm_src: [512, 128]
sbuf_dst = nl.ndarray((128, 512), dtype=hbm_src.dtype, buffer=nl.sbuf)
nisa.dma_transpose(dst=sbuf_dst, src=hbm_src)
Why it is needed#
In a packed, row-major HBM matrix, each row is a contiguous run of values. A straight copy to SBUF puts each row into its own partition. A DMA transpose puts each source column into its own partition instead.
For example, an attention kernel can store a key cache in HBM as [seqlen, d_head]. The matmul Q @ K.T sums over d_head, so NKI needs that axis in the partition dimension. The transpose puts the cache tile into SBUF as [d_head, seqlen].
Trainium2 throughput#
| Operation | Share of peak DMA throughput |
|---|---|
| Plain DMA copy | up to 100% |
| HBM→SBUF transpose | up to 90% |
| SBUF→SBUF transpose | up to 50% |
Reaching these rates requires suitable access patterns. On Trainium2 each NeuronCore-v3 is paired with 16 DMA engines. The fastest transpose access pattern lets all 16 work together, writing a block of [128, 16] at a time. Use all 128 output partitions and make the innermost free dimension a contiguous multiple of 16 to approach the peak. Smaller tiles and other valid shapes can run at lower throughput.
Versus Tensor Engine transpose#
The alternative is transposing on the Tensor Engine, either by multiplying against an identity matrix or, from NeuronCore-v3, with a real transpose mode.
| DMA transpose | Tensor Engine transpose | |
|---|---|---|
| Engine used | DMA only | Tensor Engine |
| Destination | SBUF directly | PSUM, then must be evicted |
| Source | HBM or SBUF | SBUF |
On Trainium2, a Tensor Engine transpose can be faster by itself. If the next operation needs the result in SBUF, the Vector or Scalar engine must copy it there from PSUM. DMA transpose can save that copy in kernels where those engines are already busy, for example with attention softmax.
Before NeuronCore-v3, Tensor Engine transposes had a correctness hazard as well: multiplying by an identity propagates NaN/Inf through the accumulation chain, so the result is not a bit-accurate transpose. v3's explicit transpose mode fixed that.
What is the free dimension?
The free dimensions of a tile are the axes after the first. The partition dimension maps the first axis across physical partitions. The free dimensions describe the elements within each partition.
tile = nl.ndarray((128, 512), dtype=nl.bfloat16, buffer=nl.sbuf)
# ^^^ free dimension
The free dimensions can be wider than 128. A tile of shape (128, 4, 512) has two free axes and puts 4 × 512 elements in each partition.
Capacity and matmul limits#
- Partition capacity. 192 KiB per SBUF partition on NeuronCore-v2, 224 KiB on v3, and 256 KiB on v4. All free dimensions together must fit.
- The
movingfree axis of a matmul is at most 512 elements on v2 and v3, fitting one PSUM bank for FP32 output. On v4 it can use eight banks for up to 4,096 elements with FP32 output or 8,192 with BF16. NKInc_matmulreference, Trainium and Inferentia2 NKI architecture guide - The
stationaryfree axis can hold 128 elements, one for each of the systolic array columns.
Why the ordering matters#
The innermost free axis is the fastest-varying one in a packed tile. On Trainium2, Vector Engine tensor_copy and tensor_scalar on BF16 or FP16 SBUF tiles can run at 4× v2 throughput when that axis is contiguous in both operands. With the same types and buffers but a strided axis, the documented gain is 2×. Contiguous runs also give the DMA engines larger chunks to transfer. Trainium2 NKI architecture guide
In matmul output#
The free axis of the moving tensor becomes the free axis of the output, while the free axis of the stationary tensor becomes the output's partition axis. You can choose the roles to put the output in the layout the next operation expects.
What is Logical NeuronCore configuration?LNC
Logical NeuronCore configuration (LNC) controls how many physical NeuronCores the compiler and runtime present as one logical core. It applies to Trainium2 and Trainium3. LNC=1 exposes each physical core separately. LNC=2 groups cores in pairs, which can reduce the number of workers and model shards. AWS LNC configuration guide
Counting cores on Trn2#
Trn2 defaults to LNC=2 in the runtime. On a trn2.48xlarge, neuron-ls reports 64 logical cores with this configuration. Use that count when sizing worker groups and tensor-parallel degrees.
| Trn2 scope | Physical cores | Logical cores at LNC=2 |
|---|---|---|
| One chip | 8 | 4 |
trn2.48xlarge | 128 | 64 |
Writing and compiling kernels#
At LNC=2, NKI compiles one instruction stream for each physical core. Both can access shared HBM. Call nl.program_id() to get 0 or 1 and select the part of a tensor that core should process. Each core keeps its own SBUF, PSUM, and tile limits, including the 128-partition limit. AWS guide to LNC in NKI
An unspecified NKI 0.7 kernel defaults to LNC=1, while the graph compiler defaults to LNC=2 on Trainium2 and Trainium3. Set NEURON_LOGICAL_NC_CONFIG explicitly and check that the kernel, graph compiler's --lnc setting, and runtime agree. A launch such as kernel[2](x) takes precedence over the environment setting for the kernel. Starting with Neuron SDK 2.33.0, the graph compiler rejects kernel and graph LNC mismatches by default. AWS NKI migration guide
What are MXFP8 and MXFP4?
MXFP8 and MXFP4 are Open Compute Project floating-point formats that store a scale for each small group of values. This is called microscaling. Each group can represent a different range of magnitudes, which helps when one part of a tensor has much larger values than another. MXFP4 uses four data bits per value and MXFP8 uses eight, plus the scale shared by the group.
On Trainium3#
The NeuronCore-v4 Tensor Engine reads one 8-bit scale per 32 elements along the axis the matmul sums over. It can multiply an MXFP8 matrix by an MXFP4 matrix and apply their scales in the same instruction. It converts MXFP4 data to MXFP8 before doing the math. Trainium3 peaks at 2,517 TFLOPS per chip for either format, about four times its BF16 rate. AWS Trainium3 chip specifications, Trainium3 NKI architecture guide, NeuronCore-v4 architecture
In NKI#
nki.isa.nc_matmul_mx reads the stationary and moving tiles from SBUF, along with one scale tensor for each. Each packed element contains four values along the contraction axis. At 128 partitions, one matmul therefore covers 512 contraction elements. The Tensor Engine accumulates in FP32. The PSUM destination can be FP32 with a moving free dimension of up to 4,096, or BF16 with up to 8,192. Both limits use all eight PSUM banks. NKI nc_matmul_mx reference
The v4 Vector Engine can use nki.isa.quantize_mx to produce MXFP8 data and scales from BF16 or FP16 in SBUF. This lets a kernel quantize intermediate activations before the next matmul without moving them through HBM. Ordinary FP8 inputs are available through nki.isa.nc_matmul. Trainium3 NKI architecture guide
What is a NEFF?NEFF
A NEFF is a file in the Neuron Executable File Format. It holds code that runs on a Neuron device. The Neuron Compiler produces it. The Neuron Runtime loads it into device memory and executes it. It is analogous to a CUDA cubin.
A NEFF holds engine instructions and the compiled plan for moving data through SBUF, PSUM and device memory. Weights can be embedded or supplied separately, depending on the framework export. AWS NEFF generation guide
When compilation happens#
The framework chooses when to produce the NEFF and how much work to put in it.
- TorchNeuron can compile a single operator in eager mode or a captured graph on first use with
torch.compile. - A serving stack such as vLLM Neuron can compile graphs for shape buckets during warmup or ahead of deployment.
- Legacy
torch_neuronx.traceproduces a TorchScript artifact that embeds the NEFF and can be saved for later inference.
The compiled code targets specific hardware and input shapes and types. A different shape or option can require another compilation. A matching compilation cache entry can supply the executable without running the compiler again. Compiling a larger graph lets the compiler plan tiling, data movement and synchronization across operators. See software-managed memory for what that plan controls.
What is NISA?NISA
NISA stands for Neuron Instruction Set Architecture, the instructions a NeuronCore executes. NKI exposes low-level operations through nki.isa, usually imported as nisa.
In nki.language you describe the operation, and the compiler selects the instructions. With nki.isa you choose the operation closer to the hardware. Some calls emit more than one instruction or let you pick the engine. These calls use tiles already allocated in suitable buffers.
import nki.isa as nisa
import nki.language as nl
nisa.nc_matmul(dst=matmul_psum, stationary=stationary_sbuf, moving=moving_sbuf)
nisa.nc_transpose(dst=transpose_psum, data=input_sbuf, engine=nisa.engine.tensor)
nisa.dma_transpose(dst=transpose_sbuf, src=input_hbm)
nisa.activation(dst=activation_sbuf, op=nl.gelu, data=input_sbuf)
Each instruction specifies tile size limits, operand types and permitted buffers. For example, Tensor Engine matmul reads SBUF and writes PSUM. AWS nki.isa API · AWS activation API
Instruction families#
| Family | Examples | Engine |
|---|---|---|
| Matmul | nc_matmul, nc_matmul_mx | Tensor |
| Transpose | nc_transpose | Tensor / Vector |
| Element-wise ops | tensor_tensor, tensor_scalar | Vector, with GpSimd and Scalar support depending on the operation |
| Reductions and statistics | tensor_reduce, bn_stats, bn_aggr | Vector |
| On-chip copies | tensor_copy | Vector, Scalar or GpSimd, depending on buffers, types and generation |
| Activations | activation, activation_reduce | Scalar, with some activation modes on GpSimd on v4 |
| Fast exponential | exponential | Vector on v4 |
| Transfers | dma_copy, dma_transpose, dma_compute | DMA |
| Selection | affine_select, range_select, iota, memset | Vector / GpSimd |
| Quantization | quantize_mx | Vector on v4 |
NKI tensor_tensor reference · NKI tensor_scalar reference · NKI tensor_copy reference · NKI exponential reference
Collectives have their own nki.collectives namespace.
Versioning#
Instruction modes vary with the target NeuronCore generation.
nisa.matmul_perf_mode.double_row— the double-rate FP8 matmul, from NeuronCore-v3.nisa.nc_matmul(..., is_transpose=True)— bit-accurate transpose mode, v3.nisa.dge_mode.hwdge— hardware descriptor generation, v3.nisa.quantize_mx— MXFP8 quantization, v4.
A kernel written against v3 instructions will not necessarily run on NeuronCore-v2. To branch at compile time, query the target:
if nisa.get_nc_version() >= nisa.nc_version.gen3:
...
This branch resolves during NKI specialization. The resulting kernel uses the instruction sequence for its target generation. AWS get_nc_version API
What is NKI?NKI
NKI, the Neuron Kernel Interface, is a Python API and compiler for writing kernels that run on the engines inside a NeuronCore. A kernel can implement a single operation or combine several operations so they can reuse data in on-chip memory.
This NKI 0.7 kernel adds two tensors with the same shape and data type. It loads each input as a single tile, so the first axis can have at most 128 entries and the inputs and result must fit in SBUF. Run it with LNC=1.
import nki
import nki.language as nl
@nki.jit
def add_kernel(a_tensor, b_tensor):
out = nl.ndarray(a_tensor.shape, dtype=a_tensor.dtype, buffer=nl.shared_hbm)
a = nl.load(a_tensor)
b = nl.load(b_tensor)
nl.store(out, value=nl.add(a, b))
return out
The inputs and output live in HBM. nl.load brings each input into SBUF before the add. The result goes back to HBM through nl.store. These transfers are explicit because Neuron memory is software-managed.
How a kernel runs#
nki.languageprovides buffers, data types, loops and high-level operations. A convenience operation can lower to one or more hardware instructions.nki.isaexposes low-level operations and their operands. Use it when tuning engine use, memory layout or instruction scheduling.
@nki.jit marks the kernel entry point. In NKI 0.7, Python runs at compile time to decide which operations to emit. A branch on input shape, for example, emits only the operations for the shape seen at compilation. The compiler turns those operations into device instructions on tiles and tells engines when to wait for one another's results. Use the nki.* modules for current kernels. The previous neuronxcc.nki.* namespace has a different API. AWS NKI language guide · AWS NKI migration guide
Using kernels in models#
Native TorchNeuron can call a @nki.jit kernel directly on Neuron tensors in eager mode or inside torch.compile(backend="neuron"). For a named PyTorch custom operator, decorate a typed wrapper with torch_neuronx.nki_op and declare any mutated arguments in mutates_args. To train through the operator, register its backward function with .register_autograd. JAX integration is also available. AWS guide to NKI in TorchNeuron · AWS framework integration guide
The NKI Library offers tuned kernels for common operations. The NKI CPU simulator runs kernels locally for debugging and correctness checks.
What is the NKI CPU simulator?
The NKI CPU simulator runs a @nki.jit kernel in Python and NumPy on a CPU. To debug a kernel, call nki.simulate(kernel)(a, b) with NumPy arrays and compare the result with a reference implementation. You can set Python breakpoints. The experimental simulator also checks many operand constraints and fills uninitialized buffers with recognizable values. PyTorch workflows can opt in with NKI_SIMULATOR=1. AWS NKI CPU simulator guide
The simulator approximates hardware arithmetic and allocates tensors independently, so it cannot tell you whether they all fit on-chip. It can simulate a subset of collectives, with one CPU process per rank. Run the compiled kernel on Trainium to check how it fits on-chip memory and use Neuron Explorer to see instruction timing and engine overlap. AWS simulator limitations
What is the NKI Library?
The NKI Library contains AWS's optimized NKI kernels for Trn2 and Trn3. It includes attention, matrix multiplication, normalization, quantization and collectives. Each kernel's reference lists the layouts, shapes, data types, and configurations it accepts. AWS kernel reference
The Neuron compiler bundles a compatible version that you can import as nkilib. The standalone nki-library package takes precedence when installed in the same environment, so check which library branch or release matches your compiler. The source also shows how each kernel tiles data, manages its buffers, and schedules work. AWS setup and compatibility guide · NKI Library source
What is nki.language?
nki.language, conventionally imported as nl, is the high-level API for NKI. Use it to create tensors in specific memories and express operations and loops. The compiler turns its NumPy-style operations into nki.isa instructions. AWS marks convenience operations such as nl.load, nl.store and nl.softmax as experimental. AWS nki.language API
This kernel computes softmax across the columns of each row. Run it with LNC=1. Each batch of rows keeps the full width in SBUF. Leave room for the softmax intermediates.
import nki
import nki.language as nl
@nki.jit
def softmax_kernel(in_tensor):
out = nl.ndarray(in_tensor.shape, dtype=in_tensor.dtype, buffer=nl.shared_hbm)
rows = in_tensor.shape[0]
tile_rows = nl.tile_size.pmax
for start in range(0, rows, tile_rows):
stop = min(start + tile_rows, rows)
tile = nl.load(in_tensor[start:stop, :])
nl.store(out[start:stop, :], value=nl.softmax(tile, axis=1))
return out
Buffers are explicit#
Neuron memory is software-managed. A tensor's buffer determines which instructions can access it.
| Buffer | Memory |
|---|---|
nl.shared_hbm | HBM, shared by the physical programs of an LNC=2 kernel |
nl.sbuf | SBUF, core-local working memory |
nl.psum | PSUM, core-local matmul accumulation |
nl.private_hbm | HBM private to the physical core |
nl.load and nl.store use DMA to transfer tiles between HBM and SBUF. nl.tile_size.pmax gives the 128-partition limit. The partition is the first on-chip tile dimension, which determines the row count in this example. AWS tile-size API
Specialization and device loops#
The NKI 0.7 frontend unrolls Python for and while loops whose bounds or conditions it can evaluate at compile time. It traces the body once for each iteration. For a counted loop that runs on the device, use nl.fori_loop(lower, upper, body). For a device-side condition, use nl.while_loop(init, body) and return the next condition value from the body.
The old iterators nl.affine_range, nl.sequential_range and nl.static_range are deprecated aliases for range. Migrate nl.dynamic_range loops and Python while loops that test a device register to the compiled loop APIs. AWS NKI loop guide
What is the partition dimension?
The partition dimension is the first axis of any tile in SBUF or PSUM. These memories have 128 physical partitions, so the first axis can hold at most 128 entries. In a 2-D tile, each row occupies one partition.
tile = nl.ndarray((128, 512), dtype=nl.bfloat16, buffer=nl.sbuf)
# ^^^ partition dimension, maximum 128
# ^^^ free dimension
Why 128#
For matrix multiplication, each of the 128 SBUF partitions feeds one row of processing elements in the systolic array. The limit comes from that physical layout.
Which axis goes first in a matmul#
In an ordinary, unpacked matmul, put the contraction dimension on the partition axis of both inputs.
The contraction dimension is the axis you sum over, K in A[M, K] @ B[K, N]. To compute this with nc_matmul, pass A in [K, M] layout and B in [K, N] layout. Double-rate FP8 and MX matmul pack more than one contraction element into each partition. NKI nc_matmul reference
For example, an attention kernel can store keys in HBM as [seqlen, d_head]. Computing Q @ K.T contracts over d_head. A DMA transpose can move the keys to SBUF as [d_head, seqlen] in the same transfer.
Working with it#
In current NKI, the first axis of the shape passed to nl.ndarray is the partition axis for SBUF and PSUM. For a leading axis of 300 elements, tile it into 128, 128, and 44 elements. A loop over range(0, 300, 128) covers all three, including the final partial tile. AWS data representation guide
On NeuronCore-v3, an SBUF partition holds 224 KiB and a PSUM partition holds 16 KiB. Move completed matmul results out of PSUM to make room for the next output tiles.
What are Neuron rounding modes?
The rounding mode determines which value Neuron stores when a floating-point result falls between two representable values.
- RNE (round nearest, ties to even) selects the nearest representable value. At an exact tie, it picks the value with a zero in the last significand bit. This is the default.
- SR (stochastic rounding) chooses either neighboring representable value, with probability proportional to the proximity of the exact result.
RNE is available on all NeuronCore generations. Stochastic rounding is available starting with NeuronCore-v2. AWS rounding modes
Small updates in low precision#
Suppose an update adds 0.5 to an FP16 value of 1024.0. The exact result is halfway between 1024.0 and 1025.0. RNE chooses 1024.0 every time, so repeatedly adding the increment to the rounded result leaves it unchanged. Stochastic rounding picks 1025.0 half the time, preserving the increment in expectation.
The same problem arises when a training update is small relative to a BF16 weight. Stochastic rounding can help such updates accumulate and can make a full-precision master copy of weights unnecessary for some workloads. That saves HBM, with convergence depending on the training recipe. AWS rounding modes and accumulation example
Runtime settings#
Set NEURON_RT_STOCHASTIC_ROUNDING_EN=1 to enable stochastic rounding in the runtime. For controlled comparisons, the Neuron Runtime also exposes NEURON_RT_STOCHASTIC_ROUNDING_SEED. AWS runtime environment variables
What is software-managed memory?
Memory on a NeuronCore is software-managed. The kernel or Neuron Compiler schedules the transfers between device memories. AWS memory hierarchy guide
A CPU or GPU cache can fetch a missing line automatically. NeuronCore has no such cache between device memories. To compute on data in HBM, the program issues a DMA transfer to SBUF.
Consequences#
- Estimate arithmetic intensity by counting the operations and bytes transferred in the schedule. The compiler can insert extra transfers for spills, so check a profile when the numbers disagree.
- Work in tiles to fit the available on-chip memory. Keep a tile in SBUF for reuse when possible. Issuing another load moves those bytes from HBM again.
- Schedule a DMA transfer for the next tile while the Tensor Engine uses the current one. See latency hiding.
neuronx-cc encodes the memory plan in a NEFF. In TorchNeuron eager mode, the backend compiles or reuses device code for each supported operator as PyTorch calls it.
The hierarchy#
| Level | Memory | Managed by | Moved with |
|---|---|---|---|
| On-chip | PSUM | program | engine instructions |
| On-chip | SBUF | program | DMA to/from HBM |
| Device | HBM | program | DMA |
| Host | CPU DRAM | framework | PyTorch / JAX |
Compute-engine instructions move tensors between SBUF and PSUM. The framework transfers tensors between host and device memory before and after NKI kernels run.
When you exceed capacity#
If live tiles exceed on-chip capacity, the compiler can move them to a larger memory and reload them when needed. A spill from SBUF to HBM adds a write and a read to the kernel's HBM traffic. See spilling.
What are stationary and moving matrices?
A matrix multiplication on the Tensor Engine has two inputs. The stationary matrix stays in the systolic array while the moving matrix streams through it.
LoadStationary(LS) loads the stationary matrix into the array.- The moving matrix is streamed by a
MultiplyMoving(MM) instruction, multiplying against the held stationary matrix and writing results to PSUM.
One nki.isa.nc_matmul call lowers to those two hardware instructions.
# stationary: [K, M], moving: [K, N], dst: [M, N]
nki.isa.nc_matmul(dst, stationary, moving) # stationary.T @ moving
In this unpacked matmul, both inputs put the contraction dimension K on the partition axis. That is why the math reads stationary.T @ moving.
The layout rule#
The free axis of
stationarybecomes the partition axis of the output. The free axis ofmovingbecomes the free axis of the output.
The layout follows the geometry of the array. Results emerge along the axis perpendicular to the input partitions, so AWS's architecture diagrams draw the PSUM partition dimension at a right angle to SBUF's. Trainium2 NKI architecture guide
Choosing the output layout#
You can swap the roles, and you get a transposed result:
nki.isa.nc_matmul(dst_mn, x, y) # [M, N]
nki.isa.nc_matmul(dst_nm, y, x) # [N, M]
If both inputs fit the chosen roles, choose the order that gives the next operation the layout it needs. For example, if it needs N on the partition axis, produce [N, M] directly and save a transpose.
Tile size limits differ by role#
The two roles have different caps, which is another reason the assignment matters. For a standard nc_matmul with hardware tiling mode off:
| Role | Axis | Limit | Source |
|---|---|---|---|
stationary | free | 128 | array columns |
stationary | partition | 128 | array rows |
moving | partition | 128 | array rows |
moving, v2 and v3 | free | 512 | one PSUM bank with FP32 output |
moving, v4 | free | 4,096 (FP32 output) or 8,192 (BF16 output) | up to eight PSUM banks |
The moving role can take a wider free dimension than the stationary role. That can reduce the number of matmul calls needed to cover the output. NKI nc_matmul reference, Trainium and Inferentia2 NKI architecture guide
Double-rate FP8#
On NeuronCore-v3, the double-rate FP8 mode extends the contraction dimension to 256 by giving each processing element two multiply-accumulates per cycle. Both operands take an extra axis of size exactly 2:
# stationary: [128, 2, 128] moving: [128, 2, 512] dst: [128, 512]
nisa.nc_matmul(dst, stationary, moving, perf_mode=nisa.matmul_perf_mode.double_row)
LoadStationary places two values in each processing element. MultiplyMoving streams in two matching values so the element can compute both products in the same cycle. Zero-pad an odd contraction length before packing it into the two axes.
What is structured sparsity?
Structured sparsity is a regular pattern of zeros in a matrix. On NeuronCore-v3 and v4, the Tensor Engine can use that pattern to skip multiplications by zero.
The pattern is M:N: within every group of N contiguous elements, at most M are non-zero. Neuron supports 4:16, 4:12, 4:8, 2:8, 2:4, 1:4, and 1:2.
At 2:4, at least two entries in every group of four must be zero. One of the two matmul inputs needs to follow the pattern. Model weights are a common choice because they can be pruned ahead of time.
Peak throughput#
| Scope | Input format | Dense TFLOPS | Sparse TFLOPS |
|---|---|---|---|
| Trainium2, per chip | FP8 | 1,299 | 2,563 |
| NeuronCore-v3, per engine | cFP8 | 158 | 316 |
| NeuronCore-v4, per engine | FP16 / BF16 / TF32 | 79 | 315 |
AWS publishes the chip and engine peaks separately. On v4, dense MXFP8 and MXFP4 also peak at 315 TFLOPS per engine. They use a separate dense path. AWS Trainium2 specifications, AWS NeuronCore-v3 architecture, AWS NeuronCore-v4 architecture
The v3 Tensor Engine has an input path of 2×128 elements per cycle for dense BF16 and 5×128 for sparse input. Trainium2 NKI architecture guide
Why the pattern has to be structured#
A systolic array streams data through a fixed grid in lockstep. A dense matmul still processes arbitrary zeros. An M:N pattern lets the sparse path reserve a fixed number of slots per group and encode where those values belong.
To use a supported pattern, prune weights to meet the per-group limit and measure model accuracy. Fine-tuning can help recover accuracy after pruning. Both 1:2 and 4:8 keep at most half the weights, but a group of eight gives pruning more choice about which weights to keep. With 4:16, each group keeps at most a quarter of the weights.
Restrictions#
On NeuronCore-v3, sparse matmul is incompatible with double-rate FP8 mode. The dense FP8 double-row mode and the sparse path have separate peak rates. Trainium2 NKI architecture guide
What is a tile?
A tile is a rectangular chunk of a tensor, sized to fit in on-chip memory and meet the shape limits of the instruction that will use it. Tensor instructions on a NeuronCore take tiles as inputs or destinations.
A typical NKI kernel loads tiles, computes on them and stores the results.
A tile in SBUF or PSUM has one partition dimension and one or more free dimensions. The first axis can use up to 128 physical partitions. The other axes describe the values within each partition.
# A BF16 moving tile for a matmul on NeuronCore-v3.
tile = nl.ndarray((128, 512), dtype=nl.bfloat16, buffer=nl.sbuf)
In a standard matmul, each input has a different role and a different limit on its free dimension.
| Constraint | Limit | Source |
|---|---|---|
| Partition axis | 128 | SBUF partitions, systolic array rows |
stationary free axis | 128 | systolic array columns |
moving free axis, v2 and v3 | 512 | one FP32 PSUM bank per partition |
moving free axis, v4 | 4,096 (FP32 output) or 8,192 (BF16 output) | up to eight PSUM banks per partition |
| Total live SBUF data, v2–v4 | 24–32 MiB per core | SBUF capacity |
Matmul tiles must meet the size limits for the target instruction. If live intermediates exceed available SBUF, the compiler may spill them to HBM. NKI nc_matmul reference
Pipelining tiles#
A GPU can hide memory latency by running another warp while one waits for data. On Neuron, the kernel or compiler can overlap explicit DMA transfers with computation. With enough buffer space and independent work, a pipeline can look like this.
load tile n+1 (DMA, in background)
compute tile n (Tensor Engine)
store tile n-1 (DMA, in background)
See latency hiding for how these transfers can overlap.
Tile size is also the main lever on arithmetic intensity in matmul. A larger tile can reuse its inputs for more operations per byte fetched from HBM.
For how to choose tile shapes, see tiling.
What is tiling?
Tiling is splitting a tensor operation into tile-sized pieces that fit the hardware's shape limits and on-chip memory. In an NKI kernel, split any axis that would otherwise need more than 128 on-chip partitions.
Matmul tile limits#
These limits apply to ordinary nc_matmul with hardware tiling mode off:
- Partition axis ≤ 128. SBUF has 128 partitions, wired to the 128 rows of the systolic array.
stationaryfree axis ≤ 128, the number of array columns.movingfree axis. On v2 and v3, the limit is 512 elements for an FP32 destination in one PSUM bank. On v4, the limit is 4,096 for FP32 output or 8,192 for BF16 output across eight banks. NKInc_matmulreference, Trainium and Inferentia2 NKI architecture guide
In an unpacked matmul, the contraction dimension maps to the partition dimension of both operands.
That is the axis the array sums over. If a tile arrives with K on its free axis, move K to the partition axis before the matmul. You can arrange that layout in the operation that produces the tile or use a transpose.
Tiling a matmul#
For A[M, K] @ B[K, N], splitting an output axis and splitting the contraction axis do different things.
MandNsplit into independent tiles with disjoint outputs.Ksplits into pieces whose results must be summed. Run the firstnc_matmulwithaccumulate=False, then useaccumulate=Trueto add later products to the same PSUM destination.
For example, unpacked K = 4096 can use 32 matmuls that accumulate into one PSUM tile, without a separate reduction.
Choosing sizes#
Larger matmul tiles can reuse inputs for more multiply-adds per byte of HBM traffic, increasing arithmetic intensity. A 128×128 stationary tile uses the full Tensor Engine array. On v4 a wider moving tile uses more PSUM banks, leaving less space for other live outputs.
Budget SBUF for all live tiles. Double-buffering needs room for the current tile and the next one so computation and data transfer can overlap. If the live tiles exceed capacity, the compiler may spill to HBM.
Layout decisions#
The free axis of the stationary tile becomes the partition axis of the result. The moving tile supplies the result's free axis. Choose stationary and moving roles that put the result in the layout the next operation needs.
Double-rate FP8 matmul requires the second axis of both inputs to have length 2. Zero-pad an odd contraction length before packing. MX matmul on v4 packs four contraction elements into each input element and requires a partition axis of size 32, 64, or 128. NKI nc_matmul_mx reference
What is JAX NeuronX?
JAX NeuronX is the beta plugin that lets JAX train and run models on Inf2, Trn1, Trn2, and Trn3. The libneuronxla package makes Neuron devices available through PJRT, JAX's plugin interface for accelerator backends. The jax-neuronx package brings in a tested set of dependencies and adds support for calling NKI kernels. JAX NeuronX overview · Installation matrix
When you call a function wrapped in jax.jit, JAX records the computation and passes it through the XLA stack. The Neuron backend compiles it for the device. Changing shapes, dtypes, or how arrays are split across devices can trigger a new compilation. After setup, run jax.devices() to confirm JAX sees your Neuron devices. AWS installation check
What is nccom-test?
nccom-test measures how fast Trainium workers exchange data through collectives such as all-reduce, all-gather, reduce-scatter, and all-to-all. The example measures all-reduce across two workers (ranks) at several message sizes.
nccom-test -r 2 --minbytes 1024 --maxbytes 1073741824 --stepfactor 4 --datatype fp32 allr
Reading the results#
time(us)is the measured collective latency in microseconds.algbwdivides the message size by the measured time. It is the application's effective throughput for that operation and those ranks.busbwscalesalgbwby a factor based on the collective and rank count. For an all-reduce acrossrranks the factor is2 × (r − 1) / r. It estimates communication bandwidth per rank from the amount of data the algorithm exchanges.
The columns labeled GB/s use GiB/s, according to the AWS guide. Compare runs with the same operation, message size, dtype and rank placement. --show-algorithm helps explain a change across configurations. AWS NCCOM-TEST user guide
Topology and placement#
Use neuron-ls --topology to inspect device connectivity. Trainium can use NeuronLink between chips on a single instance and across hosts within a supported UltraServer. Cross-instance collectives outside that NeuronLink domain use EFA. Match the rank placement to your workload when measuring bandwidth. Chip specifications describe the link hardware, while nccom-test reports the throughput of an operation. AWS inter-node collectives guide
For an application-level check, use Neuron Explorer to see when the CC-Cores run and whether the app overlaps communication with compute.
What is neuronx-cc?neuronx-cc
neuronx-cc is the Neuron Graph Compiler for Inf2, Trn1, Trn2 and Trn3. It translates a graph of tensor operations into a NEFF built for the chosen accelerator, which the Neuron Runtime loads and executes. neuron-cc is the separate legacy compiler for Inf1.
Your framework usually invokes the compiler for you. If you have exported a graph as an XLA HLO protobuf, you can compile it directly.
neuronx-cc compile model.hlo.pb --framework XLA --target trn2 --output model.neff
What the compiler decides#
Neuron's device memory is software-managed. The compiler schedules compute, tiling, DMA transfers, buffer lifetimes, and synchronization. When the compiler sees several operations together, it can sometimes fuse them and keep intermediate results in on-chip memory. With native TorchNeuron, the compilation unit may be an operator in eager mode or a captured graph under torch.compile. The caller's graph and cache determine when a fresh compilation is needed.
Options worth knowing#
- Precision.
--auto-cast=noneis the compiler default starting in Neuron SDK 2.27. Older versions defaulted to casting FP32 matrix operations to BF16. Use--auto-cast=matmult --auto-cast-type=bf16to opt into that behavior. The framework's own mixed-precision policy is a separate setting. Neuron 2.27 compiler release notes - Model type and optimization level.
--model-typecan targettransformerorunet-inference.-Ocontrols the optimization level. - Integer behavior.
--native-int64=enabledrequests native 64-bit execution on Trn2 and later where supported.--implicit-integer-downcastcontrols whether operations without a suitable integer datapath can use a lossy conversion. Check data types and the CLI reference before relying on defaults.
When graph compilation fails, the framework decides how to handle the error. TorchNeuron has different fallback rules for eager operators and compiled graphs. The compilation caches can reuse a previously compiled executable.
What is the Neuron device plugin?
The Neuron device plugin tells Kubernetes how many Neuron devices and NeuronCores a node can allocate. A container can request whole devices with aws.amazon.com/neuron or cores with aws.amazon.com/neuroncore. This fragment requests four devices.
resources:
limits:
aws.amazon.com/neuron: 4
If a pod needs a group of chips connected by NeuronLink, the Neuron scheduler extension can select that group. Neuron DRA lets pods request devices by attributes and topology through Kubernetes resource claims. EKS Auto Mode includes the device plugin for Neuron hardware. AWS EKS device management guide
The Neuron driver runs on the host. The pod uses the exposed devices through the Neuron Runtime and its framework packages, typically from a Neuron DLC.
The Neuron Node Problem Detector reports health problems at the node level. Automatic node recovery is opt-in. For isolation of a single faulty device on a standalone Trainium instance, see DRA device taints and Neuron Observer. AWS Node Problem Detector guide · AWS device taints guide
What are Neuron DLAMIs and DLCs?DLC
Neuron DLAMIs (Deep Learning Amazon Machine Images) set up the EC2 host. Base images include the Neuron driver, EFA software, and Neuron tools. Framework images add one or more Python environments with preinstalled training or inference packages. AWS Neuron DLAMI guide
Neuron DLCs (Deep Learning Containers) package the application environment, including the runtime and framework packages. They use the driver installed on the host. On Kubernetes, the Neuron device plugin or Neuron DRA allocates devices and exposes them to pods. AWS EKS device management guide
Image and host compatibility#
AWS publishes Neuron SDK 2.33 DLCs on Ubuntu 26.04. The host image has its own version matrix. For example, AWS publishes the multi-framework DLAMI for Ubuntu 24.04 and 26.04 and a base DLAMI for Amazon Linux 2023. For a manual host installation, the runtime and driver compatibility tables list tested operating systems, kernels, and glibc versions by instance family. AWS container release notes · AWS DLAMI release notes AWS runtime and driver compatibility
What is Neuron Dynamic Resource Allocation?DRA
The Neuron Dynamic Resource Allocation (DRA) driver lets Kubernetes allocate Neuron devices based on their hardware and how they are connected. The driver publishes available devices and attributes in ResourceSlice objects. A workload uses a ResourceClaim or ResourceClaimTemplate to request devices from the neuron.aws.com device class. Where supported, the claim can select a connected group of chips or set a Logical NeuronCore configuration for the allocation. AWS Neuron DRA guide
On EKS, Neuron DRA requires Kubernetes 1.34 or later. It runs on supported Trainium and Inferentia2 nodes provisioned by Karpenter, EKS managed node groups or self-managed node groups. Allocation modes vary by instance type. For Kubernetes 1.34, the Neuron guide specifies node AMIs at 1.34.2 or later. EKS Auto Mode uses the Neuron device plugin for Neuron accelerators. Each node uses one allocator for its Neuron devices. AWS EKS device management guide · AWS Neuron DRA prerequisites
The Neuron UltraServer Operator uses DRA's ResourceSlice objects to manage supported Trn3 UltraServer workloads. On Trainium, DRA can also use Neuron Observer fault events to mark faulty devices with device taints. Taints can keep Kubernetes from placing work on those devices. This beta feature is opt-in and requires Kubernetes 1.36 or later, DRA driver 1.3.0 or later, and a Neuron kernel driver from SDK 2.33.0 or later. A fault taints the affected device on a standalone instance, or the node-level allocation on an UltraServer. AWS UltraServer Operator guide · AWS device taints guide
What is the Neuron driver?
The Neuron driver, packaged as aws-neuronx-dkms for Inf2 and Trainium, is the Linux kernel module that gives the host access to Neuron devices. The Neuron Runtime uses it to communicate with the hardware.
The package uses Dynamic Kernel Module Support (DKMS) to build the module for the host kernel. After a kernel upgrade, it needs matching headers and a successful build for the new kernel. These commands check whether Linux has loaded the module and whether Neuron can see the devices.
lsmod | grep neuron
neuron-ls
AWS Neuron Runtime and Driver compatibility reference
OS and kernel compatibility#
The compatibility reference lists tested configurations by instance family, OS, kernel, and glibc version. Neuron Driver 2.31 added support for Linux 7.0, the default kernel in Ubuntu 26.04. Neuron 2.33.0 dropped Amazon Linux 2 support. Driver 2.31 also reorganized the Neuron sysfs tree, so scripts that read device attributes directly may need new paths. AWS Neuron Driver release notes · AWS Amazon Linux 2 announcement · AWS sysfs migration guide
The driver comes installed on a Neuron DLAMI. In a container deployment, the driver stays on the host and the workload uses exposed device files. On EKS, the Neuron device plugin or Neuron DRA handles allocation.
What is Neuron Explorer?
Neuron Explorer is a profiler that records when a Neuron workload runs each operation. Its timelines let you see whether compute overlaps with DMA transfers and which dependencies leave an engine idle. For ongoing utilization and memory metrics, see neuron-monitor.
What it shows#
- Per-engine timelines for the Tensor, Vector, Scalar, and GpSimd engines, plus DMA queues.
- A hierarchy view, from the whole model down to individual instructions.
- A memory viewer for SBUF, PSUM, and HBM allocation.
- A tensor viewer for inspecting actual values.
- Source linking, mapping instructions back to your NKI or framework code.
- Device and system profiles cover on-device execution or a wider trace that includes host activity and collectives.
- AI recommendations, automated suggestions from the profile.
You can also open traces in Perfetto. AWS Perfetto guide
What to look for#
Gaps on the Tensor Engine timeline. Follow the dependency arrows to see what the next matrix multiply needs. A late DMA transfer can leave it waiting for input. It can also wait for another engine to consume the previous result in PSUM. See latency hiding.
Softmax in an attention trace. Check which engine evaluates the exponentials before looking for a bottleneck. A kernel can use nki.isa.activation on the Scalar Engine. On NeuronCore-v4 it can also use nki.isa.exponential on the Vector Engine. AWS Trainium3 NKI architecture guide
Unexpected DMA traffic. Compare against the expected transfers to spot extra HBM round trips from spilling.
Capturing and exporting profiles#
Use neuron-explorer capture with a compiled NKI kernel. To profile a live vLLM Neuron server, use its profiling endpoints for capture and open the output in Explorer. Native TorchNeuron also integrates with torch.profiler.profile. Pass ProfilerActivity.CPU, ProfilerActivity.PrivateUse1, and a NeuronConfig to correlate the framework trace with runtime and device activity. AWS capture guide · AWS vLLM Neuron profiling guide · AWS PyTorch profiling guide
For programmatic analysis, neuron-explorer view --output-format parquet exports the full profile as Parquet tables. AWS plans to retire the full-profile JSON export in the next SDK release, identified as 2.34 in the 2.33.1 export guide. PyTorch's trace.json is a separate input that adds framework events to an Explorer profile. AWS full-profile JSON announcement · AWS profile export guide · AWS profile files reference
Neuron Explorer replaces Neuron Profiler and Neuron Profiler 2.0, and can open existing NEFF and NTFF captures from those tools. AWS migration guide
What is Neuron Observer?
Neuron Observer is a service that monitors the health and performance of Trn2 and Trn3 nodes on Amazon EKS. It entered public beta in Neuron 2.33.0. It identifies the node and device affected by a hardware fault and collects utilization, latency, and network metrics. You can query node health with the nobs command or HTTP API, collect metrics with Prometheus, or export them through OpenTelemetry. AWS Neuron Observer overview · AWS Neuron Observer release notes
With device health monitoring enabled, Neuron DRA can use Observer fault events to mark a faulty device on a standalone Trainium instance or a node-level allocation on an UltraServer. Kubernetes uses that mark, called a taint, when deciding where to place workloads. neuron-monitor remains supported for JSON metrics, and Neuron Explorer captures traces for workload profiling. AWS device taints guide
What is the Neuron persistent cache?
The Neuron Persistent Cache saves compiled NEFFs from the legacy PyTorch/XLA and Transformers NeuronX stacks. When a later run needs the same executable, it can load the file and skip compilation. Native TorchNeuron and vLLM Neuron have their own caches with different settings.
Which cache applies?#
| Stack | What it saves and how to configure it |
|---|---|
Legacy PyTorch/XLA lazy execution and transformers-neuronx | The Neuron Persistent Cache stores compiler results in /var/tmp/neuron-compile-cache by default. Select a local directory or S3 URI with NEURON_COMPILE_CACHE_URL or the wrapper's NEURON_CC_FLAGS=--cache_dir=.... The lazy path also has a per-process JIT cache. The persistent cache excludes graphs created with torch_neuronx.trace when weights are frozen. |
| Native TorchNeuron | The native backend has a content-addressed NEFF cache (TORCH_NEURONX_NEFF_CACHE_DIR, default /tmp/neff_cache) and an HLO cache shared by eager and compiled execution (TORCH_NEURONX_HLO_CACHE_DIR). An optional Dynamo precompile cache (TORCH_CACHING_PRECOMPILE) can reuse work from graph capture. Use a shared NEFF cache across instances and keep TORCH_NEURONX_NEFF_LOCAL_CACHE_DIR for local locks and scratch. |
| Standalone vLLM Neuron | The plugin's compilation cache stores compiled graphs locally by default under $VLLM_CACHE_ROOT/neuron/compile_cache and supports an optional shared NFS or FSx tier (NEURON_LIBTORCH_REMOTE_CACHE). The native route also saves graph traces in its Precompile Cache to speed up startup. |
| Legacy NxD Inference | NEURON_COMPILED_ARTIFACTS selects a directory with a precompiled model export. Legacy integration guide |
For JAX NeuronX, use the cache settings for your installed JAX and PJRT versions.
Preparing a deployment#
Warm up the exact model and serving configuration you intend to deploy, then verify a restart can find the artifacts. Shapes, dtypes, compiler options, compiler versions, or the target can change the graph or cache key. A warm startup can reuse compiled code and still has to load weights and initialize the server. A serving KV cache stores attention state for requests.
What is the Neuron Runtime?libnrt
The Neuron Runtime loads compiled NEFFs onto Neuron devices and executes them through the Neuron driver. It reserves cores for the process, allocates device memory, moves inputs and outputs, and runs collectives.
Native TorchNeuron, JAX NeuronX and the legacy PyTorch/XLA integration use this runtime. The aws-neuronx-runtime-lib package supplies the C library at /opt/aws/neuron/lib/libnrt.so and headers under /opt/aws/neuron/include. You can also load and execute a NEFF directly through the Python nrtpy API. AWS Runtime developer guide · AWS nrtpy guide
Core allocation and runtime settings#
| Variable | Effect |
|---|---|
NEURON_RT_VISIBLE_CORES | Specify which logical NeuronCore IDs the process can use, for example 0-3 |
NEURON_RT_NUM_CORES | Reserve the requested number of available cores |
NEURON_LOGICAL_NC_CONFIG | Select how many physical cores make up a logical NeuronCore on supported hardware |
NEURON_RT_STOCHASTIC_ROUNDING_EN | Enable stochastic rounding |
NEURON_RT_LOG_LEVEL | Control runtime log verbosity |
NEURON_RT_VISIBLE_CORES takes precedence over NEURON_RT_NUM_CORES. AWS Runtime configuration guide · AWS Runtime environment variables
If device access breaks after an upgrade, check that your instance family, host OS, kernel, and glibc match the compatibility table. Some Neuron SDK 2.33 runtime features, including asynchronous tensor I/O and host-device transfer profiling, require Neuron Driver 2.31 or later. AWS compatibility reference · AWS Neuron 2.33 changes
What is the Neuron SDK?
The AWS Neuron SDK is the software stack for Inferentia and Trainium. It connects your model code or serving engine to the compiler, runtime, and device driver. A Neuron release bundles components that each have their own version numbers. Neuron 2.33.1 release notes
Which software should I use?#
The table describes Neuron 2.33.1 and notes the separately released SGLang preview. Start with the row for your workload and instance family.
| Workload | Where to start |
|---|---|
| PyTorch training or inference in your own script on Trn2 or Trn3 | TorchNeuron runs PyTorch operators in eager mode and can optimize graphs with torch.compile. For large-model pretraining, see TorchTitan Neuron. |
| Hugging Face fine-tuning or inference from Python on Trn2 or Trn3 | The upstream Hugging Face libraries can use the native neuron device through TorchNeuron. |
| Text and vision-language serving on Trn2 and Trn3 | vLLM Neuron, the standalone plugin. |
| Diffusion and multimodal generation on Trn2 or Trn3 | vLLM Omni Neuron. |
| SGLang serving on Trainium | The SGLang-Neuron preview covers language models on Trn3 and diffusion models on Trn2. |
| JAX training or inference on Inf2, Trn1, Trn2 or Trn3 | JAX NeuronX makes Neuron devices available to JAX. |
| Custom kernels | NKI, called from a framework or used in model implementations. |
| Existing PyTorch inference on Inf2 or Trn1 | The legacy PyTorch NeuronX integration is in maintenance. Deployments that use NxD Inference are maintained on SDK 2.31. |
| Existing Inf1 inference | See the legacy software listed under Inf1. |
Compiler, runtime and tools#
The compiler neuronx-cc turns a computation into a device executable called a NEFF. The runtime loads and executes them through the driver. The framework decides when to compile and which cache to consult. In native PyTorch eager mode, the compiler can see one operator at a time. A serving engine can compile a larger graph and share it across requests that fit the same input dimensions.
Deep Learning AMIs and containers ship tested combinations. Use neuron-ls for device discovery, neuron-monitor for metrics, and Neuron Explorer for profiling.
What is neuron-ls?
neuron-ls lists the Neuron devices on an instance or exposed to a container. It shows which cores belong to each device, how the devices connect, and which processes are using them.
Excerpt from AWS's example of a 16-chip Trn2 system with LNC set to 2.
$ neuron-ls
logical-neuroncore-config: 2
+--------+--------+----------+--------+---------------+--------------+---------------+------+
| NEURON | NEURON | NEURON | NEURON | CONNECTED | PCI | CPU | NUMA |
| DEVICE | CORES | CORE IDS | MEMORY | DEVICES | BDF | AFFINITY | NODE |
+--------+--------+----------+--------+---------------+--------------+---------------+------+
| 0 | 4 | 0-3 | 96 GB | 12, 3, 4, 1 | 0000:cc:00.0 | 48-95,144-191 | 1 |
| 1 | 4 | 4-7 | 96 GB | 13, 0, 5, 2 | 0000:b5:00.0 | 48-95,144-191 | 1 |
...
| 15 | 4 | 60-63 | 96 GB | 11, 14, 3, 12 | 0000:f7:00.0 | 48-95,144-191 | 1 |
Reading the inventory#
logical-neuroncore-config: 2. This is LNC, and it is why the NEURON CORES column reports four logical cores per device. Each Trainium2 chip physically has eight NeuronCore-v3 cores. The whole instance exposes 64 logical cores. A tensor-parallel group can use a subset if the model and topology support it.
CONNECTED DEVICES. The NeuronLink neighbors of each device. Four neighbors per device match the 4×4 2D torus on 16-chip Trn2 instances. --topology displays the system topology.
NUMA NODE and CPU AFFINITY. These columns show which host CPU and memory domain is closest to a device. Placement matters when the host moves data to the accelerator frequently. The table's 96 GB memory label corresponds to the 96 GiB per chip listed in the Trainium2 specifications.
Options#
| Flag | Effect |
|---|---|
-w, --wide | Wider table |
-a, --show-all-procs | Include processes not using Neuron Runtime 2.x, such as neuron-monitor |
-t, --topology | Show device topology |
-j, --json-output | Emit the Neuron 2.33.1 JSON format |
It works on all Neuron instance types — Inf1, Inf2, Trn1, Trn2, and Trainium3 instances. AWS neuron-ls user guide
AWS announced that Neuron 2.34 will replace --json-output and -j with --output-format json. The updated schema adds top-level instance and UltraServer fields, so scripts that consume the 2.33 output need to update both the flag and their parser. AWS neuron-ls JSON announcement
Diagnosing device access#
If the list is empty on a Neuron instance, check host driver installation and whether the driver built for the current kernel. From a container, also check the device mappings. Use the process columns or --show-all-procs when a process may still be holding devices.
What is neuron-monitor?
neuron-monitor collects periodic metrics from the Neuron Runtime and the host. It writes each sample as JSON to standard output, where a script can read it. Companion scripts can expose the metrics to Prometheus or publish them to CloudWatch.
neuron-monitor | neuron-monitor-prometheus.py --port 8008
The exporter in this example requires the Prometheus Python client. AWS neuron-monitor user guide
What it reports#
- Per-NeuronCore utilization.
- Device memory usage, with categories such as model code, constants, tensors and runtime allocations.
- Application execution counts, latency statistics and errors.
- System CPU and memory usage and hardware counters such as ECC events.
The JSON configuration selects which applications and metrics to include and how often to sample them. Core utilization tells you how long a core was busy. To see what each engine or DMA queue was doing, use Neuron Explorer. AWS monitoring configuration and metric groups
For interactive use, neuron-top shows live utilization and memory. Neuron Observer adds per-device health events and cluster telemetry for Trn2 and Trn3 on Amazon EKS. Both tools are supported in Neuron 2.33.1. AWS Neuron Observer overview
What is neuron-top?
neuron-top is a terminal dashboard for live NeuronCore utilization, host and device memory usage, and models loaded by each process.
neuron-top
Open it to see which cores a process is using and how much memory it has allocated. For scripts, dashboards, and alerts, use the JSON output from neuron-monitor. AWS neuron-top user guide
The limits of a utilization number#
A core can look busy when the Scalar Engine is working and the Tensor Engine is idle. To see what each engine spent time doing, capture a trace with Neuron Explorer. Device memory usage gives you a starting point for checking whether a larger batch or longer context will fit.
What is NxD Core?
NxD Core (NeuronX Distributed Core) supplies the distributed building blocks for NxD Inference and NxD Training. Install it as neuronx-distributed and import it as neuronx_distributed. For example, a sharded linear layer splits its weights across chips for tensor parallelism. NxD Core also creates the process groups for those chips and provides tools for saving and loading sharded checkpoints. Archived release notes
Support and replacement APIs#
AWS put the training APIs in maintenance in Neuron 2.30 for critical security fixes. For new Trn2 and Trn3 training, use PyTorch's distributed APIs via TorchNeuron or TorchTitan Neuron for large-scale pretraining. AWS training maintenance announcement
The inference APIs have a separate lifecycle. On Inf2 and Trn1 they stay in maintenance at Neuron 2.31 for critical bug and security fixes. For Trn2 and Trn3, AWS announced an end to support in Neuron 2.34. Native torch.compile(backend="neuron") replaces model-building and tracing APIs such as ModelBuilderV2 and parallel_model_trace in the neuronx_distributed.trace module. For LLM serving on Trn2 and Trn3, use vLLM Neuron. AWS inference support announcement
What is NxD Inference?NxDI
NxD Inference (NeuronX Distributed Inference, or NxDI) is the legacy neuronx-distributed-inference library for running inference across Neuron cores. It implements supported models and uses NxD Core to split computation and move data between cores. It also manages the KV cache and supports features such as continuous batching, quantization, and speculative decoding for selected models. The legacy vLLM + NxD Inference integration loads models from this library. AWS NxDI overview
Support and migration#
NxDI and the NxD Core inference APIs are in maintenance for critical bug and security fixes. AWS announced an end to that support on Trn2 and Trn3 in Neuron 2.34. On Inf2 and Trn1, maintenance continues on Neuron 2.31. AWS inference support announcement
For new text or vision-language serving on Trn2 and Trn3, use the standalone vLLM Neuron plugin. It supplies its own model implementations and builds executables for the selected model and serving configuration. For inference from a PyTorch script, use TorchNeuron with torch.compile. AWS migration guide
What is NxD Training?NxDT
NxD Training (NeuronX Distributed Training, or NxDT) is the legacy PyTorch/XLA library for distributed pretraining and fine-tuning on Trainium. It builds on NxD Core. Older recipes use YAML to describe how to divide a model or dataset across workers with tensor, pipeline, and data parallelism. NxDT also supports splitting optimizer state with ZeRO-1 and converting checkpoints. The package is neuronx-distributed-training.
Support and migration#
AWS put NxDT and NxD Core training APIs in maintenance in Neuron 2.30 for critical security fixes. The last SDK release to support the NxDT package was Neuron 2.31.0, with neuronx-distributed-training pinned to 1.7.0. Starting in 2.31.0, AWS stopped including NxDT in Neuron AMIs. For an AMI with NxDT preinstalled, use a 2.30.0 or earlier image. Maintenance announcement · NxDT release notes · Neuron 2.31 changes
On Trn2 and Trn3, use TorchNeuron with standard PyTorch distributed APIs for new PyTorch training. For pretraining recipes, start with TorchTitan Neuron.
What is SGLang-Neuron?
SGLang-Neuron is a plugin that lets the SGLang serving engine run models on Trainium through TorchNeuron. Version 0.1.0 launched as a public preview on November 12, 2026, with its own container. On Trn3, the preview can run the prompt and token generation phases of language models on separate workers (prefill/decode disaggregation). On Trn2, it runs supported models using SGLang Diffusion.
The preview covers models such as GPT-OSS-120B for text generation and FLUX.1-dev and Wan2.2 A14B for diffusion. See the supported configurations and container tag in the release notes for this preview. SGLang-Neuron release notes
What is torch-neuronx?
torch-neuronx is the package name shared by native TorchNeuron and the older PyTorch NeuronX integration. The version tells you which programming model a recipe expects.
| Build | What it provides in Neuron 2.33.1 |
|---|---|
2.13.* or 2.14.* | TorchNeuron, the native neuron device backend in public beta on Trn2 and Trn3. Use eager mode or torch.compile(backend="neuron"). |
2.9.* | The deprecated PyTorch NeuronX build based on PyTorch/XLA. PyTorch 2.9 is the last PyTorch release family for this integration. Neuron 2.33.1 still ships the wheel for existing inference workloads. |
The 2.33.1 package inventory labels the 2.9 wheel as native PyTorch. AWS's component release notes identify that wheel as PyTorch/XLA and list the native builds under TorchNeuron. Package inventory · PyTorch NeuronX release notes · TorchNeuron release notes
torch-neuron is the separate legacy package for Inf1.
Reading older PyTorch/XLA code#
In legacy inference code, torch_neuronx.trace(model, example) creates a TorchScript module that embeds a compiled NEFF. It can be saved and reloaded with torch.jit.load and is specialized to the traced input shapes and types. See AWS's trace API reference.
In legacy training code, xm.xla_device() selects an XLA device. PyTorch/XLA records operations into a graph until it reaches a boundary such as xm.mark_step() or a read of a tensor value on the host. The graph at that boundary is the unit of compilation and the input to the legacy persistent cache. AWS directs new PyTorch training on Trn2 and Trn3 to TorchNeuron and TorchTitan Neuron.
AWS announced that XLA inference support on Trn2 and Trn3 ends in Neuron 2.34. Inf2 and Trn1 XLA inference entered maintenance in Neuron 2.31 and receives critical bug and security fixes. A move to native TorchNeuron involves updating device placement and replacing the XLA-specific tracing or training calls. AWS Inf2 and Trn1 maintenance announcement
What is TorchNeuron?
TorchNeuron is the native PyTorch backend for Trn2 and Trn3, in public beta as of Neuron 2.33.1. It gives PyTorch a neuron device so you can place a model and its tensors on Trainium with ordinary PyTorch calls. It registers the device through PyTorch's PrivateUse1 extension point. Match your PyTorch 2.13 or 2.14 version to the native torch-neuronx wheel family. AWS TorchNeuron overview · TorchNeuron release notes
Hugging Face ecosystem#
On Trn2 and Trn3, upstream Transformers, Accelerate, PEFT, TRL, and Diffusers can use the native PyTorch neuron device for supported workloads. Hugging Face documents these examples.
| Workload | Where to start |
|---|---|
| Transformers inference | Pass device_map="neuron" to from_pretrained(). For supported text generation, a static KV cache keeps the attention state at a fixed shape as the sequence grows and reduces recompilation. Transformers on AWS Trainium |
| Fine-tuning and post-training | Transformers Trainer detects Neuron through Accelerate. PEFT adds support for adapter fine-tuning. The TRL recipe fine-tunes Qwen3-8B on Trainium2 with SFTTrainer, fixed input shapes, tensor parallelism, and Fully Sharded Data Parallel (FSDP). Trainer guide · TRL recipe |
| Diffusion and custom kernels | Supported Diffusers pipelines run in eager and compiled mode. AWS publishes NKI kernels for use through Hugging Face Kernels. Diffusers on Trainium · AWS Neuron kernels on the Hub |
Model and feature coverage depends on the workload and package versions. The TorchNeuron compatibility lookup lists tested Transformers inference configurations and their reproduction scripts. Optimum Neuron provides separate model wrappers and export workflows for the earlier PyTorch/XLA stack. transformers-neuronx is AWS's retired decoder library.
Eager and compiled execution#
import torch
model = torch.nn.Linear(16, 8).to("neuron")
x = torch.ones(2, 16, device="neuron")
y = model(x) # Eager
compiled = torch.compile(model, backend="neuron")
z = compiled(x) # Compiles on the first call for this signature
Eager mode dispatches PyTorch operators as Python calls them. TorchNeuron translates a supported operator into StableHLO, compiles a device executable called a NEFF on a cache miss, and queues it on the device. Opt-in Adaptive Eager Execution can fuse eligible queued operations. By default, an unsupported eager operator can fall back to CPU with a warning, incurring synchronization and data transfers. AWS eager execution guide
torch.compile uses TorchDynamo to record related PyTorch operations as a graph in PyTorch's FX format. The Neuron backend lowers each captured graph through StableHLO and neuronx-cc to a NEFF. This lets the compiler optimize across operators. Graph breaks can split capture into separate graphs. If lowering or execution fails, the backend raises by default. You can enable a fallback that reruns the original graph in eager mode, where the eager operator fallback rules apply. Different input shapes can trigger recompilation. AWS compilation guide · Compilation caches
Distributed training and custom kernels#
TorchNeuron uses standard torch.distributed APIs, including DDP, FSDP and DTensor tensor parallelism, with the neuron process group backend. For large-model pretraining, TorchTitan Neuron provides tested recipes and a compiler-friendly SimpleFSDP option. Use NKI for a custom device kernel inside an otherwise standard PyTorch model. See the distributed guide.
What is TorchTitan Neuron?
TorchTitan Neuron is the beta Neuron port of PyTorch TorchTitan for pretraining language models on Trn2 and Trn3. It runs on native TorchNeuron. Its recipes show how to split model state across workers with Fully Sharded Data Parallel (FSDP) and combine it with tensor, context, expert, or pipeline parallelism. Neuron 2.33.1 ships torchtitan 0.2.2+neuron.1 for native PyTorch 2.14. TorchTitan Neuron release notes
Why SimpleFSDP matters#
TorchTitan can run in eager mode or with torch.compile using the neuron backend. A standard FSDP2 recipe can compile each transformer block on its own and do parameter and gradient transfers between those blocks. SimpleFSDP puts those collectives inside the graph so the compiler can schedule communication alongside computation. Capturing a larger graph can increase compile time. AWS SimpleFSDP tutorial
For a documented starting point, AWS validates Llama 3 8B pretraining with TP4 × FSDP16 on a trn2.48xlarge. That configuration combines four-way tensor parallelism with sixteen-way FSDP. Older NxD Training recipes use PyTorch/XLA and their own sharding APIs. AWS validated TorchTitan configurations
What is transformers-neuronx?TNx
transformers-neuronx (TNx) was AWS's earlier library for running transformer decoders across NeuronCores. It provided tensor-parallel implementations for common model families and appears in older deployment recipes for Inf2, Trn1 and Trn2.
AWS put TNx in maintenance in Neuron 2.24 and ended support in 2.26. Its successor was NxD Inference. The migration guide covers the changes to Python model APIs, compiled artifacts, and serving settings. AWS support announcement · TNx-to-NxDI migration guide
On Trn2 and Trn3, the standalone vLLM Neuron plugin serves text and vision-language models. To run upstream Hugging Face Transformers for inference or fine-tuning from Python, use the native neuron device in TorchNeuron.
What is vLLM Neuron?
vLLM Neuron is the beta vllm-neuron plugin for serving supported language and vision-language models on Trn2 and Trn3. It exposes the standard vLLM command line, OpenAI-compatible server, and offline vllm.LLM API. Choose a model and serving options from the plugin's recipes. vLLM Neuron documentation
vllm serve "$MODEL" --tensor-parallel-size "$TP_SIZE"
Set MODEL and TP_SIZE from a recipe and include its other serving options. For example, the online quickstart uses eight tensor-parallel workers for GPT-OSS 20B. The standalone plugin detects Neuron hardware automatically. AWS online quickstart · AWS migration guide
Compilation and serving#
In Neuron 2.33 the default compilation route is neuron_native. It uses libtorch-neuronx-lite to run compiled graphs on the device. PyTorch captures the operations as an FX graph, the native backend translates it to StableHLO, and neuronx-cc produces NEFFs. Use the full torch-neuronx wheel for eager execution in a PyTorch script. AWS compilation routes · AWS native inference guide
Continuous batching lets new requests join while other requests are running. The plugin uses compiled graphs for a set of batch sizes and sequence lengths, called shape buckets. A change to the serving configuration can require compiling new buckets at warmup. Use the compiled artifact and trace caches to reuse that work across restarts. The plugin can also allocate KV cache in blocks and reuse blocks for requests with the same prompt prefix. AWS feature guide · Tensor parallelism design
Older guides may describe vLLM loading models from NxD Inference. The standalone plugin supplies its own model implementations. AWS announced that the standalone plugin's optional XLA route reaches end of support on Trn2 and Trn3 in Neuron 2.34. AWS vLLM plugin support announcement
What is vLLM Omni Neuron?
vLLM Omni Neuron is the beta vllm-omni-neuron plugin for vLLM Omni on Trn2 and Trn3. It serves diffusion and other multimodal generation models. For example, the Neuron 2.33 recipes use Wan2.2 A14B to generate video from a text prompt or an image. Run generation in Python with Omni.generate or send a request to the /v1/videos endpoint.
The 2.33 release compiles model graphs through libtorch-neuronx-lite and ships optimized NKI kernels. Depending on the model, a recipe can split attention across a long video sequence or split the variational autoencoder (VAE) across devices. Plugin release notes · Native inference guide · Model recipes
For text generation and vision understanding, see the vLLM Neuron plugin.
What is XLA on Neuron?XLA
XLA (Accelerated Linear Algebra) is a compiler stack for tensor programs used by JAX NeuronX and the legacy PyTorch/XLA build of torch-neuronx. HLO (High Level Optimizer) is how XLA represents a computation before turning it into device code. StableHLO is a related format with a compatibility contract for exchanging computations between frameworks and compilers. OpenXLA architecture · StableHLO overview
| Path | How the graph reaches Neuron |
|---|---|
| Legacy PyTorch/XLA | Traced or lazily accumulated PyTorch operations lower through XLA to HLO. xm.mark_step() is a graph boundary in lazy execution. |
| JAX | JAX traces functions such as jax.jit; the Neuron PJRT plugin connects the XLA path to Neuron. |
| Native TorchNeuron | PyTorch dispatches eager operators or captures FX graphs under torch.compile. The native backend translates those operators or graphs directly into StableHLO. |
All three routes can produce a NEFF for the Neuron Runtime. You can also invoke neuronx-cc directly on an exported XLA HLO protobuf; see the compiler CLI reference.
AWS's announced 2.34 cutoff applies to PyTorch/XLA inference on Trn2 and Trn3. JAX continues to use PJRT, and native TorchNeuron uses StableHLO as its input to the Neuron compiler in 2.33.1. AWS support announcement · TorchNeuron compilation guide
What is arithmetic intensity?
Arithmetic intensity measures how much math an operation does for each byte it moves. Choose the memory level you want to analyze, such as HBM, and count bytes crossing that boundary.
arithmetic intensity = FLOPs performed / bytes moved
Compare that number with the machine balance, the ratio of peak compute throughput to peak bandwidth for the same hardware scope. A Trainium2 chip has a published BF16 peak of 667 TFLOPS and HBM bandwidth of 2.9 TB/s, for a balance of about 230 FLOPs per byte. Use per-chip throughput with per-chip bandwidth. Several NeuronCores share a chip's HBM, so the bandwidth one core sustains depends on the workload and placement. Trainium2 specifications
In the roofline model, below the balance point bandwidth sets the upper bound. Above it, compute sets the upper bound. A real kernel can fall below both because of launch overhead, poor overlap, or limits on an individual engine.
| Operation | FLOPs | Ideal BF16 bytes moved | FLOPs per byte |
|---|---|---|---|
Element-wise add, n elements | n | 6n (two reads, one write) | 0.17 |
Layer norm, n elements | ~5n | 4n (one read, one write) | ~1.3 |
Matmul, M×K by K×N | 2MKN | 2(MK + KN + MN) | grows with operand reuse |
Decode attention, one query per head, head width d, context length L | ~4dL (two matrix-vector products) | ~4dL (keys and values) | ~1 |
These are simplified examples. They omit bias and scale reads for layer norm, and omit softmax, queries and outputs for decode attention. Sharing keys and values across query heads also changes the decode estimate.
For a square matmul of size N that reads each input once and writes its output once, intensity is N/3. If the kernel rereads tiles from HBM, the real intensity is lower. Tiling increases reuse, and fusion can keep intermediate results in SBUF. In both cases, the same math requires fewer HBM transfers.
What is a PSUM bank conflict?
A PSUM bank conflict occurs when two engines try to access the same bank of partial-sum memory at the same time and the accesses have to take turns.
On v2 through v4, PSUM holds 2 MiB across 128 partitions. Each partition contains eight banks of 2 KiB each. A bank holds 512 FP32 values.
Tile width by generation#
On NeuronCore-v3, one nc_matmul writes one PSUM bank per partition, giving a moving free-axis limit of 512 FP32 elements. On NeuronCore-v4, one destination can span all eight banks. The moving limit becomes 4,096 with FP32 output or 8,192 with BF16 output. The Tensor Engine still uses FP32 for internal accumulation. NKI nc_matmul reference
The conflict itself#
On NeuronCore-v2, the Vector and Scalar engines take turns accessing PSUM. On v3 they can access separate banks at full bandwidth in parallel. If both request bank 3 at the same time, one waits. Trainium2 NKI architecture guide
Banks and overlap#
On v3, separate banks allow the Tensor Engine to accumulate one output tile while another engine copies a completed tile to SBUF. On v4 a wider output can consume several banks, leaving less space for other accumulation groups. Little's Law explains why enough independent work has to be available to use that overlap.
A GPU shared-memory bank conflict also serializes accesses. There the contention is among threads in a warp. The v3 example here is contention between two engines.
What is NeuronCore batching?
Batching runs several inputs through a model together. A layer can reuse the same weights across inputs, doing more arithmetic for each byte loaded from HBM. This raises arithmetic intensity when weight reads dominate.
Batching during LLM decode#
At batch size one, an LLM may read the same weights for every token it generates. Processing more sequences in one step lets a kernel reuse those weights across sequences. The gain slows once compute or KV-cache traffic becomes the larger cost. The KV cache stores each sequence's past keys and values and grows with the number and length of sequences.
A larger batch can raise aggregate tokens per second while increasing queueing or per-step latency. A serving system chooses a batch size based on its throughput and latency targets.
Continuous batching#
In a fixed batch, a finished request's slot can sit idle while longer requests continue generating.
Continuous batching lets sequences join and leave a running batch between decode steps, so the scheduler can use freed slots for new requests. This is available in vLLM Neuron.
Batching and compilation#
NEFFs can be compiled for particular input shapes. A serving scheduler can vary which requests are in the batch and still select a compiled bucket for the shape it will run. For example, vLLM Neuron can bucket by the number of sequences and can optionally bucket by decode context length. Warming the relevant caches reduces cold start overhead. See the vLLM Neuron configuration reference.
In training#
Batching in training is a different question. There, batch size is a convergence parameter as much as a performance one, and it interacts with learning rate schedules. Batch size also changes the memory needed for activations.
What does compute-bound mean?
An operation is compute-bound when the rate of arithmetic sets its runtime. For example, a well-tiled matrix multiplication can reuse its inputs enough to keep the Tensor Engine busy even though it only loads each input tile from device memory occasionally.
The roofline model predicts a compute limit when arithmetic intensity exceeds the machine balance. Use the peak for the engine doing the work and the bandwidth for the memory being accessed. Large matrix multiplications, convolutions, and long-prompt prefill can hit this limit when they reuse their inputs enough.
Prefill and decode have different reuse patterns#
LLM inference often shifts from compute-bound prefill to memory-bound decode. The actual bottleneck depends on the model, prompt length, context length, batch, and implementation.
| Prefill | Decode | |
|---|---|---|
| Work | Process prompt tokens, sometimes in chunks | Generate one token per sequence per step |
| Weight reuse | Across the prompt tokens in a chunk | Across sequences in the batch |
| Common bottleneck | Compute on long prompts | Memory at small batches |
| Helped by | Faster matmul, sparsity | Quantization, batching |
With disaggregated inference, separate worker pools handle prefill and decode. The prefill worker passes the KV cache, which holds attention keys and values for the prompt, to the decode worker. The serving system can size each pool independently. See the vLLM Neuron disaggregation tutorial for supported configurations.
When arithmetic sets the limit#
- Use a supported lower-precision format. FP8 matmul can reach about twice the per-engine BF16 peak on NeuronCore-v3. MXFP8 can reach about four times the per-engine BF16 peak on NeuronCore-v4.
- Use structured sparsity if your model meets a supported zero pattern and your kernel selects the sparse matmul path. Speedups depend on generation and data type.
- Check tile geometry. A kernel limited by arithmetic can still fall short of the published peak if it leaves part of the array idle.
Use Neuron Explorer to see which engine is busy. A normalization kernel can saturate the Vector Engine while leaving the Tensor Engine idle. The Tensor Engine's peak is then a poor baseline for that kernel.
What is data parallelism on Neuron?DP
Data parallelism (DP) trains replicas of the same model on different examples from a batch. Each worker process (a rank) computes its own gradients. In PyTorch DistributedDataParallel (DDP), all-reduce synchronizes the gradients so every replica makes the same update.
DP can span instances in an UltraCluster. With ordinary DDP, each replica still needs room for its model, gradients, optimizer state, and activations. A mixed-precision Adam setup with BF16 parameters and gradients, FP32 master weights, and two FP32 moment buffers needs about 16 bytes per parameter before activations. For a 70B-parameter model that is roughly 1.1 TB per replica, well beyond the 96 GiB of one Trainium2 chip.
Sharding the replicated state#
ZeRO-1 shards the optimizer state across data-parallel ranks. It was available in legacy NxD Training.
For native Trainium training, TorchNeuron supports standard PyTorch DDP and FSDP2. The FSDP2 path in TorchTitan Neuron shards parameters, gradients, and optimizer state. It gathers parameters for computation and reduce-scatters the gradients. See the TorchTitan support matrix.
Overlapping the all-reduce#
DDP groups gradients into buckets and can start reducing a bucket as soon as its gradients are ready. Backpropagation can continue on layers whose gradients are still being computed. Neuron's dedicated collective communication cores can run those reductions alongside compute. The tail of the final collective still counts toward step time if backward finishes first. See latency hiding and nccom-test.
What is engine parallelism?
Engine parallelism means overlapping work on separate NeuronCore engines. Each engine has its own instruction stream. A matmul can run while another engine processes a result from a previous tile, provided the two operations have independent data to work on.
Here are the compute engines on NeuronCore-v3.
| Engine | Peak or configuration | Work |
|---|---|---|
| Tensor | 79 BF16 TFLOPS | matmul, convolution |
| Vector | 1.0 FP32 TFLOPS | reductions, normalization |
| Scalar | 1.2 FP32 TFLOPS | activations, exp |
| GpSimd | 8 × 512-bit | general-purpose SIMD operations |
Plus the Sync Engine and DMA engines, which also run concurrently.
Overlapping tiles#
In a well-pipelined matmul chain, at any instant:
- The Tensor Engine computes tile
ninto PSUM. - The Vector or Scalar Engine drains tile
n-1from PSUM to SBUF, applying the activation on the way. - DMA engines fetch tile
n+1from HBM.
Keeping several tiles in flight can hide the cost of loading inputs and copying completed results. Each stage still needs enough buffer space and memory bandwidth to keep pace.
Synchronization#
The compiler inserts hardware synchronization based on the dependencies it sees. When every step needs the full result of the previous one, the engines have to wait. Working in tiles can let one engine process tile n-1 as another computes tile n.
What limits it#
Some engine pairs contend for memory ports, and the rules changed between generations:
| Restriction | v2 | v3 |
|---|---|---|
| Vector + GpSimd on SBUF | serialized | can overlap |
| Vector + Scalar on PSUM | serialized | can overlap on different banks |
The Vector Engine's performance mode also shares a memory bus with GpSimd. Hardware arbitrates when they both request it. Trainium2 NKI architecture guide
Neuron Explorer shows a timeline per engine. Use it to see which work overlaps and where an engine sits idle. A core-level utilization figure from neuron-top cannot show that.
What is operator fusion?
Fusion combines several operators into one so that intermediate results stay in on-chip memory instead of round-tripping to HBM.
Fusion can speed up memory-bound work by eliminating reads and writes at the boundary between operators.
Consider y = gelu(x @ w + b), unfused:
1. matmul: read x and w from HBM → write matmul result to HBM
2. bias: read matmul result, b → write biased result to HBM
3. gelu: read biased result → write y to HBM
The matmul and bias results each make a round trip through HBM. A fused version can keep both results on the chip:
1. read x, w, b from HBM into SBUF
2. matmul on the Tensor Engine → PSUM
3. bias + gelu on Scalar/Vector → SBUF
4. write y to HBM
The fused version does the same math with fewer HBM transfers, so its HBM arithmetic intensity is higher. Neuron's scratchpads are software-managed. The kernel or compiler must plan to reuse an intermediate on chip.
Fusion also maps naturally onto the hardware, because a NeuronCore's engines are specialized and independent. A fused matmul-plus-activation puts the matmul on the Tensor Engine and the activation on the Scalar Engine, where the Scalar Engine can process one tile while the Tensor Engine works on the next. That overlap is an example of engine parallelism.
Who does it#
neuronx-cc can fuse common patterns when the operators appear in the same compiled graph. You can also fuse them explicitly in an NKI kernel. FlashAttention, for example, computes attention in tiles and keeps intermediate scores on chip, avoiding a full attention matrix in HBM. NKI performance guide
The limit#
Fusion changes which buffers have to be live at the same time. If they exceed SBUF capacity, the compiled kernel may spill data back to HBM. Smaller tiles can help fit a fused operation, though they can also reduce reuse. Compare HBM traffic and execution time in Neuron Explorer.
What is latency hiding on Neuron?
Latency hiding keeps an engine busy with independent work while another operation is in progress. For example, the Tensor Engine can compute one tile while a DMA engine loads the next.
The target shape is a software pipeline:
DMA: load tile n+1 ────────────►
Tensor: compute tile n ───────────►
DMA: store tile n-1 ───────────►
This pipeline keeps the Tensor Engine busy if tile n+1 finishes loading into SBUF before compute needs it.
A GPU can switch to another ready warp while one waits for data. On Neuron, overlap between compute and data movement comes from the schedules produced by the compiler or from independent work you arrange in an NKI kernel.
The hardware that helps#
- DMA engines run in parallel with compute. 128 of them on Trainium2, about 16 per NeuronCore-v3.
- The Sync Engine exists to trigger DMAs without injecting instructions into a compute engine's stream.
- The DGE generates descriptors independently. This can reduce the work the issuing engine spends preparing a transfer.
- CC-Cores do the same for collectives, overlapping communication with computation.
What you do#
Expose independent work. Use Python range() for statically unrolled tile loops in current NKI. Organize loads and compute so there is independent work for the scheduler to overlap. Use nl.fori_loop or nl.while_loop for device-side loops when the bounds depend on runtime values. See nki.language and the NKI optimization guide.
Double-buffer. Size tiles so that two fit in SBUF alongside the other live data. One buffer feeds compute while DMA fills the other.
Watch the profile. Gaps on the Tensor Engine timeline in Neuron Explorer, with DMA activity in the gaps, can indicate that loads are on the critical path.
Overlapping collectives#
The same idea applies to distributed training. Gradient buckets can be reduced as they become ready while the rest of the backward pass continues. How much time this saves depends on when the communication starts and when the result is needed. See data parallelism.
What is Little's Law?
Little's Law relates how much work is in a system to how fast work completes and how long each item spends there. In steady state:
average work in flight = throughput × average time in the system
To plan a pipeline, use the target throughput and an estimate of latency to size the work in flight. The required concurrency can be higher once transfers queue or compete for bandwidth. Neuron's compiler or NKI kernel has to expose enough independent work for the engines to overlap.
DMA example#
Suppose a DMA transfer from HBM to SBUF takes 2 μs on average and the throughput target is 2 TB/s across a chip. In this example, you need about 4 MB of data in flight across the chip. For equal transfers of 256 KiB, that is about 16 outstanding transfers.
A Trainium2 chip provides 128 DMA engines for local and cross-device transfers. If a kernel loads one tile, waits, computes, and then issues the next load, the transfers never overlap even if spare DMA engines are available. Trainium2 NKI architecture guide
Tensor Engine example#
The Tensor Engine is deeply pipelined, so several LoadStationary/MultiplyMoving pairs are in flight at once. This is why AWS advises reasoning about a matmul's initiation interval rather than the end-to-end latency of a single instruction — the latency is already hidden, provided you supply enough independent work.
PSUM has eight banks per partition. On NeuronCore-v3, each nc_matmul output fits within one bank, leaving the other banks for independent accumulation groups. On NeuronCore-v4, a wide output can span all eight banks. The room available for interleaving accumulation groups depends on output width and data type.
Using it#
In a profile, look for gaps between engine instructions or long periods spent waiting for dependencies. To increase useful work in flight:
- Double-buffer. Use one tile buffer for compute while DMA fills the other.
- Expose independent work. Use separate buffers for transfers and computation that can overlap. In NKI 0.7, small loops with known bounds can use Python
rangeand unroll at specialization time. NKI loop guide - Leave PSUM banks free. A wide accumulation group can occupy all eight banks, leaving no bank for a second group.
This term is the Neuron counterpart of Little's Law in Modal's GPU Glossary, where the same law explains warp occupancy instead of pipeline depth.
What does memory-bound mean?
An operation is memory-bound when the rate of data transfer sets its runtime. Element-wise operations often fall into this category because they read and write many values for a small amount of arithmetic.
In the roofline model, this is the region where bandwidth caps throughput. Which memory matters depends on where the data moves. An operation can be limited by HBM or by a path into an on-chip scratchpad.
LLM decoding at batch size one#
In a batch-1 dense decode step, a weight streamed from HBM typically contributes one multiply-accumulate. BF16 stores it in two bytes, so the weight-only arithmetic intensity is roughly 1 FLOP per byte. KV-cache reads and other traffic also take bandwidth.
If each step reads all the weights from HBM, this gives a weight-only upper bound at batch size one.
tokens/sec ≤ HBM bandwidth / bytes of model weights
An 8B model in BF16 has about 16 GB of weights, which fit in a Trainium2 chip's 96 GiB of HBM. With the full chip bandwidth of 2.9 TB/s, the weight-only ceiling is about 180 tokens/s. That estimate excludes KV-cache traffic, compute, and communication. See the Trn2 architecture specifications.
What actually helps#
Quantize. Storing weights in fewer bytes can raise the bandwidth ceiling. Actual savings depend on the format, scale metadata, and which weights are quantized. See FP8 and MX formats.
Batch. Reading the weights once and using them for many sequences amortizes the traffic, raising intensity roughly linearly with batch size. This is the idea behind batching.
Fuse. Keep intermediates in SBUF rather than round-tripping them to HBM between operators.
Use more chips. Tensor parallelism can read shards in parallel across physical chips. Effective bandwidth depends on rank placement, shard balance, and communication overhead.
Reuse tiles. Tiling can reduce how often the same inputs cross the HBM boundary. Leave enough scratchpad space for both the tile and the rest of the pipeline.
A faster Tensor Engine helps only if arithmetic is taking time on the critical path. Measure the relevant bytes and bandwidth before tuning matmul throughput.
What is model FLOPs utilization?MFU
Model FLOPs utilization (MFU) compares the rate of useful model arithmetic with the hardware's theoretical peak rate.
MFU = useful model FLOPs per second / peak FLOPs per second
For dense transformer training, a common starting estimate of useful work is 6 × parameter count × token count per step. The approximation captures the main weight-matrix operations. The exact count depends on the architecture, sequence length, and which weights are active. Padding and activation recomputation add hardware work without increasing the model FLOPs in that estimate.
Compare runs using the same counting convention. Report the device count, precision, and which portion of the run you timed. For small-batch LLM decode, weight or KV-cache traffic can dominate. Pair MFU with tokens per second and measured HBM bandwidth utilization to see where time goes. Neuron Explorer metric definitions
Which peak to divide by#
On Neuron this needs care, because "peak" depends on precision:
| Trainium2 | Peak per chip |
|---|---|
| FP8 | 1,299 TFLOPS |
| BF16/FP16/TF32 | 667 TFLOPS |
| FP32 | 181 TFLOPS |
| Sparse FP8/FP16/BF16/TF32 | 2,563 TFLOPS |
Divide by the peak for the precision and mode used by the workload, using the total peak of the chips included in the measurement. A dense BF16 run should use the dense BF16 peak. Mixed-precision comparisons should say how the denominator was chosen.
Raising it#
The levers are the ones in this section, and which applies depends on the roofline:
- Engine parallelism — overlap independent work on the engines your kernel uses.
- Latency hiding — overlap DMA with compute.
- Fusion — remove HBM round trips.
- Tile geometry — fill the Tensor Engine array while leaving enough scratchpad space to overlap work.
- Overlapped collectives — launch gradient reductions as buckets become ready.
A profile in Neuron Explorer can show whether the job spends time on arithmetic, transfers, or waiting for other ranks.
What is NeuronCore Pipeline?
NeuronCore Pipeline is an Inf1 inference feature. The compiler splits a model into consecutive groups of layers. Each group runs on a NeuronCore with its weights held in on-chip memory, and requests pass from one group to the next.
Keeping the weights on chip avoids fetching them from device DRAM for every request. NeuronLink-v1 carries activations when stages span devices. An inf1.24xlarge has 16 Inferentia chips and 64 NeuronCores. AWS gives BERT and ResNet-50 as examples that can benefit without large batches.
The legacy neuron-cc compiler enables it with:
--neuroncore-pipeline-cores N
Benchmark core counts that fit the model and compare throughput and latency. See the AWS NeuronCore Pipeline reference.
Modern Trainium serving typically stores weights in HBM and stages smaller tiles through SBUF. Tensor parallelism splits the work inside a layer. Pipeline parallelism also splits by layer and can run with weights in device memory.
What is overhead on Neuron?
Overhead is time and work spent preparing or dispatching computation. On Neuron, it includes host dispatch, first-use compilation, synchronization, and transfers. A profile separates these from time spent compute-bound or memory-bound on the device.
Dispatch, compilation, and graph breaks#
Eager dispatch. TorchNeuron can dispatch an ATen operator at a time. A new operator specialization can trigger compilation before it executes. Unsupported eager operators may run on the CPU, adding device transfers and synchronization. Experimental adaptive eager mode can fuse eligible queued operations. It is off by default in Neuron 2.33.
Compiled execution. torch.compile(backend="neuron") lets the compiler compile each captured graph as a NEFF. This gives the compiler room to fuse operators and schedule their data transfers, with fewer host dispatches. Dynamo graph breaks split the work into separately compiled segments. Legacy PyTorch NeuronX lazy execution has a separate mechanism for materializing pending work.
Cold or repeated compilation. A new shape, dtype, compiler setting, or failed graph guard can require a new specialization. A guard is a condition PyTorch checks before reusing a captured graph. Check cache hits and account for warmup separately when measuring steady state. Serving stacks often use fixed buckets for this reason.
Transfers and synchronization#
Host-to-device movement. Moving inputs from host DRAM to device HBM can stall a job whose data pipeline cannot keep up. Use neuron-ls to check device and NUMA placement. Printing an eager device tensor also incurs a synchronization and host copy.
Collectives on the critical path. Reducing gradients after backward adds the uncovered collective time to each step. Neuron's dedicated CC-Cores can communicate while compute engines work when dependencies allow it. See latency hiding.
Neuron Explorer correlates device and system activity. Look at host dispatch and compilation around device idle gaps, as well as DMA and collectives before a stalled compute engine.
See AWS's TorchNeuron compile guide and eager execution overview.
What is peak rate?
A peak rate is a theoretical throughput limit under specified conditions. The compute peak is the flat part of a roofline and the denominator in model FLOPs utilization. Published peaks assume full use of the relevant hardware, with no stalls. A benchmark measures the rate a particular workload sustains.
Compute peaks by chip and engine#
Per Trainium2 chip:
| Precision | Peak |
|---|---|
| Sparse FP8/FP16/BF16/TF32 | 2,563 TFLOPS |
| Dense FP8 | 1,299 TFLOPS |
| BF16 / FP16 / TF32 | 667 TFLOPS |
| FP32 | 181 TFLOPS |
Per NeuronCore-v3, by engine:
AWS publishes chip and engine figures separately. Use the chip figures for a chip-level estimate. Use the Vector Engine's peak, for example, if it does the arithmetic you are measuring. Trainium2 chip specifications and Trainium2 engine specifications.
Bandwidth peaks#
The Trainium2 chip overview reports 2.9 TB/s of HBM bandwidth and 3.5 TB/s of DMA bandwidth. DMA can move data on and off the chip. A transfer that reads local HBM is also subject to the HBM limit. Cross-chip transfers depend on which NeuronLink path they use.
When reporting a percentage of peak, state the precision, whether the peak is dense or sparse, and the scope (engine, chip, or multiple chips). Dividing peak compute by peak bandwidth for a matching scope gives the machine balance.
What is pipeline parallelism on Neuron?PP
Pipeline parallelism (PP) assigns different groups of layers to different devices. Each group is a stage. Stages send activations forward and gradients backward during training. A stage can also use tensor parallelism to split its layer computations across devices.
The pipeline bubble#
A stage waits for the previous stage to produce its input. Splitting a batch into smaller microbatches lets stage 1 begin the next one while stage 2 works on the current one. The bubble is time that stages spend idle while the pipeline fills, drains, or waits for a slower stage.
For one fill-and-drain pass with equally fast stages, the idle fraction is (stages - 1) / (microbatches + stages - 1). More microbatches can reduce this overhead, though scheduling and activation memory still matter. In autoregressive inference, each sequence's next token depends on its last token. Serving multiple independent sequences provides more work to pipeline.
Combining strategies#
A training job can combine several strategies. The communication pattern helps decide where to place each group.
| Strategy | Communicates | Typical placement |
|---|---|---|
| Tensor | within layers | within a fast NeuronLink domain |
| Context | within attention | within a fast NeuronLink domain |
| Pipeline | at stage boundaries | within or across instances |
| Data | gradient synchronization | across instances |
On Trn2 and Trn3, TorchNeuron supports torch.distributed.pipelining. AWS's setup guide requires EFA/RDMA for stage-to-stage communication, including for a pipeline on a single node. TorchNeuron distributed training guide
What is the roofline model?
The roofline model estimates the speed an operation could reach given the available compute throughput and memory bandwidth. Plot arithmetic intensity on the x-axis and FLOPs per second on the y-axis.
throughput ceiling = min(peak compute throughput,
arithmetic intensity × peak memory bandwidth)
The slanted part of the chart is the bandwidth limit. The flat part is the compute limit. The two meet at the machine balance.
Numbers for Trainium2#
For a Trainium2 chip against HBM at 2.9 TB/s:
| Precision | Peak | Machine balance |
|---|---|---|
| BF16 | 667 TFLOPS | ~230 FLOPs/byte |
| FP8 | 1,299 TFLOPS | ~448 FLOPs/byte |
| FP32 | 181 TFLOPS | ~62 FLOPs/byte |
At a given precision, the lower of the two ceilings predicts the bottleneck if the operation can reach that ceiling. Switching to FP8 raises the compute ceiling. It can also change the operation's intensity, since it can take fewer bytes to store the inputs. Trainium2 published chip peaks
Choose the relevant rates#
Pick the peak for the engine doing the work. On NeuronCore-v3, the Tensor Engine peaks at 79 BF16 TFLOPS. The Vector Engine peaks at 1.0 FP32 TFLOPS. A reduction running on the Vector Engine has a different ceiling from a Tensor Engine matmul.
Pick the bandwidth for the data path you measured. A kernel that works in SBUF after loading its inputs has a different bandwidth limit from one that continually fetches from HBM. See peak rate.
Using it#
Measure the achieved throughput, estimate the intensity for the chosen data path, and plot the point.
- Near the slanted line: reduce bytes moved with tiling, fusion, or quantization.
- Near the flat line: look for ways to do less work or use a faster supported format.
- Below either limit: profile the operation in Neuron Explorer. Idle engine time can come from poor overlap, synchronization, or unexpected spills.
What is spilling on Neuron?
Spilling moves a value out of fast memory to make room for other work. A reload brings it back when the kernel needs it. The Neuron compiler can insert these transfers, such as saving an intermediate from SBUF to HBM and reading it back.
The program still computes the same result, but the extra transfers may show up as unexpected DMA activity. In Neuron Explorer, compare Spill Save Bytes and Spill Reload Bytes with overall SBUF traffic. NKI guide to spill metrics
The budgets#
| Memory | Capacity | Per partition |
|---|---|---|
| SBUF, v2 | 24 MiB | 192 KiB |
| SBUF, v3 | 28 MiB | 224 KiB |
| SBUF, v4 | 32 MiB | 256 KiB |
| PSUM, v2–v4 | 2 MiB | 16 KiB |
The Tensor Engine writes its results to PSUM. Copy completed results to SBUF so the next matmul has space to accumulate.
Reducing spills#
Count all buffers that must fit at once. If you double-buffer inputs to overlap loads and compute, each input needs two buffers. Fusion can avoid HBM traffic between operators, but the fused operation may also need space for more live intermediates. Adjust the tile size and compare the profile again.
What is tensor parallelism on Neuron?TP
Tensor parallelism (TP) splits computations within a layer across several logical NeuronCores. Each rank (worker process) computes on its slice of the weights. A collective combines or redistributes the results.
For example, a feed-forward block's first linear layer can be column-parallel, giving each rank a slice of the output features. A row-parallel second layer consumes the sharded features and produces partial outputs. An all-reduce combines them when every rank needs the full result. With sequence parallelism, a reduce-scatter can leave the result sharded. Attention commonly shards by head.
What TP buys#
TP can fit a model whose weights and KV cache exceed the memory of one chip. Spreading weight shards across chips also lets those chips read their local HBM in parallel. The bandwidth gain depends on the physical chips used, the balance of the shards, and the cost of the collectives between ranks.
On a Trn2 instance with LNC=2, each chip has four logical cores. A TP group of 16 ranks can occupy four chips if placement uses four ranks per chip. Check the device map to see which chips supply bandwidth.
Choosing the degree and placing ranks#
- Count the available logical cores with Logical NeuronCore configuration and the device allocation in mind. A full
trn2.48xlargeexposes 64 logical cores atLNC=2. - Check model and backend constraints. The number of attention heads, KV heads, and intermediate dimensions can constrain valid sharding. Some implementations replicate KV heads at higher TP degrees.
- Benchmark valid degrees that fit the model and KV cache. More ranks give each rank less work and add communication. In vLLM Neuron, TP trades off with other strategies such as data parallelism.
- Keep frequently communicating ranks in a fast NeuronLink domain where possible. A Trn2 UltraServer links instance members over NeuronLink, and a Trn3 UltraServer uses NeuronSwitch and direct links inside its scale-up domain. Neuron DRA can allocate topology-aware groups on eligible EKS clusters.
See AWS's vLLM Neuron tensor parallelism design for worked examples of attention, MLP sharding, and KV-head replication.