Comparison

Self-Attention vs. Recurrent Layers: Complexity and Parallelization

For sequence length nn and representation dimension dd, a self-attention layer requires O(n2⋅d)O(n^2 \cdot d) computation and O(1)O(1) sequential operations. A standard recurrent layer requires O(n⋅d2)O(n \cdot d^2) computation and O(n)O(n) sequential operations because each hidden state hth_t depends on ht−1h_{t-1}. Thus, when n<dn < d, as is typical for word-piece or byte-pair sequences in the supplied course context, self-attention has lower asymptotic per-layer complexity and permits parallel computation across sequence positions. For long sequences, restricting each position to an attention neighborhood of size rr reduces the per-layer complexity to O(r⋅n⋅d)O(r \cdot n \cdot d) while retaining O(1)O(1) sequential operations.

0

1

Updated 2026-09-12

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