Log inStart free
LESSON 34.04 · 5 STAGES · 3 CONTROLS · 3 CHECKSPRO · PREVIEW

Prompt compression and context pruning

Watch three cuts shrink a chat prompt, and see what each cut costs.


Pro lesson. Stage 1 is free to watch. Pro opens all 5 stages, 3 controls and 3 checks, in this lesson and every other.

Go Pro · $8.25/mo
EXPLAINER · 34.04 · PROMPT TRIMMERPROMPT 1,000 · OUTPUT 200 · 45.7 MS
01
Stage 1 of 5 · Where tokens go
Each prompt holds a system prompt, earlier turns, help chunks and a question. One output token costs as much as 6 prompt tokens.
Explain it simply

Each row is one of the 12 sample chats. Each row starts with the system prompt, and the prefix cache already holds it, so it costs little. In the panel, one output token takes about 144 microseconds of GPU time. A new prompt token takes only 23.

Twelve rows of prompt tokens, 1,000 on average. A request uses 45.7 GPU milliseconds, and the busy GPU time costs 137 dollars a day.

prompt tokens: system, turns, summary, chunks, questionoutput tokens, GPU time, costsettings, 1B model worklost factsdashed: removed tokens
system prompt (cached)turnssummarychunksquestionremovedQ01Q02Q03Q04Q05Q06Q07Q08Q09Q10Q11Q12H100 time per token (batch 32)cached prompt token7.8 µsprompt token23.0 µsoutput token143.9 µsmean request: 1,000 + 200 tokens600 × 23.0 µs200 × 144 µs= 45.7 GPU ms a request2.7M a day at $4.00/h: $137 a dayprompt tokens and their costlost factt = 600 × 0.023 + 400 × 0.0078 + 200 × 0.144 ≈ 45.7 mssystem prompt (cached)turnssummarychunksquestionremovedQ01Q02Q03Q04Q05Q06Q07Q08Q09Q10Q11Q12H100 time per token (batch 32)cached prompt token7.8 µsprompt token23.0 µsoutput token143.9 µsmean request: 1,000 + 200 tokens600 × 23.0 µs200 × 144 µs= 45.7 GPU ms a request2.7M a day at $4.00/h: $137 a dayprompt tokens and their costlost factt = 600 × 0.023 + 400 × 0.0078 + 200 × 0.144 ≈ 45.7 ms
Toy: 12 help-chat requests, 8B model on an H100, toy prices
STAGE 1 / 5
MATH · STAGE 1HOVER A SYMBOL OR A SHAPE
t=u cu+s cs+o co\sy{t}{ink}{t} = \sy{u}{data}{u}\,c_u + \sy{s}{data}{s}\,c_s + \sy{o}{out}{o}\,c_o
t=600×0.023+400×0.0078+200×0.144≈45.7 mst = 600\times 0.023 + 400\times 0.0078 + 200\times 0.144 \approx 45.7\,\text{ms}

GPU time adds new prompt tokens, cached tokens and output tokens.

Common mix-ups

MYTHHalving the prompt tokens halves the GPU cost.

The fix, and 1 more mix-up with the diagram to show them, come with Pro.

Predict, then reveal
3 CHECKS · PRO
Q01If only the top chunk is kept, how many of the 12 requests keep every chunk they need?

Make your guess, then test it in the diagram. All 3 checks come with Pro.

PRO LESSON · YOU WATCHED STAGE 1 OF 5
Unlock the full explainer
  • 4 more stages and 3 live controls
  • 2 mix-up cards and 3 predict-then-reveal checks
  • Watch it as a narrated video, in three voices
  • Every Pro lesson and capstone · 656 in total

$99 a year, or $15 a month. Cancel any time.