Parallel Sampling
Parallel sampling is an inference technique that generates several independent continuations from the same prompt state, then selects or combines them. It is the mechanism behind best-of-n and self-consistency: share the prompt prefill and prefix KV cache, but pay separately for each branch’s generated tokens and divergent KV cache.
The need appears when one generation is unreliable but making a single answer longer is not the right fix. Reasoning tasks, code generation, extraction, and agent decisions often have multiple plausible paths, only some of which end well. Parallel sampling spends compute sideways: try several continuations from the same prompt, usually with sampling enabled, then use a verifier, reward model, metric, log probability, or vote to decide what to return.
Mechanically, the server runs prefill once for the prompt and stores the resulting KV cache as a shared prefix. It then forks multiple sequence states from that prefix. As soon as branches generate different tokens, each branch appends its own KV blocks. Best-of-n scores the completed branches and picks one. Self-consistency maps each branch, such as a rationale, to a final answer and returns the answer with the strongest agreement.
The common misunderstanding is that parallel sampling is n complete requests. It is not, if the serving stack really shares the prefix. Prefill work and prefix memory are paid once, while autoregressive decode is still paid per branch token. The trade-off is therefore sublinear memory and prefill cost, but roughly linear decode cost. If outputs are long or the prompt is short, the saving can be small.
Engineers meet this in inference servers, schedulers, and billing models rather than in model architecture. Systems such as paged KV caches and prefix caches allow branch objects to reference the same prompt blocks and copy on write after divergence. Correct pricing separates prefill, decode, KV residency, and verifier passes. If cache sharing is missing, parallel sampling quietly becomes expensive independent retrying.
Common questions
- How is parallel sampling different from batching?
- Batching groups work so hardware is used efficiently; parallel sampling is a decoding strategy that intentionally creates multiple continuations for the same request. They often interact: the branches may be batched together, but their value comes from independent attempts and later selection or aggregation, not merely from running unrelated requests in one batch.
- Is best-of-n the same as self-consistency?
- No. Best-of-n chooses the highest-scoring complete branch according to a verifier, reward, metric, or other scorer. Self-consistency first extracts an answer from each branch, then chooses the answer supported by the most branches. Best-of-n trusts a scoring function; self-consistency trusts agreement across diverse reasoning paths.
- When is parallel sampling worth it?
- It depends on prompt length, output length, verifier quality, and how often extra attempts change the result. It is attractive when the prompt is expensive and shared, outputs are moderate, and selection is reliable. It is weak when decode dominates, branches are very long, or the serving stack duplicates prefix KV instead of sharing it.
- Does parallel sampling reduce latency?
- Sometimes, but it is not a latency trick by default. Running branches concurrently can avoid waiting for serial retries, yet it also consumes batch slots, KV memory, and decode bandwidth. For a busy service, one wide request may delay other users. The honest answer depends on scheduler policy, available hardware, and branch length.