vllm.sampling_params
Sampling parameters for text generation.
BeamSearchParams
¶
Bases: Struct
Beam search parameters for text generation.
Source code in vllm/sampling_params.py
GuidedDecodingParams
dataclass
¶
One of these fields will be used to build a logit processor.
Source code in vllm/sampling_params.py
disable_additional_properties
class-attribute
instance-attribute
¶
disable_additional_properties: bool = False
json_object
class-attribute
instance-attribute
¶
These are other options that can be set
__init__
¶
__init__(
json: Optional[Union[str, dict]] = None,
regex: Optional[str] = None,
choice: Optional[list[str]] = None,
grammar: Optional[str] = None,
json_object: Optional[bool] = None,
backend: Optional[str] = None,
backend_was_auto: bool = False,
disable_fallback: bool = False,
disable_any_whitespace: bool = False,
disable_additional_properties: bool = False,
whitespace_pattern: Optional[str] = None,
structural_tag: Optional[str] = None,
) -> None
__post_init__
¶
Validate that some fields are mutually exclusive.
Source code in vllm/sampling_params.py
_extract_backend_options
¶
Extract backend options from the backend string.
Source code in vllm/sampling_params.py
from_optional
staticmethod
¶
from_optional(
json: Optional[Union[dict, BaseModel, str]] = None,
regex: Optional[str] = None,
choice: Optional[list[str]] = None,
grammar: Optional[str] = None,
json_object: Optional[bool] = None,
backend: Optional[str] = None,
whitespace_pattern: Optional[str] = None,
structural_tag: Optional[str] = None,
) -> Optional[GuidedDecodingParams]
Source code in vllm/sampling_params.py
SamplingParams
¶
Bases: Struct
Sampling parameters for text generation.
Overall, we follow the sampling parameters from the OpenAI text completion API (https://platform.openai.com/docs/api-reference/completions/create). In addition, we support beam search, which is not supported by OpenAI.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
n
|
Number of output sequences to return for the given prompt. |
required | |
best_of
|
Number of output sequences that are generated from the prompt.
From these |
required | |
presence_penalty
|
Float that penalizes new tokens based on whether they appear in the generated text so far. Values > 0 encourage the model to use new tokens, while values < 0 encourage the model to repeat tokens. |
required | |
frequency_penalty
|
Float that penalizes new tokens based on their frequency in the generated text so far. Values > 0 encourage the model to use new tokens, while values < 0 encourage the model to repeat tokens. |
required | |
repetition_penalty
|
Float that penalizes new tokens based on whether they appear in the prompt and the generated text so far. Values > 1 encourage the model to use new tokens, while values < 1 encourage the model to repeat tokens. |
required | |
temperature
|
Float that controls the randomness of the sampling. Lower values make the model more deterministic, while higher values make the model more random. Zero means greedy sampling. |
required | |
top_p
|
Float that controls the cumulative probability of the top tokens to consider. Must be in (0, 1]. Set to 1 to consider all tokens. |
required | |
top_k
|
Integer that controls the number of top tokens to consider. Set to 0 (or -1) to consider all tokens. |
required | |
min_p
|
Float that represents the minimum probability for a token to be considered, relative to the probability of the most likely token. Must be in [0, 1]. Set to 0 to disable this. |
required | |
seed
|
Random seed to use for the generation. |
required | |
stop
|
list of strings that stop the generation when they are generated. The returned output will not contain the stop strings. |
required | |
stop_token_ids
|
list of tokens that stop the generation when they are generated. The returned output will contain the stop tokens unless the stop tokens are special tokens. |
required | |
bad_words
|
list of words that are not allowed to be generated. More precisely, only the last token of a corresponding token sequence is not allowed when the next generated token can complete the sequence. |
required | |
include_stop_str_in_output
|
Whether to include the stop strings in output text. Defaults to False. |
required | |
ignore_eos
|
Whether to ignore the EOS token and continue generating tokens after the EOS token is generated. |
required | |
max_tokens
|
Maximum number of tokens to generate per output sequence. |
required | |
min_tokens
|
Minimum number of tokens to generate per output sequence before EOS or stop_token_ids can be generated |
required | |
logprobs
|
Number of log probabilities to return per output token.
When set to None, no probability is returned. If set to a non-None
value, the result includes the log probabilities of the specified
number of most likely tokens, as well as the chosen tokens.
Note that the implementation follows the OpenAI API: The API will
always return the log probability of the sampled token, so there
may be up to |
required | |
prompt_logprobs
|
Number of log probabilities to return per prompt token. |
required | |
detokenize
|
Whether to detokenize the output. Defaults to True. |
required | |
skip_special_tokens
|
Whether to skip special tokens in the output. |
required | |
spaces_between_special_tokens
|
Whether to add spaces between special tokens in the output. Defaults to True. |
required | |
logits_processors
|
list of functions that modify logits based on previously generated tokens, and optionally prompt tokens as a first argument. |
required | |
truncate_prompt_tokens
|
If set to -1, will use the truncation size supported by the model. If set to an integer k, will use only the last k tokens from the prompt (i.e., left truncation). Defaults to None (i.e., no truncation). |
required | |
guided_decoding
|
If provided, the engine will construct a guided decoding logits processor from these parameters. Defaults to None. |
required | |
logit_bias
|
If provided, the engine will construct a logits processor that applies these logit biases. Defaults to None. |
required | |
allowed_token_ids
|
If provided, the engine will construct a logits processor which only retains scores for the given token ids. Defaults to None. |
required | |
extra_args
|
Arbitrary additional args, that can be used by custom sampling implementations, plugins, etc. Not used by any in-tree sampling implementations. |
required |
Source code in vllm/sampling_params.py
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 |
|
_all_stop_token_ids
class-attribute
instance-attribute
¶
_bad_words_token_ids
class-attribute
instance-attribute
¶
allowed_token_ids
class-attribute
instance-attribute
¶
guided_decoding
class-attribute
instance-attribute
¶
guided_decoding: Optional[GuidedDecodingParams] = None
include_stop_str_in_output
class-attribute
instance-attribute
¶
include_stop_str_in_output: bool = False
spaces_between_special_tokens
class-attribute
instance-attribute
¶
spaces_between_special_tokens: bool = True
truncate_prompt_tokens
class-attribute
instance-attribute
¶
__post_init__
¶
Source code in vllm/sampling_params.py
__repr__
¶
__repr__() -> str
Source code in vllm/sampling_params.py
_verify_args
¶
Source code in vllm/sampling_params.py
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
_verify_greedy_sampling
¶
clone
¶
clone() -> SamplingParams
Deep copy, but maybe not the LogitsProcessor objects.
LogitsProcessor objects may contain an arbitrary, nontrivial amount of data that is expensive to copy. However, if not copied, the processor needs to support parallel decoding for multiple sequences See https://github.com/vllm-project/vllm/issues/3087
Source code in vllm/sampling_params.py
from_optional
staticmethod
¶
from_optional(
n: Optional[int] = 1,
best_of: Optional[int] = None,
presence_penalty: Optional[float] = 0.0,
frequency_penalty: Optional[float] = 0.0,
repetition_penalty: Optional[float] = 1.0,
temperature: Optional[float] = 1.0,
top_p: Optional[float] = 1.0,
top_k: int = 0,
min_p: float = 0.0,
seed: Optional[int] = None,
stop: Optional[Union[str, list[str]]] = None,
stop_token_ids: Optional[list[int]] = None,
bad_words: Optional[list[str]] = None,
include_stop_str_in_output: bool = False,
ignore_eos: bool = False,
max_tokens: Optional[int] = 16,
min_tokens: int = 0,
logprobs: Optional[int] = None,
prompt_logprobs: Optional[int] = None,
detokenize: bool = True,
skip_special_tokens: bool = True,
spaces_between_special_tokens: bool = True,
logits_processors: Optional[
list[LogitsProcessor]
] = None,
truncate_prompt_tokens: Optional[
Annotated[int, Meta(ge=1)]
] = None,
output_kind: RequestOutputKind = CUMULATIVE,
guided_decoding: Optional[GuidedDecodingParams] = None,
logit_bias: Optional[
Union[dict[int, float], dict[str, float]]
] = None,
allowed_token_ids: Optional[list[int]] = None,
extra_args: Optional[dict[str, Any]] = None,
) -> SamplingParams
Source code in vllm/sampling_params.py
update_from_generation_config
¶
update_from_generation_config(
generation_config: dict[str, Any],
model_eos_token_id: Optional[int] = None,
) -> None
Update if there are non-default values from generation_config
Source code in vllm/sampling_params.py
update_from_tokenizer
¶
update_from_tokenizer(tokenizer: AnyTokenizer) -> None