Why do RNNs suffer from vanishing gradients across long sequences whereas Transformers do not?
Last updated
In an RNN, the gradient across
t−ksteps is a product of Jacobians, so it decays (or explodes) exponentially with distance. LSTMs/GRUs only mitigate this.In a Transformer, attention links any two positions directly, so gradient path length depends on layer count, not sequence length.
Residual connections (
x + f(x)) carry gradients through depth undiminished. Caveats remain: Post-LN needs warmup, and saturated softmax shrinks gradients (hence√d_kscaling).