Offline batched inference means generating text for a list of input prompts without running a model server. The LLM class is the main class for running offline inference with the vLLM engine, and SamplingParams specifies the parameters for the sampling process. This is different from serving a model with vllm serve: here your Python script loads the model, runs the whole list, and exits.
Install vLLM
The quickstart lists Linux as the operating system and Python 3.10 to 3.13. It recommends uv, a fast Python environment manager, to create and manage the Python environment:
uv venv --python 3.12 --seed
source .venv/bin/activate
uv pip install vllm --torch-backend=auto
By default, vLLM downloads models from Hugging Face when you first use them, so the first run includes a model download.
Write the script
The docs give this example script, examples/basic/offline_inference/basic.py. It imports the two classes, defines a list of four prompts, and sets the sampling temperature to 0.8 and the nucleus sampling probability to 0.95:
from vllm import LLM, SamplingParams
prompts = [
"Hello, my name is",
"The president of the United States is",
"The capital of France is",
"The future of AI is",
]
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)
llm = LLM(model="facebook/opt-125m")
outputs = llm.generate(prompts, sampling_params)
for output in outputs:
prompt = output.prompt
generated_text = output.outputs[0].text
print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")
llm.generate adds the input prompts to the vLLM engine’s waiting queue and executes the engine to generate the outputs with high throughput. The outputs are returned as a list of RequestOutput objects, which include all of the output tokens. Each output carries its prompt in output.prompt and its generated text in output.outputs[0].text. Run the example with python examples/basic/offline_inference/basic.py.
Know the two things that catch people out
First, llm.generate does not automatically apply the model’s chat template to the input prompt. If you are using an Instruct model or Chat model, apply the chat template yourself, or use the llm.chat method and pass a list of messages in the same format as OpenAI’s client.chat.completions. Second, by default vLLM uses the sampling parameters recommended by the model creator by applying the generation_config.json from the Hugging Face model repository if it exists. If you prefer vLLM’s defaults, set generation_config="vllm" when creating the LLM instance. The chat and generate example scripts also accept sampling parameters as arguments — --max-tokens, --temperature, --top-p, and --top-k — so you can change them without editing the script.
Try it: four checks from install to four replies
| Check | What you should see | If you do not see it |
|---|---|---|
| Install finished | uv pip install vllm --torch-backend=auto completes with no error |
Check the Python version is 3.10 to 3.13 and the environment is activated |
| Script imports | from vllm import LLM, SamplingParams runs with no error |
Check vLLM installed into the active environment |
| Four outputs | One printed reply for each of the four prompts | Check the prompt list has four entries and llm.generate was called with both arguments |
| Text read correctly | Each reply printed from output.outputs[0].text |
Check the loop reads output.prompt and output.outputs[0].text from each output |
Expected result. We checked the vLLM quickstart, which gives the Linux and Python 3.10 to 3.13 prerequisites, the uv install commands, the four prompts, SamplingParams with temperature 0.8 and top_p 0.95, the LLM class with facebook/opt-125m, llm.generate, the RequestOutput list, the generation_config.json default, and the chat template note with the llm.chat alternative, and the vLLM offline inference examples page, which gives the full basic.py script, the command to run it, and the –max-tokens, –temperature, –top-p, and –top-k arguments. We did not install vLLM or run the script on this machine.
Limits
This guide covers offline batch generation in one script only. It does not start a server: for an OpenAI-compatible API server, use vllm serve instead. The example model is facebook/opt-125m, a small test model, and larger models need a GPU with enough memory. The quickstart lists Linux as the prerequisite operating system, and the install commands shown are for NVIDIA GPUs. We did not test any of this ourselves.
Sources
- vLLM Quickstart — Linux and Python 3.10 to 3.13 prerequisites, uv install, four prompts, SamplingParams temperature 0.8 and top_p 0.95, LLM with facebook/opt-125m, llm.generate, RequestOutput list, generation_config.json default, chat template note and llm.chat
- vLLM Offline Inference examples — full basic.py script, python examples/basic/offline_inference/basic.py, chat.py and generate.py accept –max-tokens, –temperature, –top-p, and –top-k
