This document is relevant for: Trn2, Trn3
What is TorchTitan Neuron?#
This topic covers TorchTitan Neuron and how it applies to pre-training with
the AWS Neuron SDK. TorchTitan is a PyTorch-native library for pre-training
large models. On Trainium it runs on TorchNeuron, the native PyTorch
backend for Neuron, so you can use TorchTitan’s standard model definitions,
parallelism strategies, and torch.compile integration without changing
your model code.
TorchTitan expresses every parallelism strategy with standard PyTorch building
blocks: DeviceMesh, DTensor, fully_shard (FSDP2), and
torch.distributed collectives. TorchNeuron registers a neuron device and
a neuron process-group backend that implement these APIs. When you add
--compile.enable --compile.backend neuron, TorchTitan’s compiled regions
are lowered by the Neuron compiler. Large-model pre-training on Trainium
therefore stays inside the PyTorch-native stack, with no separate framework or
graph-tracing layer to adopt.
Applies to#
This concept is applicable to:
Pre-training workloads on Trn2 and Trn3 instances using TorchTitan.
Distributed training using TorchTitan’s built-in parallelism strategies on top of TorchNeuron’s
torch.distributedsupport.
Support matrix#
Component |
Supported version or value |
|---|---|
Neuron SDK |
2.34.0 (TorchNeuron public beta) |
PyTorch |
2.14.0 |
|
2.14.3.1 package family |
Python |
3.12, 3.13, 3.14 (Linux x86_64) |
TorchTitan |
Use aws-neuron/torchtitan-neuron, the Neuron fork of upstream |
Instance types |
Trn2 and Trn3. Most TorchTitan tutorials use a single |
Execution modes |
Eager, and |
Strategy |
Status |
Notes |
|---|---|---|
FSDP2 ( |
Supported |
Default TorchTitan data-parallel sharding
( |
SimpleFSDP |
Supported with |
Compiler-friendly FSDP for |
Tensor parallel (TP) |
Supported |
DTensor |
Context parallel (CP) |
Supported |
Ring attention for sequence-sharded SDPA, forward and backward. |
Expert parallel (EP) |
Supported |
Uneven |
Pipeline parallel (PP) |
Supported |
The Neuron backend implements point-to-point |
DDP |
Supported |
Standard |
Activation checkpointing |
Supported |
|
How TorchTitan works on Neuron#
TorchTitan is a layer on top of the native PyTorch backend. It does not use
PyTorch/XLA, and it doesn’t trace your model into a separate graph framework.
Model code, parallelism plans, the optimizer, and checkpointing are ordinary
PyTorch running on the neuron device.
┌──────────────────────────────────────────────────────────────┐
│ TorchTitan │
│ models (Llama3, Qwen3, DeepSeek-V3, GPT-OSS, ...) │
│ parallelize: FSDP2 / SimpleFSDP, TP, CP, EP, AC │
│ train loop, optimizer, checkpoint, metrics │
├──────────────────────────────────────────────────────────────┤
│ PyTorch 2.14 │
│ DeviceMesh · DTensor · fully_shard · torch.distributed │
│ torch.compile (Dynamo + AOTAutograd) │
├──────────────────────────────────────────────────────────────┤
│ TorchNeuron (torch-neuronx) │
│ "neuron" device (PrivateUse1) "neuron" process group │
│ eager ATen dispatch DTensor sharding rules │
│ torch.compile backend="neuron" NKI kernels (SDPA, ...) │
├──────────────────────────────────────────────────────────────┤
│ Neuron compiler (neuronx-cc) · Neuron runtime · collectives │
├──────────────────────────────────────────────────────────────┤
│ Trainium (Trn2 / Trn3) NeuronCores │
└──────────────────────────────────────────────────────────────┘
A training run goes through four layers:
Process and device setup.
torchrunstarts one process per NeuronCore. SetNEURON_RT_NUM_CORESand--nproc_per_nodeto the same value. TorchNeuron registers theneuronbackend forinit_process_groupand assigns each rank its NeuronCore fromLOCAL_RANK.Parallelism. TorchTitan builds a
DeviceMeshand applies its parallelism plan with DTensor andfully_shard. TorchNeuron records every mesh’s replica groups when the mesh is created, which SPMD compilation depends on. It also supplies sharding rules for attention and linear layers so that DTensor operations stay sharded on the device.Execution. Without
--compile.enable, every operation runs in eager mode. Each ATen op is compiled to a Neuron executable on first use and then cached. With--compile.enable --compile.backend neuron, TorchTitan wraps part of the model intorch.compile, and those regions are compiled by the Neuron compiler instead:Stock models with FSDP2: each
TransformerBlockis compiled separately withfullgraph=True. FSDP2’s parameter all-gather and gradient reduce-scatter run as eager collectives between the compiled blocks.SimpleFSDP: the whole model is compiled as one
fullgraph=Truegraph. The FSDP collectives are inside the graph, so the compiler can schedule communication together with compute. This is why SimpleFSDP is the recommended FSDP choice withtorch.compile.
Caching. Compiled executables are stored in a persistent cache keyed by the workload, the target, the logical NeuronCore (LNC) configuration, the compiler version, and the compiler options. The first step of a run can take several minutes to compile. Later steps, and later runs with the same configuration, reuse the cache.
Supported models#
TorchTitan’s model families run on TorchNeuron through the same model definitions used on other hardware. The following configurations have tutorials in the torchtitan-neuron repository:
Model |
Workload |
Validated configuration |
|---|---|---|
Llama3-8B |
Pre-training |
TP4 × FSDP16 on one |
Llama3-70B |
Pre-training |
TP4 × FSDP64 on four nodes, full activation checkpointing. Eager,
|
Qwen3-32B (dense) |
Pre-training |
TP4 × FSDP16, full activation checkpointing. Eager, |
Qwen3-8B (dense) |
Pre-training |
MXFP8 |
Qwen3-30B-A3B (MoE) |
Pre-training |
TP4 × FSDP16, stock |
Qwen3-235B-A22B (MoE) |
Pre-training |
All 94 layers on a four-node Trn3 UltraServer: EP128 × TP4 × FSDP64,
full activation checkpointing, |
DeepSeek-V3-16B (MoE) |
Pre-training |
Mixture of experts (MoE) with multi-head latent attention. TP4 × FSDP16,
stock |
GPT-OSS-20B (MoE) |
Pre-training |
MoE with grouped experts. TP4 × FSDP16, stock |
Qwen3-8B |
Inference |
Hugging Face |
The stock grouped_mm recipes run TorchTitan’s own MoE code on the
TorchNeuron dynamic NKI kernels, so upstream MoE models train without
Neuron-specific model changes. They also use TorchTitan’s own attention:
FlexAttention with document masking for Qwen3-30B-A3B and DeepSeek-V3-16B, and
varlen attention with attention sinks and a 128-token sliding window for
GPT-OSS-20B. Each model also has a fused-combine eager recipe
(*_stock_gmm_fused_combine_tp4_fsdp16) that runs the MoE combine as one NKI
kernel. The NKI blockwise MoE recipes are still available for advanced use. See
torchtitan_neuron/docs/moe-tutorials.md.
MXFP8 on Trn3 applies to Linear layers and to the NKI MoE kernels.
Other TorchTitan models use the same building blocks and are expected to run, but they do not have a validated TorchNeuron configuration.
Distributed strategies#
TorchTitan composes its parallelism strategies on a multi-dimensional
DeviceMesh. Each rank of the mesh is one process, and each process owns one
logical NeuronCore. On a trn2.48xlarge with the default LNC=2, that is 64
ranks per node: 16 Trainium2 devices with 4 logical cores each.
FSDP2 and SimpleFSDP. Both shard parameters, gradients, and optimizer state
across the data-parallel shard dimension. FSDP2 (fully_shard) uses runtime
hooks around each module and works in eager mode and with per-block
compilation. SimpleFSDP expresses sharding as DTensor parametrizations, so the
all-gather and reduce-scatter are traced into the compiled graph. Use
SimpleFSDP when you combine FSDP with torch.compile.
Tensor parallelism (DTensor). TP shards attention heads and MLP projections. TorchNeuron provides DTensor sharding strategies for scaled dot-product attention (replicated, head-sharded, batch-sharded, and sequence-sharded) and for linear forward and backward, so a TP plan stays sharded through attention.
Context parallelism. Sequence-sharded attention runs as ring attention. By default, TorchNeuron uses a fused NKI ring-attention kernel that drives the whole ring inside one kernel, and falls back to PyTorch’s templated ring otherwise.
Expert parallelism. MoE token dispatch uses all_to_all_single with
uneven split sizes. TorchNeuron implements this as a native NKI all-to-all-v
collective that sends exactly the requested per-rank counts without dynamic
shapes. Set NEURON_USE_NKI_ALLTOALLV=0 to use the padding-based fallback.
The MoE combine (weighting the expert outputs by their routing scores and
scattering them back to the token positions) also has a fused NKI kernel:
the stock fused-combine recipes
(qwen3_30b_a3b_stock_gmm_fused_combine_tp4_fsdp16,
deepseek_v3_16b_stock_gmm_fused_combine_tp4_fsdp16, and
gpt_oss_20b_stock_gmm_fused_combine_tp4_fsdp16) run it through
NeuronTokenDispatcher in eager mode with EP=1. Other configurations use the
stock TorchTitan combine. The Qwen3 EP recipes use the Neuron EP backend
(neuron_ep) instead, which runs on Trn3; see How to use EP to train a model with TorchTitan on Neuron.
Mapping onto NeuronCores. Collective cost depends on where the ranks of a group sit. Ranks on the same Trainium device communicate fastest, then ranks on the same node, then ranks across nodes. Put the most communication-heavy dimension on the innermost mesh dimension:
TP communicates in every layer, so keep each TP group on one device. For example, TP=4 matches the 4 logical NeuronCores of a Trainium2 device at LNC=2.
FSDP communicates once per layer or per step and can span devices and nodes.
--parallelism.data-parallel-shard-degree -1uses all remaining ranks.
trn2.48xlarge, 64 ranks, TP=4 × FSDP=16
device 0 device 1 device 15
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ r0 r1 r2 r3 │ │ r4 r5 r6 r7 │ ... │ r60 r61 r62 r63 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
TP group 0 TP group 1 TP group 15
└────────────── FSDP shards across the 16 TP groups ──────────────┘
The LNC setting changes the number of ranks per node and is part of the compilation cache key, so changing it triggers a recompile.
Known limitations#
The following limitations are specific to running TorchTitan on Neuron. For
general TorchNeuron constraints (operator coverage, data types, and
torch.compile parameters), see the TorchNeuron API compatibility guide.
Static shapes only.
torch.compileon Neuron requires static shapes. Keep--training.seq-lenand--training.local-batch-sizefixed for a run. Each new input shape triggers a new compilation.Long first step. The first training step compiles every graph and can take several minutes. Throughput is steady after that. The persistent NEFF cache avoids paying this cost again on later runs.
Compile mode. Only
mode="default"is supported. TorchTitan’s default is compatible.Forced graph breaks under
fullgraph=True. TorchTitan compiles withfullgraph=True. TorchNeuron forces a graph break on operations Neuron can’t lower in a compiled graph, and underfullgraph=Trueeach of those becomes an error. This affects:torch._grouped_mm/grouped_mm, used by MoE grouped experts, when a call cannot run on the ragged NKI kernels inside the graph (bfloat16orfloat16inputs, static shapes, nobias, kernel shape constraints). The dynamic NKI kernels are on by default. WithTORCH_NEURONX_USE_DYNAMIC_NKI_KERNELS=0every call forces a graph break, unlessTORCH_NEURONX_USE_TILED_GROUPED_MM_KERNELS=1is also set; a call that breaks runs on Neuron in eager mode.sort,argsort, andtopk, only when neither the compiler TopK nor the TorchNeuron device sort can serve the call: a floating-pointsortover more than 16,384 elements, or atopkwithk≥ 16,384, that the device sort does not fit, and anint32orint64call that the device sort does not serve. The MoE dispatch argsort stays in the graph.
For MoE models, use the stock
grouped_mmrecipes and leaveTORCH_NEURONX_USE_DYNAMIC_NKI_KERNELSat its default. The whole MoE layer, includinggrouped_mm, the dispatch argsort, and the combine, then stays in the compiled graph.Attention backends. SDPA, FlexAttention, and
varlen_attnrun on the NKI attention kernels in eager mode and withtorch.compile.varlen_attndoes not supportseqused_k,block_table, ALiBi, or dropout.64-bit types.
float64andint64are computed as 32-bit types on the device. Keep training inbfloat16/float32.Pinned TorchTitan revision. The tutorials are validated against aws-neuron/torchtitan-neuron, the Neuron fork of upstream
pytorch/torchtitancommit 7cdf0aa9.Profiling. Neuron device profiling through TorchTitan’s built-in profiler needs support for the PrivateUse1 profiler activity, which isn’t in the pinned revision. The Llama3 tutorial passes
--profiling.no-enable-profiling. To profile, usetorch.profilerwithtorch_neuronx.profiling.NeuronConfigand Neuron Explorer.
Note
Running on Trn3: The instance-dependent values on this page, such as the
number of ranks per node, the device memory (HBM) per rank,
NEURON_RT_NUM_CORES, and the device mesh shapes, are for Trn2
(trn2.48xlarge). Trn3 servers have a different number of Trainium chips, so
these values do not apply to Trn3 without change. Before you run on Trn3,
calculate them again from the Amazon EC2 Trn3 architecture and Trainium3 architecture
specifications. For the effect of the LNC setting on the number of visible
cores, see Logical NeuronCore configuration.
Further reading#
How to set up TorchTitan Neuron — Set up TorchTitan on a Neuron instance.
TorchTitan training tutorials — TorchTitan training tutorials for Llama, DeepSeek, and GPT-OSS.
Best practices for TorchTitan Neuron — Enablement and performance guidance.
This document is relevant for: Trn2, Trn3