vllm.v1.structured_output.backend_types
StructuredOutputBackend
dataclass
¶
Bases: ABC
Engine-level backend for structured output requests.
Source code in vllm/v1/structured_output/backend_types.py
allocate_token_bitmask
abstractmethod
¶
Allocates a token bitmask for the specified maximum number of sequences.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
max_num_seqs
|
int
|
The maximum number of sequences for which to allocate the bitmask. |
required |
Source code in vllm/v1/structured_output/backend_types.py
compile_grammar
abstractmethod
¶
compile_grammar(
request_type: StructuredOutputOptions, grammar_spec: str
) -> StructuredOutputGrammar
Compiles a grammar specification into a structured output grammar.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_type
|
StructuredOutputOptions
|
The type of structured output request. |
required |
grammar_spec
|
str
|
The grammar specification to compile. |
required |
Returns:
Name | Type | Description |
---|---|---|
StructuredOutputGrammar |
StructuredOutputGrammar
|
The compiled structured output grammar. |
Source code in vllm/v1/structured_output/backend_types.py
StructuredOutputGrammar
¶
Bases: ABC
Request-level backend for structured output requests.
Source code in vllm/v1/structured_output/backend_types.py
accept_tokens
abstractmethod
¶
Determines whether the provided tokens are accepted for the given request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
str
|
The unique identifier for the request. |
required |
tokens
|
list[int]
|
A list of token IDs to evaluate. |
required |
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the tokens are accepted, False otherwise. |
Source code in vllm/v1/structured_output/backend_types.py
fill_bitmask
abstractmethod
¶
is_terminated
abstractmethod
¶
is_terminated() -> bool
Checks whether the structured output process has terminated.
Returns:
Name | Type | Description |
---|---|---|
bool |
bool
|
True if the process is terminated, False otherwise. |
reset
abstractmethod
¶
rollback
abstractmethod
¶
rollback(num_tokens: int) -> None
Rolls back the state of the grammar by a specified number of tokens. Will also revert counters for the number of processed tokens.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
num_tokens
|
int
|
The number of tokens to roll back. |
required |
Source code in vllm/v1/structured_output/backend_types.py
validate_tokens
abstractmethod
¶
Validates the provided tokens against the grammar. Will not advance the FSM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tokens
|
list[int]
|
A list of token IDs to validate. |
required |
Returns:
Type | Description |
---|---|
list[int]
|
list[int]: A list of accepted token IDs. Will be a prefix of the input tokens, and empty if none are accepted. |