Sampling
Generation is not “the one true next token.” Sampling parameters draw from the vocabulary distribution. Offline, that is SamplingParams. Online, the same knobs map to OpenAI fields plus extra_body.
Defaults may come from the repo’s generation_config.json—see OpenAI-Compatible API. Always cap max_tokens so a runaway sample cannot hog scheduler slots.
Offline: SamplingParams
Reuse one LLM instance; swap SamplingParams per batch. Instruct models may also take llm.chat(messages, sampling_params=...) (confirm the method on your version).
Parameter intuition
Very high temperature plus a tiny top_p fight each other. Change one or two knobs and compare the same prompt.
Greedy vs sampling
- Greedy / near-deterministic:
temperature=0(or very low), no nucleus lottery. Good for extraction, classification, rigid formats, regression tests. - Sampling: temperature around 0.6–1.0 with
top_p. Good for chat and writing. Tiny models (0.5B) fall apart if temperature is too high—start near 0.7.
If you need JSON-shaped output, prefer official structured outputs / guided decoding (names change) over begging in the prompt.
Online: Chat Completions fields
Some OpenAI fields (e.g. user) are ignored. Extra vLLM sampling keys go in extra_body; see “Extra parameters” in the official server docs.
Mapping from Transformers generate()
vLLM tokenizes and detokenizes for you. Do not mix raw token-id lists with string prompts accidentally. Recommended sampling on the model card is often already in generation_config.json.
Debug checklist
- Start with
temperature=0andmax_tokens=32to prove the model generates (not an instant EOS from the template). - Turn sampling on and confirm the two outputs differ.
- If it repeats a sentence forever, lower temperature, add
stop, or check you did not feed a chat transcript into the completions API. - Latency rises with
max_tokensand concurrency—that is continuous batching working, not a hang.