This document is relevant for: Trn3

What is TorchAO Neuron?#

This topic covers TorchAO Neuron and how it applies to low-precision training with the AWS Neuron SDK. TorchAO is the PyTorch-native library for quantized training and inference. TorchAO Neuron is the Neuron fork of TorchAO. It adds Trainium-specific support for AO’s MXFP8 quantization and matrix multiplication interfaces. In addition, the fork adds new performance-optimized code paths which differ from the upstream implementations by fusing quantization and matrix multiplication. TorchTitan Neuron uses these features for MXFP8 training on top of TorchNeuron, the native PyTorch backend.

Applies to#

This concept is applicable to:

  • Trn3 instances.

  • MXFP8 training with TorchTitan Neuron.

Requirements#

Component

Required version

Instance types

Trn3

Neuron SDK

2.34

PyTorch

2.14.0

torch-neuronx

2.14.3.1

torchtitan-neuron

0.2.2+neuron.2, for the MXFP8 training recipes

Supported configurations#

TorchAO Neuron supports the following MXFP8 configurations on dense nn.Linear layers, in eager mode and under torch.compile with backend="neuron". Quantizing MoE expert weights is available through TorchTitan Neuron.

  • ``MXFP8Linear`` — TorchAO’s MXFP8 linear, running on Neuron through the quantize_mx custom operator and aten::_scaled_mm pytorch core operator. Quantization and the matmul stay separate operations, so the layer keeps upstream TorchAO semantics.

  • Fused MXFP8 linear (neuron_fused_mx_linear) — an autograd function that runs quantization and the scaled matmul as one Neuron custom operation. Its kernel configuration arguments select:

    • NKI kernel lowering (default) — forward and backward run the matmul_mxfp8 NKI kernels, which also accept a quantization layout and a tuned-config file.

    • MLIR custom operator lowering — the forward and backward run the neuronx-cc custom op instead, and takes none of the NKI configuration arguments.

  • Pre-quantized weights — a separate workflow, not part of the fused autograd function. Quantize a weight once and reuse the encoding across matmuls, so a distributed gather moves FP8 instead of bf16. It is exposed as the neuron::quantize_mx_nki and neuron::prequantized_mx_scaled_mm_nki custom operators, for callers that supply their own autograd function.

How TorchAO Neuron works#

TorchAO Neuron is a thin PyTorch layer over three backends: NKI Library kernels (NKI lowering), Neuron compiler custom ops (MLIR lowering), and TorchNeuron ops (quantize_mx, aten::_scaled_mm). TorchTitan Neuron recipes show how to use it in training.”

Quantization layouts#

MXFP8 groups elements along the contraction dimension and stores one scale per group. The NKI lowering supports two layouts, 1x32 (the default) and wrapX. They differ in how a group is formed and in which NeuronCore engine rearranges the operand into the layout the matmul expects. 1x32 is the only layout the pre-quantized weight path supports.

For how the layout choice interacts with kernel selection and performance, and how to tune it, see Tutorial: Auto-tune MXFP8 kernel configs for TorchTitan Neuron training.

Further reading#

This document is relevant for: Trn3