pip install vllm★Prebuilt CUDA wheels. On uv:uv pip install vllm --torch-backend=autoauto-detects your GPU/driver.# needs a supported GPU (NVIDIA/AMD/Intel) on Linux; Python 3.10-3.14noteLinux-first. CPU, TPU, Gaudi, and Apple-silicon builds exist but use separate install paths (see docs).export HF_TOKEN="hf_..." # for gated Hugging Face modelsModels are pulled from the Hugging Face Hub by id. SetVLLM_USE_MODELSCOPE=1to pull from ModelScope instead.from vllm import LLM, SamplingParams★The two objects you use most: the engine and its generation config.
llm = LLM(model="meta-llama/Llama-3.1-8B-Instruct")★Loads weights onto the GPU once. Any HF model id (or a local path). Addtensor_parallel_size=Nto shard across N GPUs.outs = llm.generate(["Hello, ", "The capital of France is"], sp)★Pass a list of prompts — vLLM batches them together. Continuous batching keeps the GPU saturated automatically.for o in outs: print(o.prompt, o.outputs[0].text)★EachRequestOutputhas the prompt + one or moreCompletionOutputs (.text,.token_ids,.cumulative_logprob).LLM(model=..., max_model_len=8192, dtype="bfloat16", seed=0)Common constructor args: cap context length, set precision, fix the seed. These mirror thevllm serveflags.
sp = SamplingParams(temperature=0.8, top_p=0.95, max_tokens=256)★The core knobs.temperature=0= greedy/deterministic. Alsotop_k,min_p,repetition_penalty,presence_penalty.SamplingParams(n=3, best_of=3)n= how many completions to return per prompt;best_ofgenerates then keeps the best.SamplingParams(stop=["\n\n"], stop_token_ids=[128009])Stop strings/token ids.ignore_eos=Trueto keep generating past EOS.SamplingParams(logprobs=5, prompt_logprobs=1)Return per-token logprobs for the output (and optionally the prompt).