Concept icon
Concept

Computational Complexity and Parallelization

Self-attention layers exhibit a per-layer computational complexity of O(n2d)O(n^2 \cdot d) and execute in O(1)O(1) sequential operations. In contrast, standard recurrent layers require O(nd2)O(n \cdot d^2) operations per layer and O(n)O(n) sequential operations, because hidden states hth_t must be computed sequentially from ht1h_{t-1}.

In machine translation and natural language processing tasks using word-piece or byte-pair representations, the sequence length nn is typically smaller than the representation dimensionality dd. Consequently, self-attention layers are computationally faster than recurrent layers in practice, while fully enabling parallel computation across all positions within a training example.

To improve computational efficiency for tasks involving very long sequences where nn is large, self-attention can be restricted to attend only to a neighborhood of size rr centered around the respective output position. This restricted self-attention reduces the per-layer complexity to O(rnd)O(r \cdot n \cdot d) while keeping sequential operations at O(1)O(1).

0

1

Concept icon
Updated 2026-09-07

Tags

Prep Sessions

Foundational Deep Learning Architectures: Transformers and Residual Networks @ University of Michigan - Ann Arbor

Ch.2 Transformer Training and Evaluation - Foundational Deep Learning Architectures: Transformers and Residual Networks @ University of Michigan - Ann Arbor

Complexity and Path Lengths in Self-Attention - Foundational Deep Learning Architectures: Transformers and Residual Networks @ University of Michigan - Ann Arbor