Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 03 · AI · Past the basics · about 21 min to read

Watch: Attention in production: KV cache, MQA, GQA and MLA
▶ VideoPlay it as a journeyTutor comes with a plan

Inference at Scale (why an LLM is fast, and cheap)

Inference at Scale
Inference at Scale · Open board

The “Inference at Scale” board of the How LLMs Work track. It draws one fact and the four tricks that fall out of it. This lesson is how people found each one, mostly by running out of money.

Before you start. From Inference (sampling, context, KV cache, hallucination): a model writes a reply one token at a time, a token being a chunk of text about three quarters of a word, running the whole model again for each one and keeping a scratch pad called the KV cache so it never re-reads the conversation from the start. Three more of its words recur here: the model’s stored numbers, its dials, are its weights. A layer is one row of those dials, and the model is a stack of rows. And the model never picks a token outright, it scores every possible next token and rolls dice weighted by those scores. That lesson explained what generation does. This one explains why it costs what it costs.

Lesson 19 of 83 in AI

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 30 November 2022: the chatbot nobody could afford to run
  • Memory-bound: why one token costs 7 ms of moving and 0.045 ms of maths
  • Batching: thirty-two people served on one trip past the weights
  • Quantization: fewer bits per weight, so there is less to wheel
  • The KV cache: it fills the card long before the weights do
  • 2023: PagedAttention, the operating system’s trick played on the KV cache
  • Speculative decoding: a small model guesses, the big one checks four in one trip
  • How busy is the counter?
  • The prompt is the other way round
  • Thirty-two chats, priced step by step
  • Why the notebook is 512 KB a token
  • Four guesses, one trip
  • All of it in code

Terms it explains: How LLMs Work, token, KV cache, weights, layer, 14 GB, one token, memory-bound, batching, more than six times, frontier models, quantization, 4 GB, 94% empty, PagedAttention, under 4%, speculative decoding, once, 7.18 ms, FLOP, arithmetic intensity, prefill, Continuous batching, int8, int4, key, value, attention heads.

Related paper

Review AI