Glintwell
Running models

Making a model fast and cheap to use

Training happens once. Running the model happens billions of times. This page covers how models generate text, where the memory goes, and the methods that make them fast.

Basics

Two phases: reading and writing

  • Prefill: the model reads the whole prompt at once. This is heavy math and runs fast on modern chips.
  • Decode: the model writes one token at a time, each depending on the last. Every step must read all the model's weights from memory, so speed depends on memory bandwidth, not math.
  • Because the two phases stress different things, large services sometimes run them on separate machines.
Memory

The key-value cache

To avoid redoing work, the model stores the keys and values for every earlier token: the KV cache. For long texts and many users, this cache can need more memory than the model itself.

That is why attention designs that shrink the cache (grouped heads, compressed latents, sliding windows, linear attention) matter so much in practice.

Throughput

Batching and paged memory

  • Continuous batching: new requests join the running batch as soon as others finish, instead of waiting for the whole batch.
  • Paged attention: the cache is stored in small fixed-size pages, like computer memory, so it wastes almost no space and requests can share pages for common prompts.
  • Prefix caching: a system prompt used by many requests is computed once and reused.
Smaller numbers

Quantization

  • Store weights in 8 bits instead of 16: half the memory, nearly no quality loss.
  • 4-bit weights: a quarter of the memory. Smart methods choose how to round each group of weights using a little sample data, and protect the small share of weights that matter most. Quality loss is small for most uses.
  • Outliers (a few huge activation values) are the main obstacle; methods that move that difficulty from activations into weights, or rotate the numbers first, make low-bit math work.
  • The KV cache can be quantized too, to 8 or even 4 bits.
  • Some models are trained with low precision in mind from the start, so they lose almost nothing when quantized.
Speed

Speculative decoding

A small, fast draft model guesses the next several tokens; the big model checks them all in one pass and keeps the ones it agrees with. The output is exactly what the big model would have written, only faster, often 2 to 3 times.

  • The draft can be a separate small model, extra prediction heads on the big model, or the multi-token prediction heads trained during pretraining.
Expert models

Serving mixture-of-experts models

  • Only a few experts run per token, so expert models are fast for their size, but all experts must sit in memory.
  • Large services spread experts across many chips and balance the load by copying popular experts.
  • On a single machine, rarely used experts can live in slower memory.
Adapting

Cheap fine-tuning with adapters

  • Low-rank adapters: freeze the model and train two small matrices next to each big one. You train well under 1 percent of the weights, and can swap adapters for different tasks.
  • Quantized adapters: keep the frozen model in 4 bits while training the adapter, so a large model can be fine-tuned on a single graphics card.
Local

Running a model on your own computer

  • A rough rule: a model needs about 2 bytes per parameter in 16-bit, 1 byte in 8-bit, and a little over half a byte in 4-bit, plus room for the cache. A 7-billion-parameter model in 4-bit fits in about 5 GB.
  • Open tools can run quantized models on an ordinary laptop's processor or graphics chip, entirely offline.
  • Small distilled models (1 to 8 billion parameters) are the sweet spot for local use.