vllm.entrypoints.pooling.offline
¶
Classes:
-
PoolingOfflineMixin–Offline inference for pooling models.
PoolingOfflineMixin
¶
Bases: OfflineInferenceMixin
Offline inference for pooling models.
Methods:
-
classify–Generate class logits for each prompt.
-
embed–Generate embeddings using the model's configured pooling task.
-
encode–Apply pooling to the hidden states corresponding to the input
-
score–Generate similarity scores for all pairs
<text,text_pair>or
classify(prompts, *, pooling_params=None, use_tqdm=True, lora_request=None, tokenization_kwargs=None)
¶
Generate class logits for each prompt.
This class automatically batches the given prompts, considering the memory constraint. For the best performance, put all of your prompts into a single list and pass it to this method.
Parameters:
-
(prompts¶PromptType | Sequence[PromptType]) –The prompts to the LLM. You may pass a sequence of prompts for batch inference. See PromptType for more details about the format of each prompt.
-
(pooling_params¶PoolingParams | Sequence[PoolingParams] | None, default:None) –The pooling parameters for pooling. If None, we use the default pooling parameters.
-
(use_tqdm¶bool | Callable[..., tqdm], default:True) –If
True, shows a tqdm progress bar. If a callable (e.g.,functools.partial(tqdm, leave=False)), it is used to create the progress bar. IfFalse, no progress bar is created. -
(lora_request¶list[LoRARequest] | LoRARequest | None, default:None) –LoRA request to use for generation, if any.
-
(tokenization_kwargs¶dict[str, Any] | None, default:None) –Overrides for
tokenizer.encode.
Returns:
embed(prompts, *, use_tqdm=True, pooling_params=None, lora_request=None, tokenization_kwargs=None)
¶
Generate embeddings using the model's configured pooling task.
This class automatically batches the given prompts, considering the memory constraint. For the best performance, put all of your prompts into a single list and pass it to this method.
Parameters:
-
(prompts¶PromptType | Sequence[PromptType]) –The prompts to the LLM. You may pass a sequence of prompts for batch inference. See PromptType for more details about the format of each prompt.
-
(pooling_params¶PoolingParams | Sequence[PoolingParams] | None, default:None) –The pooling parameters for pooling. If None, we use the default pooling parameters.
-
(use_tqdm¶bool | Callable[..., tqdm], default:True) –If
True, shows a tqdm progress bar. If a callable (e.g.,functools.partial(tqdm, leave=False)), it is used to create the progress bar. IfFalse, no progress bar is created. -
(lora_request¶list[LoRARequest] | LoRARequest | None, default:None) –LoRA request to use for generation, if any.
-
(tokenization_kwargs¶dict[str, Any] | None, default:None) –Overrides for
tokenizer.encode.
Returns:
-
list[EmbeddingRequestOutput] | list[PoolingRequestOutput]–For
embed,EmbeddingRequestOutputobjects with one vector per -
list[EmbeddingRequestOutput] | list[PoolingRequestOutput]–prompt in
outputs.embedding. Fortoken_embed, -
list[EmbeddingRequestOutput] | list[PoolingRequestOutput]–PoolingRequestOutputobjects with a matrix inoutputs.data. -
list[EmbeddingRequestOutput] | list[PoolingRequestOutput]–Rows are token vectors, or chunk vectors when late chunking is
-
list[EmbeddingRequestOutput] | list[PoolingRequestOutput]–enabled. Results follow input order and preserve chunk metadata.
encode(prompts, pooling_params=None, *, use_tqdm=True, lora_request=None, pooling_task=None, tokenization_kwargs=None)
¶
Apply pooling to the hidden states corresponding to the input prompts.
This class automatically batches the given prompts, considering the memory constraint. For the best performance, put all of your prompts into a single list and pass it to this method.
Parameters:
-
(prompts¶PromptType | Sequence[PromptType] | DataPrompt) –The prompts to the LLM. You may pass a sequence of prompts for batch inference. See PromptType for more details about the format of each prompt.
-
(pooling_params¶PoolingParams | Sequence[PoolingParams] | None, default:None) –The pooling parameters for pooling. If None, we use the default pooling parameters.
-
(use_tqdm¶bool | Callable[..., tqdm], default:True) –If
True, shows a tqdm progress bar. If a callable (e.g.,functools.partial(tqdm, leave=False)), it is used to create the progress bar. IfFalse, no progress bar is created. -
(lora_request¶list[LoRARequest] | LoRARequest | None, default:None) –LoRA request to use for generation, if any.
-
(pooling_task¶PoolingTask | None, default:None) –Override the pooling task to use.
-
(tokenization_kwargs¶dict[str, Any] | None, default:None) –Overrides for
tokenizer.encode.
Returns:
-
list[PoolingRequestOutput]–A list of
PoolingRequestOutputobjects containing the -
list[PoolingRequestOutput]–pooled hidden states in the same order as the input prompts.
score(data_1, data_2, /, *, use_tqdm=True, pooling_params=None, lora_request=None, tokenization_kwargs=None, chat_template=None, chat_template_content_format='auto')
¶
Generate similarity scores for all pairs <text,text_pair> or
<multi-modal data, multi-modal data pair>.
The inputs can be 1 -> 1, 1 -> N or N -> N.
In the 1 - N case the data_1 input will be replicated N
times to pair with the data_2 inputs.
The input pairs are used to build a list of prompts for the
cross encoder model. This class automatically batches the prompts,
considering the memory constraint. For the best performance, put all
of your inputs into a single list and pass it to this method.
Supports both text and multi-modal data (images, etc.) when used with appropriate multi-modal models. For multi-modal inputs, ensure the prompt structure matches the model's expected input format.
Parameters:
-
(data_1¶ScoreInput | list[ScoreInput]) –Can be a single prompt, a list of prompts or
ScoreMultiModalParam, which can contain either text or multi-modal data. When a list, it must have the same length as thedata_2list. -
(data_2¶ScoreInput | list[ScoreInput]) –The data to pair with the query to form the input to the LLM. Can be text or multi-modal data. See PromptType for more details about the format of each prompt.
-
(pooling_params¶PoolingParams | None, default:None) –The pooling parameters for pooling. If None, we use the default pooling parameters.
-
(use_tqdm¶bool | Callable[..., tqdm], default:True) –If
True, shows a tqdm progress bar. If a callable (e.g.,functools.partial(tqdm, leave=False)), it is used to create the progress bar. IfFalse, no progress bar is created. -
(lora_request¶list[LoRARequest] | LoRARequest | None, default:None) –LoRA request to use for generation, if any.
-
(chat_template¶str | None, default:None) –The chat template to use for scoring. If None, use the chat template passed to the LLM constructor.
-
(chat_template_content_format¶ChatTemplateContentFormatOption, default:'auto') –The format of message content passed to the scoring template: "string" for plain text, "openai" for structured content blocks, or "auto" to detect from the template. Defaults to "auto".
-
(tokenization_kwargs¶dict[str, Any] | None, default:None) –Overrides for
tokenizer.encode.
Returns: