Gradivex
  • Home
  • Academy
  • Arena
  • Visualizer
  • Models
Log in
NLP & Transformers/The Transformer/Lesson 5

Why transformers beat RNNs

Module 3 · Lesson 5 of 5 · 7 min read
Theory

The winning move was economic

The tempting story: transformers won because attention is smarter than recurrence. The true story is blunter: transformers won because they made GPUs profitable. Architecture quality mattered, but throughput decided the war.

An RNN must finish token 41 before touching token 42; a 10,000-token document is a 10,000-step queue, and a GPU (a machine built to do millions of things at once) idles in that queue. A transformer processes all 10,000 tokens simultaneously during training. Same hardware, orders of magnitude more learning per hour.

Add the path-length bonus: between token 3 and token 9,000, an RNN's gradient crosses ~9,000 multiplications (you watched signals die in far shorter chains), while attention connects them in ONE step, at every layer. Cheaper training AND healthier gradients over distance. That combination is why "train on the whole internet" went from fantasy to budget line.

Interactive

Race them yourself

Pick a sequence length and compare the time shape: the RNN queues one token after another, the transformer runs a fixed number of parallel layers regardless of length.

tokens in the sequence
RNN8 sequential steps
each step waits for the one before it
Transformer12 parallel rounds
every token processed at once, 12 layers deep, whatever the length
Attention pays for this with 8 × 8 = 64 pairwise scores per layer. All of them computable at the same time, which is the kind of bill a GPU loves.

At 8 tokens the queue barely hurts. Short sequences kept RNNs viable for years.

Theory

The bill, and the rematch nobody scheduled

Attention's price tag is printed right in the race panel: every token scores every token, so compute grows with the SQUARE of length. Double the context, quadruple the attention bill. The 128k-token context windows you use today are a stack of engineering workarounds (sparse patterns, KV caches, memory tricks) built to blunt that square.

And at generation time the tables partially turn: an RNN carries one compact state forward, while a transformer generating token 10,001 must still attend over the 10,000 before it. Inference cost is the transformer's ongoing tax, paid on every token it ever writes.

Which is why the story is not closed. State-space models (Mamba and relatives) are recurrence rebuilt on modern math: parallel to train, RNN-cheap to run. Whether they dethrone attention or merely haunt it, remember the lesson of THIS lesson: architectures win on hardware economics, not elegance. Judge every challenger by that yardstick.

Interactive

Check your understanding

What was the decisive factor in transformers replacing RNNs?

Takeaway

What to remember

  • ✓Transformers won on hardware economics: full-sequence parallelism during training versus the RNN's token queue.
  • ✓Any two tokens connect in one attention hop; RNN gradients cross one multiplication per intervening step.
  • ✓The price: attention compute grows with the square of sequence length, and inference re-reads the whole context.
  • ✓Long-context features are engineering against that square, not its repeal.
  • ✓State-space models are recurrence's rematch attempt. Judge them, like everything, on throughput per euro.
  • ✓Module complete: the machine is assembled. Next module: what happens when you make it enormous and feed it the internet.
Mentor-0

Stuck on something in this lesson? Ask.

0/1000

Every lesson is free to read. Log in to save your progress, complete lessons, and earn Compute and XP.

Log in free
Full transformer architecture
Gradivex

Understand AI from the inside, read it, see it, prove it.

Platform

AcademyVisualizerRoadmapsModels

Community

DiscordLeaderboard

Company

PrivacyTerms

© 2026 Gradivex. All rights reserved.