vllm.v1.structured_output.utils ¶
OutlinesVocabulary ¶
Wrapper class for outlines_core.Vocabulary
, which allows us to store a hash with the vocabulary
Source code in vllm/v1/structured_output/utils.py
__init__ ¶
Source code in vllm/v1/structured_output/utils.py
_reduced_vocabulary ¶
Create a map from vocabulary tokens to lists of equivalent token ids.
Returns:
Type | Description |
---|---|
dict[bytes, list[int]] | A Dict of token string -> equivalent token ids |
Source code in vllm/v1/structured_output/utils.py
apply_grammar_bitmask ¶
apply_grammar_bitmask(
scheduler_output: SchedulerOutput,
input_batch: InputBatch,
logits: Tensor,
device: device,
) -> None
Apply grammar bitmask to output logits of the model with xgrammar function.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scheduler_output | SchedulerOutput | The result of engine scheduling. | required |
input_batch | InputBatch | The input of model runner. | required |
logits | Tensor | The output logits of model forward. | required |
device | device | The device that model runner running on. | required |
Source code in vllm/v1/structured_output/utils.py
choice_as_grammar ¶
Source code in vllm/v1/structured_output/utils.py
convert_lark_to_ebnf ¶
Convert a Lark grammar string to EBNF format.
EBNF reference: https://github.com/ggerganov/llama.cpp/blob/master/grammars/README.md Lark grammar reference: https://lark-parser.readthedocs.io/en/latest/grammar.html
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grammar_str | str | Input grammar in Lark format | required |
Returns:
Name | Type | Description |
---|---|---|
str | str | Converted grammar in EBNF format |
Examples:
Source code in vllm/v1/structured_output/utils.py
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 |
|
get_outlines_cache ¶
Get the Cache instance to be used for index caching
Source code in vllm/v1/structured_output/utils.py
get_outlines_cache_path ¶
get_outlines_cache_path() -> str
Get the context object that contains previously-computed return values
Source code in vllm/v1/structured_output/utils.py
get_outlines_vocabulary ¶
get_outlines_vocabulary(
tokenizer: AnyTokenizer,
) -> Vocabulary
Get the Vocabulary
object for a given tokenizer.
Source code in vllm/v1/structured_output/utils.py
grammar_is_likely_lark ¶
Check if grammar appears to use Lark syntax.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
grammar_str | str | Input grammar string | required |
Returns:
Name | Type | Description |
---|---|---|
bool | bool | True if grammar appears to be in Lark format, False otherwise |
Examples: