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 09 · AI · Serving LLMs · about 25 min to read

Play it as a journeyTutor comes with a plan

Constrained Decoding (the grammar holds the pen)

Constrained Decoding
Constrained Decoding · Open board

Serving LLMs. Prefill / Decode Split (two pools, one KV in flight) asked where a request’s compute runs. This board asks a different question: once the model is about to write its next word, what is it actually allowed to write? It draws one step with a mask wedged into it, the small machine a format turns into, and a ladder of four constraints ending in the one thing none of them can promise.

Before you start. This track is about serving large language models, and one of them writes its reply a token at a time, where a token is a word or a piece of one. This lesson says “word” for readability and the second half comes back to the difference. Every time the model is about to write another word, it scores every word it knows, turns that list of scores into odds and rolls dice on those odds. It never picks a word freely. It always picks one off that scored list. That step is called decoding, and an earlier lesson priced one of them at 39 milliseconds for a batch of 32 requests. This lesson never touches that price. It only touches which words the dice are allowed to land on. You should also know what a tool call is: a name and a required shape of arguments that the model fills in, first given to it in 2023.

Lesson 81 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

  • 2023: the model that can ask your code to do something, if it writes the request right
  • Less than 40 percent: the number that proved “please” wasn’t a format
  • August 2024: the same model family, a mask, and 100 percent
  • The pen, held one word at a time
  • The grammar has to remember where the pen is
  • What the mask doesn’t cover
  • Where the missing 45 percent goes
  • Why the hand reads tokens, not letters
  • When the boxes sit inside boxes
  • Where a legal reply still goes wrong
  • All of it in code

Terms it explains: JSON, boolean, mask, grammar, automaton, enum, context-free grammar, stack.

Review AI