Basis Lab

Serving a Model to Many People

The Two Jobs That Get in Each Other's Way

Last timeServing Many Requests Together

Reading a prompt and writing an answer are different kinds of work on the same hardware. Mixed together they interfere, and the interference is felt by whoever was already mid-sentence.

A request has two quite distinct lives. First its prompt is read, all of it, in one go. Then its answer is produced, one word at a time, with the whole model read from memory for each word. These two activities look similar from the outside and are almost opposites underneath.

FIG 1Four request shapes, and what each demands of the machine
ms reading the promptms writing the answerarithmetic units kept busy, per centmemory bandwidth used, per cent
short prompt, short answer124801892
short prompt, long answer1248001495
long document, short answer14004808830
long document, long answer140048002588
The marked cell is the only one where the arithmetic is the limit, and it belongs to the only row dominated by prompt reading. Everywhere else the machine is waiting on memory, which is why the two phases cannot be treated as one workload with an average.

Why they are not the same job

Reading a prompt processes every word in it simultaneously. The model is read once and a great deal of arithmetic is done with it, so the processor's arithmetic units are the thing that runs out. Producing a word processes a single position. The model is read once again, for a tiny fraction of the arithmetic, so the memory is the thing that runs out and most of the arithmetic capability sits idle.

A machine saturated on arithmetic has memory bandwidth to spare, and a machine saturated on memory has arithmetic to spare. That sounds like an opportunity, and it is, but only if the two are arranged carefully. Done carelessly, they simply take turns and each waits for the other.

FIG 2What the first word waits for, in a typed question and a pasted document
stepthe part of the waita typed questiona pasted documentthe difference between themwhat happened
1queued, before anything at all is done for it0 ms, with a place free0 ms, with a place freenone, because queueing has nothing to do with the request's own sizeTwo requests arriving at an idle group wait the same amount of time for a place, whatever is in them.
2reading its own prompt12 ms1,400 ms1,400 / 12 = 117 times, in proportion to the words in itThe only part of the wait that grows with the request itself, and it grows straight in proportion: ten times the words is ten times the reading.
3so the first word appears after0 + 12 = 12 ms0 + 1,400 = 1,400 msone of these feels instant and the other does notBoth users typed into the same box, and neither of them chose anything except how much text to paste.
4the same two, arriving behind one document read whole1,240 + 12 = 1,252 ms1,240 + 1,400 = 2,640 msthe same 1,240 ms added to both, from somebody else's requestThe step that reads a two thousand word prompt in one go is the 1,240 ms, and it lands on whoever is waiting regardless of what they sent.
4 steps
Read the bottom row against the one above it. Of the two parts of the wait, only prompt reading grows with the request's own size, which is why a pasted document behaves so differently from a typed question, and the queueing part is the one a user can neither see nor cause. A short request can therefore wait a second for the first word without anything being wrong with it.

What one long prompt does to everybody

Here is the part that produces confusing incident reports. A step is a shared event. Whatever the step is doing, every request in the group waits for the step to finish.

So when a prompt of two thousand words is admitted and read in a single step, that step takes perhaps a second. Every other request in the group, each of them quietly producing a word every forty milliseconds, produces nothing at all for that second. Their users see the text stop mid-sentence and then resume.

The lesson stops here

3 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01Mostly Waiting
  2. 02The Average Minute Does Not Existopening only
  3. 03Reading the Weights Once for Everybodyopening only
  4. 04The Two Jobs That Get in Each Other's Wayyou are here
  5. 05Where the Complaints Actually Liveopening only
  6. 06Saying No While You Still Canopening only
  7. 07Help That Arrives Nine Minutes Lateopening only
  8. 08A Number You Can Be Held Toopening only

Read alongside