Pooling Models#

vLLM also supports pooling models, including embedding, reranking and reward models.

In vLLM, pooling models implement the VllmModelForPooling interface. These models use a Pooler to extract the final hidden states of the input before returning them.

Note

We currently support pooling models primarily as a matter of convenience. As shown in the Compatibility Matrix, most vLLM features are not applicable to pooling models as they only work on the generation or decode stage, so performance may not improve as much.

For pooling models, we support the following --task options. The selected option sets the default pooler used to extract the final hidden states:

Task

Pooling Type

Normalization

Softmax

Embedding (embed)

LAST

✅︎

Classification (classify)

LAST

✅︎

Sentence Pair Scoring (score)

*

*

*

Reward Modeling (reward)

ALL

*The default pooler is always defined by the model.

Note

If the model’s implementation in vLLM defines its own pooler, the default pooler is set to that instead of the one specified in this table.

When loading Sentence Transformers models, we attempt to override the default pooler based on its Sentence Transformers configuration file (modules.json).

Tip

You can customize the model’s pooling method via the --override-pooler-config option, which takes priority over both the model’s and Sentence Transformers’s defaults.

Offline Inference#

The LLM class provides various methods for offline inference. See Engine Arguments for a list of options when initializing the model.

LLM.encode#

The encode method is available to all pooling models in vLLM. It returns the extracted hidden states directly, which is useful for reward models.

llm = LLM(model="Qwen/Qwen2.5-Math-RM-72B", task="reward")
(output,) = llm.encode("Hello, my name is")

data = output.outputs.data
print(f"Data: {data!r}")

LLM.embed#

The embed method outputs an embedding vector for each prompt. It is primarily designed for embedding models.

llm = LLM(model="intfloat/e5-mistral-7b-instruct", task="embed")
(output,) = llm.embed("Hello, my name is")

embeds = output.outputs.embedding
print(f"Embeddings: {embeds!r} (size={len(embeds)})")

A code example can be found here: examples/offline_inference/embedding.py

LLM.classify#

The classify method outputs a probability vector for each prompt. It is primarily designed for classification models.

llm = LLM(model="jason9693/Qwen2.5-1.5B-apeach", task="classify")
(output,) = llm.classify("Hello, my name is")

probs = output.outputs.probs
print(f"Class Probabilities: {probs!r} (size={len(probs)})")

A code example can be found here: examples/offline_inference/classification.py

LLM.score#

The score method outputs similarity scores between sentence pairs. It is primarily designed for cross-encoder models. These types of models serve as rerankers between candidate query-document pairs in RAG systems.

Note

vLLM can only perform the model inference component (e.g. embedding, reranking) of RAG. To handle RAG at a higher level, you should use integration frameworks such as LangChain.

llm = LLM(model="BAAI/bge-reranker-v2-m3", task="score")
(output,) = llm.score("What is the capital of France?",
                      "The capital of Brazil is Brasilia.")

score = output.outputs.score
print(f"Score: {score}")

A code example can be found here: examples/offline_inference/scoring.py

Online Serving#

Our OpenAI-Compatible Server provides endpoints that correspond to the offline APIs: