Skip to main content
Use vLLM for high-throughput production deployments, batch processing, or serving models via an API.
vLLM offers significantly higher throughput than Transformers, making it ideal for serving many concurrent requests. However, it requires a CUDA-compatible GPU. For CPU-only environments, consider using llama.cpp instead.

Installation

Install vLLM v0.14 or a more recent version:

Basic Usage

The LLM class provides a simple interface for offline inference. Use the chat() method to automatically apply the chat template and generate text:

Sampling Parameters

Control text generation behavior using SamplingParams. Key parameters:
  • temperature (float, default 1.0): Controls randomness (0.0 = deterministic, higher = more random). Typical range: 0.1-2.0
  • top_p (float, default 1.0): Nucleus sampling - limits to tokens with cumulative probability ≤ top_p. Typical range: 0.1-1.0
  • top_k (int, default -1): Limits to top-k most probable tokens (-1 = disabled). Typical range: 1-100
  • min_p (float): Minimum token probability threshold. Typical range: 0.01-0.2
  • max_tokens (int): Maximum number of tokens to generate
  • repetition_penalty (float, default 1.0): Penalty for repeating tokens (>1.0 = discourage repetition). Typical range: 1.0-1.5
  • stop (str or list[str]): Strings that terminate generation when encountered
Create a SamplingParams object:
For a complete list of parameters, see the vLLM Sampling Parameters documentation.

Batched Generation

vLLM automatically batches multiple prompts for efficient processing. You can control batch behavior and generate responses for large datasets:

OpenAI-Compatible Server

vLLM can serve models through an OpenAI-compatible API, allowing you to use existing OpenAI client libraries.
Optional parameters:
  • --max-model-len L: Set maximum context length
  • --gpu-memory-utilization 0.9: Set GPU memory usage (0.0-1.0)

Chat Completions

Once running, you can use the OpenAI Python client or any OpenAI-compatible tool:

Vision Models

Installation for Vision Models

To use LFM Vision Models with vLLM, install the required versions:

Basic Usage

Initialize a vision model and process text and image inputs:

OpenAI-Compatible API

You can also serve vision models through the OpenAI-compatible API:
Then use the OpenAI client with image content:
For a complete working example, see the vLLM Vision Model Colab notebook.