What is beam search?

Beam search is a decoding method that keeps the few most likely partial sequences at each generation step and finally picks the kept sequence with the highest total probability; the number kept is the beam width.

Unlike greedy decoding, which takes only the most likely token each step and never backtracks, beam search keeps several alternatives open, so it can find a sequence slightly less likely at first but better overall. Unlike sampling methods such as top-p sampling, it is deterministic.

Topic
Prompts, context, reasoning and generation
Also known as
Beam decoding

How beam search works

  1. A beam width is chosen, say 4; at the first step the 4 most likely tokens are kept as beams.
  2. At each step possible next tokens extend every beam and all candidates are scored by total log probability.
  3. Only the 4 highest-scoring sequences among all candidates remain; the rest are dropped.
  4. Sequences reaching an end token are set aside; scores are usually length-normalised, since otherwise short sequences are favoured.

In more detail

Length penalties and repetition penalties

Standard beam search maximises sequence likelihood, which naturally favours shorter sequences because every added token multiplies in a probability below 1. In practice, length normalisation divides the total log probability by the sequence length raised to a tunable exponent; a repetition or coverage penalty can also be added to prevent loops.

KV cache overhead and the effect on inference engines

During LLM decoding, beam search multiplies active sequence states by the beam width B, increasing KV-cache memory pressure and reducing maximum concurrent batch size on GPU. Modern serving engines mitigate prefill overhead via shared prefix KV blocks, yet divergent decoding steps still consume roughly B times the per-token cache of greedy decoding.

Step-level beam search in reasoning models

While token-level beam search has largely faded from open-ended chat, step-level beam search has re-emerged in reasoning pipelines. In test-time compute scaling, candidate reasoning steps are scored by a Process Reward Model (PRM) and the top B partial reasoning paths are expanded iteratively rather than single tokens.

Commonly confused terms

TermHow it differs
Diverse beam searchDiverse beam search adds a dissimilarity penalty across beam groups to prevent near-identical candidates; standard beam search often produces beams differing by only one or two tokens.

Why beam search matters for on-premises AI

Beam search is common in tasks expecting output close to one right answer, such as machine translation, summarisation and speech recognition. Being deterministic, the same input gives the same output, which eases testing and audit. In open-ended chat it can produce repetitive, bland text, so sampling has largely replaced it there. Cost rises with beam width, a multiplier to include when planning in-house GPU capacity.

ON-PREMISES EXAMPLE

An automotive supplier uses beam search in an in-house model translating technical manuals from English to Turkish; since a paragraph always gets the same translation, checking output against the approved terminology list is easier.

Common questions

Why is beam search rarely used in chat models?

It seeks the most likely sequence, which in open-ended text can give repetitive, bland answers. Sampling with temperature and top-p gives more natural text in chat.

How is beam width chosen?

A wider beam tries more alternatives, but cost grows with width while gains shrink past a point. The value is chosen on the task's own validation data.

Sources

In the glossary: Glossary, A to C

What does this term mean for your infrastructure?

We can work out together in a technical assessment how it maps onto your data, hardware and security requirements.

Request a technical assessment →

This site sets no cookies. Visitor numbers are counted in aggregate using a cookieless method that does not identify anyone. See the Privacy Policy for details.