AWS Trainium 50 Exercises #5: Fundamentals of Distributed Training
Chapter 5: Fundamentals of Distributed Training
This chapter assumes the following knowledge:
- Basic understanding of AWS Trainium (covered in Chapter 2)
- Fundamental understanding of neural networks
Problems (33–37)
Training using multiple memory devices in parallel is called distributed training. (Device: here refers to the smallest unit that executes training. In the case of Trainium, this refers to a Neuron core. Trainium2 has both physical and logical Neuron cores; here we refer to logical Neuron cores.)
Distributed training becomes necessary when: (1) training on a single device is too slow, or (2) the model is too large to fit on a single device.
| Category | Subcategory | Overview | Solves (a)? | Solves (b)? |
|---|---|---|---|---|
| Data Parallel | Data Parallel (DP) | Splits data within a mini-batch across multiple devices | Yes | No |
| Model Parallel | Tensor Parallel (TP) | Splits parameter tensors (row-wise or column-wise) across devices | Yes | Yes |
| Pipeline Parallel (PP) | Assigns different model layer ranges to different devices (e.g., layers ●–▲ to device 1, ▲–■ to device 2, etc.) | Yes | Yes |
These are the three primary parallel strategies, and they can be combined. It is important to note that training large models that do not fit on a single device requires model parallelism (TP or PP). For Trainium (Trn), any model that cannot fit in 1 core = 16GB (which applies to most LLMs) will require model parallelism.
In the previous chapter, the training configuration was DP=1, TP=32, PP=1. (The notation DP, TP, PP may also refer to the number of parallel devices used for each method.)
- You want to train with
DP=2, TP=32, PP=8. How many Neuron cores are required, and how manytrn1.32xlargenodes will you need?Answer
2 × 32 × 8 = 512 cores are required. Since one
trn1.32xlargenode contains 32 Neuron cores, 512 ÷ 32 = 16 nodes are required.
Data Parallelism (DP)
In data parallelism, each device processes a different subset of data from the same mini-batch. The model weights are replicated across all devices, while each device performs forward and backward computation on its assigned micro-batch, after which gradients are synchronized to ensure consistent weight updates. This is the most fundamental and commonly used parallelization strategy when training with large batch sizes. The global batch size refers to the total number of samples processed per optimization step across all devices (i.e., the algorithmic mini-batch size, ignoring hardware). The micro-batch size refers to the number of samples assigned to each individual device.
- You want to train using only data parallelism, with a global batch size of 256. You have 2
trn1.32xlargenodes available. What is the DP value, and what is the micro-batch size?Answer
A
trn1.32xlargeinstance has 32 Neuron cores, and 1 core typically maps to 1 device. With 2 nodes, DP = 32 × 2 = 64. Therefore, the micro-batch size is 256 ÷ 64 = 4.
If the micro-batch size is too large to fit in device memory, gradient accumulation can be used to reduce per-device memory usage by accumulating gradients over multiple steps before performing a weight update. When using gradient accumulation, a single forward-backward execution is sometimes called a micro step, and the weight update step is called a global step.
- Training with the micro-batch size calculated above caused an OOM error. You decide to set the micro-batch size to 1 using gradient accumulation. How many gradient accumulation steps are required?
Answer
The original global batch size is 256, and DP = 64. With a micro-batch size of 1, the required gradient accumulation steps are 256 ÷ 64 ÷ 1 = 4. That is, each device performs 4 micro steps before a weight update to preserve the original global batch size.
The relationship can be summarized as:
Global batch size = Micro-batch size × Gradient accumulation steps × DP.
Tensor Parallelism (TP)
Tensor parallelism splits a single parameter tensor across multiple devices. For example, when computing a large matrix multiplication
2-layer MLP: Details
Consider a model that computes the following for input
where:
-
is the 1st layer weight (output dimension\mathbf{W}_1 \in \mathbb{R}^{h \times d} , input dimensionh )d -
is an activation function such as ReLU (applied element-wise per batch)\phi -
is the 2nd layer weight (output dimension\mathbf{W}_2 \in \mathbb{R}^{o \times h} )o -
,\mathbf{H} \in \mathbb{R}^{B \times h} \mathbf{Y} \in \mathbb{R}^{B \times o}
1st layer (Column Parallel)
Split weight
Each device shares the entire input
Then, concatenate
2nd layer (Row Parallel)
Split
Also split
Finally, sum (AllReduce) the outputs across devices to obtain the final output

💡 For further details, refer to this excellent article by Turing Inc.: https://zenn.dev/turing_motors/articles/0e6e2baf72ebbc
Notes: (1) The TP degree must divide the hidden dimension exactly (e.g., 4096 → TP must be a divisor of 4096). (2) For transformer models, TP must also divide the number of attention heads. (3) With GQA, TP must divide (KV heads × KV_REPLICATOR). Nexus Distributed (NxD) provides KV_REPLICATOR to replicate KV heads so that TP can scale beyond the KV head count limit.
- The Qwen/Qwen3-8B config.json contains
"hidden_size": 4096, "num_attention_heads": 32, "num_key_value_heads": 8. What TP configuration allows the largest valid TP value?Answer
TP must divide 32 and
(8 × KV_REPLICATOR). To maximize TP, set KV_REPLICATOR = 4, which allows TP = 32.
Pipeline Parallelism (PP)
Pipeline parallelism splits model layers across multiple devices and processes micro-batches in a staged pipeline. However, depending on the number of stages and micro-batches, idle time known as pipeline “bubbles” may reduce hardware utilization.

-
Qwen2.5-VL-32B-Instruct consists of a 32-layer visual encoder and a 64-layer text decoder, connected sequentially. You want to train it using DP=4, overall TP=8, PP(visual)=4, PP(text)=16. How many
trn1.32xlargenodes are required?Answer
The required number of cores is
4 × 8 × (4 + 16) = 640. Since eachtrn1.32xlargenode has 32 cores, the number of nodes needed is 640 ÷ 32 = 20 nodes.
By combining DP, TP, and PP, it becomes possible to accelerate training and train models that cannot fit on a single device.
- ⚠️ Notes: Trainium cores are not fully all-to-all connected; only certain communication patterns are supported (details). Therefore, not all DP/TP/PP combinations are valid. For example,
DP=1, TP=1, PP=32cannot run on a singletrn1.32xlargenode because communication between core 7 and core 8 is not supported. Additionally, whenKV_REPLICATOR > 1, extra inter-core communication is required, and some settings may be disallowed for the same reason.
Appendix: Sequence Parallelism
As an extension to tensor parallelism, sequence parallelism shards both model parameters and activations. Instead of storing a full activation tensor on each device, each device stores only a shard of the sequence dimension. This reduces memory usage, although inter-device communication becomes more complex. In NxD, this is supported transparently. In this mode: (1) each device stores only a 1/TP sequence shard, (2) activation tensors are kept in shape (sequence, batch, ...) instead of (batch, sequence, ...), and (3) the per-device tensor shape becomes [q_len//TP, batch, ...] rather than [batch, q_len, ...].
-
We would like to thank Mr. Tokoyo from AWS for his supervision of this material. ↩︎
Discussion