AI engineering glossary · Transformers LLM architecture

What is quadratic attention cost?

Quadratic attention cost (also called O(n^2) attention): The fact that standard self-attention compares every token with every other, so compute and memory for the score matrix grow with the square of sequence length. Doubling the input length roughly quadruples attention cost, which is the main obstacle to very long contexts.

Level: intermediateTopic: Transformers LLM architecture

Quadratic attention cost: an example

A 1,000-token input produces 1 million scores per head; a 10,000-token input produces 100 million.

Related terms

More Transformers LLM architecture terms

Where you learn it

Quadratic attention cost is part of the AI Engineering Program, which teaches it with notes, a hands-on lab and an exam. The first lesson is free.

Before you go

Take the cheat sheet with you

One free PDF: the key AI-engineering terms, formulas and Python idioms. No spam; unsubscribe any time.