Research

PyTorch · 2 min read

Attention and the next token

A language model writes one token at a time, looking only backwards.

In attention, each token computes how much to look at every earlier token. The causal mask makes sure no token looks at the future: during generation, the future does not exist yet. To avoid recomputing at every step, the model keeps the keys and values it already computed in the KV cache.

Each step ends with a probability list for the next token. Temperature flattens or sharpens that list; top-k cuts the unlikely options. Low temperature repeats the most likely choice, high temperature takes more risks. In a voice model the tokens are pieces of sound, and this draw becomes variation in rhythm and intonation.

Next postMore voices per GPU

Read next

  1. Infrastructure · 2 min read

    More voices per GPU

    CUDA graph, MPS and batching: how we doubled real-time voices on the same GPU.Read
  2. PyTorch · 2 min read

    From audio to tensor

    Every audio clip that enters a model becomes a tensor. Its shape decides memory and speed.Read
  3. Acoustics · 2 min read

    From sound to tokens

    One second of speech has tens of thousands of numbers. A voice model does not write them one by one.Read