What makes Transformers more parallel-friendly than RNNs?
Answer
The fundamental difference is dependency structure: an RNN computes each hidden state from the previous one, , so step
cannot start before step
finishes. A Transformer replaces recurrence with self-attention, which scores every pair of positions simultaneously, so all tokens are processed in one parallel pass. This turns sequential loops into dense matrix multiplications that saturate modern GPUs.
(1) No Temporal Dependency: Transformers process all input tokens at once; there is no hidden-state chain forcing order.
(2) Fully Parallelizable Attention: All attention scores are computed in a single matrix product
, and the FFN applies to all positions simultaneously.
(3) Optimized for GPUs: Large GEMM kernels keep thousands of GPU cores busy, unlike the RNN’s long chain of small dependent steps.
Mathematical Formulation:
Where:
is the RNN hidden state at step
; it cannot be computed before
exists.
is the full
attention score matrix, produced by one parallel GEMM from the query and key matrices
.

Figure 1: RNN: a serial chain where each step waits for the previous hidden state; Transformer: the whole sequence enters the block simultaneously.
Training-Time Consequence: With a sequence of length , an RNN needs
sequential steps no matter how much hardware you have: latency grows linearly with sequence length. A Transformer’s forward pass is a constant number of parallel matrix operations; the cost grows in FLOPs, not in wall-clock dependency depth.

Figure 2: Dependency depth: RNN needs ordered steps; the Transformer needs only
sequential layers, each internally parallel.
| Aspect | RNN | Transformer |
|---|---|---|
| Token dependency | Sequential: | None: all tokens at once |
| Training steps for n tokens | One parallel pass | |
| Core operation | Many small vector updates | Large batched GEMMs |
| Long-range signal path | Through | One attention hop, |
Why It Matters: Parallelism is why Transformers can train on web-scale corpora (a workload that would take an RNN impractically long to finish), and why attention became the default sequence model in modern NLP.
Leave a Reply