vllm
vLLM: a high-throughput and memory-efficient inference engine for LLMs
Modules:
Name | Description |
---|---|
adapter_commons |
|
assets |
|
attention |
|
beam_search |
|
benchmarks |
|
collect_env |
|
compilation |
|
config |
|
connections |
|
core |
|
device_allocator |
|
distributed |
|
engine |
|
entrypoints |
|
env_override |
|
envs |
|
executor |
|
forward_context |
|
inputs |
|
jsontree |
Helper functions to work with nested JSON structures. |
logger |
Logging configuration for vLLM. |
logging_utils |
|
logits_process |
|
lora |
|
model_executor |
|
multimodal |
|
outputs |
|
platforms |
|
plugins |
|
pooling_params |
|
profiler |
|
prompt_adapter |
|
ray |
|
reasoning |
|
sampling_params |
Sampling parameters for text generation. |
scalar_type |
|
scripts |
|
sequence |
Sequence and its related classes. |
spec_decode |
|
test_utils |
|
third_party |
|
tracing |
|
transformers_utils |
|
triton_utils |
|
usage |
|
utils |
|
v1 |
|
version |
|
worker |
|
MODULE_ATTRS
module-attribute
¶
MODULE_ATTRS = {
"AsyncEngineArgs": ".engine.arg_utils:AsyncEngineArgs",
"EngineArgs": ".engine.arg_utils:EngineArgs",
"AsyncLLMEngine": ".engine.async_llm_engine:AsyncLLMEngine",
"LLMEngine": ".engine.llm_engine:LLMEngine",
"LLM": ".entrypoints.llm:LLM",
"initialize_ray_cluster": ".executor.ray_utils:initialize_ray_cluster",
"PromptType": ".inputs:PromptType",
"TextPrompt": ".inputs:TextPrompt",
"TokensPrompt": ".inputs:TokensPrompt",
"ModelRegistry": ".model_executor.models:ModelRegistry",
"SamplingParams": ".sampling_params:SamplingParams",
"PoolingParams": ".pooling_params:PoolingParams",
"ClassificationOutput": ".outputs:ClassificationOutput",
"ClassificationRequestOutput": ".outputs:ClassificationRequestOutput",
"CompletionOutput": ".outputs:CompletionOutput",
"EmbeddingOutput": ".outputs:EmbeddingOutput",
"EmbeddingRequestOutput": ".outputs:EmbeddingRequestOutput",
"PoolingOutput": ".outputs:PoolingOutput",
"PoolingRequestOutput": ".outputs:PoolingRequestOutput",
"RequestOutput": ".outputs:RequestOutput",
"ScoringOutput": ".outputs:ScoringOutput",
"ScoringRequestOutput": ".outputs:ScoringRequestOutput",
}
ModelRegistry
module-attribute
¶
ModelRegistry = _ModelRegistry(
{
model_arch: _LazyRegisteredModel(
module_name=f"vllm.model_executor.models.{mod_relname}",
class_name=cls_name,
)
for (model_arch, (mod_relname, cls_name)) in items()
}
)
PromptType
module-attribute
¶
PromptType = Union[
SingletonPrompt, ExplicitEncoderDecoderPrompt
]
Set of possible schemas for an LLM input, including both decoder-only and encoder/decoder input types:
- A text prompt (
str
orTextPrompt
) - A tokenized prompt (
TokensPrompt
) - An embeddings prompt (
EmbedsPrompt
) - A single data structure containing both an encoder and a decoder prompt
(
ExplicitEncoderDecoderPrompt
)
__all__
module-attribute
¶
__all__ = [
"__version__",
"__version_tuple__",
"LLM",
"ModelRegistry",
"PromptType",
"TextPrompt",
"TokensPrompt",
"SamplingParams",
"RequestOutput",
"CompletionOutput",
"PoolingOutput",
"PoolingRequestOutput",
"EmbeddingOutput",
"EmbeddingRequestOutput",
"ClassificationOutput",
"ClassificationRequestOutput",
"ScoringOutput",
"ScoringRequestOutput",
"LLMEngine",
"EngineArgs",
"AsyncLLMEngine",
"AsyncEngineArgs",
"initialize_ray_cluster",
"PoolingParams",
]
AsyncEngineArgs
dataclass
¶
Bases: EngineArgs
Arguments for asynchronous vLLM engine.
Source code in vllm/engine/arg_utils.py
__init__
¶
__init__(
model: str = model,
served_model_name: Optional[
Union[str, List[str]]
] = served_model_name,
tokenizer: Optional[str] = tokenizer,
hf_config_path: Optional[str] = hf_config_path,
task: TaskOption = task,
skip_tokenizer_init: bool = skip_tokenizer_init,
enable_prompt_embeds: bool = enable_prompt_embeds,
tokenizer_mode: TokenizerMode = tokenizer_mode,
trust_remote_code: bool = trust_remote_code,
allowed_local_media_path: str = allowed_local_media_path,
download_dir: Optional[str] = download_dir,
load_format: str = load_format,
config_format: str = config_format,
dtype: ModelDType = dtype,
kv_cache_dtype: CacheDType = cache_dtype,
seed: Optional[int] = seed,
max_model_len: Optional[int] = max_model_len,
cuda_graph_sizes: list[int] = get_field(
SchedulerConfig, "cuda_graph_sizes"
),
distributed_executor_backend: Optional[
Union[
DistributedExecutorBackend, Type[ExecutorBase]
]
] = distributed_executor_backend,
pipeline_parallel_size: int = pipeline_parallel_size,
tensor_parallel_size: int = tensor_parallel_size,
data_parallel_size: int = data_parallel_size,
data_parallel_rank: Optional[int] = None,
data_parallel_size_local: Optional[int] = None,
data_parallel_address: Optional[str] = None,
data_parallel_rpc_port: Optional[int] = None,
data_parallel_backend: str = data_parallel_backend,
enable_expert_parallel: bool = enable_expert_parallel,
enable_eplb: bool = enable_eplb,
num_redundant_experts: int = num_redundant_experts,
eplb_window_size: int = eplb_window_size,
eplb_step_interval: int = eplb_step_interval,
eplb_log_balancedness: bool = eplb_log_balancedness,
max_parallel_loading_workers: Optional[
int
] = max_parallel_loading_workers,
block_size: Optional[BlockSize] = block_size,
enable_prefix_caching: Optional[
bool
] = enable_prefix_caching,
prefix_caching_hash_algo: PrefixCachingHashAlgo = prefix_caching_hash_algo,
disable_sliding_window: bool = disable_sliding_window,
disable_cascade_attn: bool = disable_cascade_attn,
use_v2_block_manager: bool = True,
swap_space: float = swap_space,
cpu_offload_gb: float = cpu_offload_gb,
gpu_memory_utilization: float = gpu_memory_utilization,
max_num_batched_tokens: Optional[
int
] = max_num_batched_tokens,
max_num_partial_prefills: int = max_num_partial_prefills,
max_long_partial_prefills: int = max_long_partial_prefills,
long_prefill_token_threshold: int = long_prefill_token_threshold,
max_num_seqs: Optional[int] = max_num_seqs,
max_logprobs: int = max_logprobs,
disable_log_stats: bool = False,
revision: Optional[str] = revision,
code_revision: Optional[str] = code_revision,
rope_scaling: dict[str, Any] = get_field(
ModelConfig, "rope_scaling"
),
rope_theta: Optional[float] = rope_theta,
hf_token: Optional[Union[bool, str]] = hf_token,
hf_overrides: HfOverrides = get_field(
ModelConfig, "hf_overrides"
),
tokenizer_revision: Optional[str] = tokenizer_revision,
quantization: Optional[
QuantizationMethods
] = quantization,
enforce_eager: bool = enforce_eager,
max_seq_len_to_capture: int = max_seq_len_to_capture,
disable_custom_all_reduce: bool = disable_custom_all_reduce,
limit_mm_per_prompt: dict[str, int] = get_field(
MultiModalConfig, "limit_per_prompt"
),
interleave_mm_strings: bool = interleave_mm_strings,
media_io_kwargs: dict[str, dict[str, Any]] = get_field(
MultiModalConfig, "media_io_kwargs"
),
mm_processor_kwargs: Optional[
Dict[str, Any]
] = mm_processor_kwargs,
disable_mm_preprocessor_cache: bool = disable_mm_preprocessor_cache,
enable_lora: bool = False,
enable_lora_bias: bool = bias_enabled,
max_loras: int = max_loras,
max_lora_rank: int = max_lora_rank,
default_mm_loras: Optional[
Dict[str, str]
] = default_mm_loras,
fully_sharded_loras: bool = fully_sharded_loras,
max_cpu_loras: Optional[int] = max_cpu_loras,
lora_dtype: Optional[Union[str, dtype]] = lora_dtype,
lora_extra_vocab_size: int = lora_extra_vocab_size,
long_lora_scaling_factors: Optional[
tuple[float, ...]
] = long_lora_scaling_factors,
enable_prompt_adapter: bool = False,
max_prompt_adapters: int = max_prompt_adapters,
max_prompt_adapter_token: int = max_prompt_adapter_token,
device: Device = device,
num_scheduler_steps: int = num_scheduler_steps,
multi_step_stream_outputs: bool = multi_step_stream_outputs,
ray_workers_use_nsight: bool = ray_workers_use_nsight,
num_gpu_blocks_override: Optional[
int
] = num_gpu_blocks_override,
num_lookahead_slots: int = num_lookahead_slots,
model_loader_extra_config: dict = get_field(
LoadConfig, "model_loader_extra_config"
),
ignore_patterns: Optional[
Union[str, List[str]]
] = ignore_patterns,
preemption_mode: Optional[str] = preemption_mode,
scheduler_delay_factor: float = delay_factor,
enable_chunked_prefill: Optional[
bool
] = enable_chunked_prefill,
disable_chunked_mm_input: bool = disable_chunked_mm_input,
disable_hybrid_kv_cache_manager: bool = disable_hybrid_kv_cache_manager,
guided_decoding_backend: GuidedDecodingBackend = backend,
guided_decoding_disable_fallback: bool = disable_fallback,
guided_decoding_disable_any_whitespace: bool = disable_any_whitespace,
guided_decoding_disable_additional_properties: bool = disable_additional_properties,
logits_processor_pattern: Optional[
str
] = logits_processor_pattern,
speculative_config: Optional[Dict[str, Any]] = None,
show_hidden_metrics_for_version: Optional[
str
] = show_hidden_metrics_for_version,
otlp_traces_endpoint: Optional[
str
] = otlp_traces_endpoint,
collect_detailed_traces: Optional[
list[DetailedTraceModules]
] = collect_detailed_traces,
disable_async_output_proc: bool = not use_async_output_proc,
scheduling_policy: SchedulerPolicy = policy,
scheduler_cls: Union[str, Type[object]] = scheduler_cls,
override_neuron_config: dict[str, Any] = get_field(
ModelConfig, "override_neuron_config"
),
override_pooler_config: Optional[
Union[dict, PoolerConfig]
] = override_pooler_config,
compilation_config: CompilationConfig = get_field(
VllmConfig, "compilation_config"
),
worker_cls: str = worker_cls,
worker_extension_cls: str = worker_extension_cls,
kv_transfer_config: Optional[KVTransferConfig] = None,
kv_events_config: Optional[KVEventsConfig] = None,
generation_config: str = generation_config,
enable_sleep_mode: bool = enable_sleep_mode,
override_generation_config: dict[str, Any] = get_field(
ModelConfig, "override_generation_config"
),
model_impl: str = model_impl,
override_attention_dtype: str = override_attention_dtype,
calculate_kv_scales: bool = calculate_kv_scales,
additional_config: dict[str, Any] = get_field(
VllmConfig, "additional_config"
),
reasoning_parser: str = reasoning_backend,
use_tqdm_on_load: bool = use_tqdm_on_load,
pt_load_map_location: str = pt_load_map_location,
enable_multimodal_encoder_data_parallel: bool = enable_multimodal_encoder_data_parallel,
async_scheduling: bool = async_scheduling,
disable_log_requests: bool = False,
) -> None
add_cli_args
staticmethod
¶
add_cli_args(
parser: FlexibleArgumentParser,
async_args_only: bool = False,
) -> FlexibleArgumentParser
Source code in vllm/engine/arg_utils.py
AsyncLLMEngine
¶
Bases: EngineClient
An asynchronous wrapper for LLMEngine
.
This class is used to wrap the LLMEngine
class to
make it asynchronous. It uses asyncio to create a background loop that keeps
processing incoming requests. The LLMEngine
is kicked
by the generate method when there are requests in the waiting queue. The
generate method yields the outputs from the LLMEngine
to the caller.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
log_requests
|
bool
|
Whether to log the requests. |
True
|
start_engine_loop
|
bool
|
If True, the background task to run the engine will be automatically started in the generate call. |
True
|
*args
|
Arguments for |
()
|
|
**kwargs
|
Arguments for |
{}
|
Source code in vllm/engine/async_llm_engine.py
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 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
|
_engine_class
class-attribute
instance-attribute
¶
_engine_class: Type[_AsyncLLMEngine] = _AsyncLLMEngine
use_process_request_outputs_callback
instance-attribute
¶
__del__
¶
__init__
¶
Source code in vllm/engine/async_llm_engine.py
_abort
¶
_abort(request_id: str) -> None
Abort a request.
Abort a submitted request. If the request is finished or not found, this method will be a no-op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
str
|
The unique id of the request. |
required |
Source code in vllm/engine/async_llm_engine.py
_engine_abort
async
¶
_get_executor_cls
classmethod
¶
_get_executor_cls(
engine_config: VllmConfig,
) -> Type[ExecutorBase]
abort
async
¶
abort(request_id: str) -> None
Abort a request.
Abort a submitted request. If the request is finished or not found, this method will be a no-op.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
str
|
The unique id of the request. |
required |
Source code in vllm/engine/async_llm_engine.py
add_logger
¶
add_logger(
logger_name: str, logger: StatLoggerBase
) -> None
add_lora
async
¶
add_lora(lora_request: LoRARequest) -> None
add_request
async
¶
add_request(
request_id: str,
prompt: PromptType,
params: Union[SamplingParams, PoolingParams],
arrival_time: Optional[float] = None,
lora_request: Optional[LoRARequest] = None,
trace_headers: Optional[Mapping[str, str]] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
priority: int = 0,
data_parallel_rank: Optional[int] = None,
) -> AsyncGenerator[
Union[RequestOutput, PoolingRequestOutput], None
]
Source code in vllm/engine/async_llm_engine.py
check_health
async
¶
Raises an error if engine is unhealthy.
Source code in vllm/engine/async_llm_engine.py
collective_rpc
async
¶
collective_rpc(
method: str,
timeout: Optional[float] = None,
args: tuple = (),
kwargs: Optional[dict] = None,
)
Perform a collective RPC call to the given path.
Source code in vllm/engine/async_llm_engine.py
do_log_stats
async
¶
do_log_stats(
scheduler_outputs: Optional[SchedulerOutputs] = None,
model_output: Optional[List[SamplerOutput]] = None,
) -> None
encode
async
¶
encode(
prompt: PromptType,
pooling_params: PoolingParams,
request_id: str,
lora_request: Optional[LoRARequest] = None,
trace_headers: Optional[Mapping[str, str]] = None,
priority: int = 0,
) -> AsyncGenerator[PoolingRequestOutput, None]
Generate outputs for a request from a pooling model.
Generate outputs for a request. This method is a coroutine. It adds the request into the waiting queue of the LLMEngine and streams the outputs from the LLMEngine to the caller.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
PromptType
|
The prompt to the LLM. See
|
required |
pooling_params
|
PoolingParams
|
The pooling parameters of the request. |
required |
request_id
|
str
|
The unique id of the request. |
required |
lora_request
|
Optional[LoRARequest]
|
LoRA request to use for generation, if any. |
None
|
trace_headers
|
Optional[Mapping[str, str]]
|
OpenTelemetry trace headers. |
None
|
priority
|
int
|
The priority of the request. Only applicable with priority scheduling. |
0
|
Yields:
Type | Description |
---|---|
AsyncGenerator[PoolingRequestOutput, None]
|
The output |
AsyncGenerator[PoolingRequestOutput, None]
|
for the request. |
Details
- If the engine is not running, start the background loop,
which iteratively invokes
vllm.engine.async_llm_engine.AsyncLLMEngine.engine_step
to process the waiting requests. - Add the request to the engine's
RequestTracker
. On the next background loop, this request will be sent to the underlying engine. Also, a correspondingAsyncStream
will be created. - Wait for the request outputs from
AsyncStream
and yield them.
Example:
# Please refer to entrypoints/api_server.py for
# the complete example.
# initialize the engine and the example input
# note that engine_args here is AsyncEngineArgs instance
engine = AsyncLLMEngine.from_engine_args(engine_args)
example_input = {
"input": "What is LLM?",
"request_id": 0,
}
# start the generation
results_generator = engine.encode(
example_input["input"],
PoolingParams(),
example_input["request_id"])
# get the results
final_output = None
async for request_output in results_generator:
if await request.is_disconnected():
# Abort the request if the client disconnects.
await engine.abort(request_id)
# Return or raise an error
...
final_output = request_output
# Process and return the final output
...
Source code in vllm/engine/async_llm_engine.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
|
engine_step
async
¶
Kick the engine to process the waiting requests.
Returns True if there are in-progress requests.
Source code in vllm/engine/async_llm_engine.py
from_engine_args
classmethod
¶
from_engine_args(
engine_args: AsyncEngineArgs,
start_engine_loop: bool = True,
usage_context: UsageContext = ENGINE_CONTEXT,
stat_loggers: Optional[
Dict[str, StatLoggerBase]
] = None,
) -> AsyncLLMEngine
Creates an async LLM engine from the engine arguments.
Source code in vllm/engine/async_llm_engine.py
from_vllm_config
classmethod
¶
from_vllm_config(
vllm_config: VllmConfig,
start_engine_loop: bool = True,
usage_context: UsageContext = ENGINE_CONTEXT,
stat_loggers: Optional[
dict[str, StatLoggerBase]
] = None,
disable_log_requests: bool = False,
disable_log_stats: bool = False,
) -> AsyncLLMEngine
Create an AsyncLLMEngine from the EngineArgs.
Source code in vllm/engine/async_llm_engine.py
generate
async
¶
generate(
prompt: PromptType,
sampling_params: SamplingParams,
request_id: str,
lora_request: Optional[LoRARequest] = None,
trace_headers: Optional[Mapping[str, str]] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
priority: int = 0,
data_parallel_rank: Optional[int] = None,
) -> AsyncGenerator[RequestOutput, None]
Generate outputs for a request.
Generate outputs for a request. This method is a coroutine. It adds the request into the waiting queue of the LLMEngine and streams the outputs from the LLMEngine to the caller.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt
|
PromptType
|
The prompt to the LLM. See
|
required |
sampling_params
|
SamplingParams
|
The sampling parameters of the request. |
required |
request_id
|
str
|
The unique id of the request. |
required |
lora_request
|
Optional[LoRARequest]
|
LoRA request to use for generation, if any. |
None
|
trace_headers
|
Optional[Mapping[str, str]]
|
OpenTelemetry trace headers. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
Prompt Adapter request to use for generation, if any. |
None
|
priority
|
int
|
The priority of the request. Only applicable with priority scheduling. |
0
|
data_parallel_rank
|
Optional[int]
|
The (global) data parallel rank that must handle this request. Only applicable if DP is enabled. |
None
|
Yields:
The output RequestOutput
objects from the LLMEngine
for the request.
Details
- If the engine is not running, start the background loop,
which iteratively invokes
engine_step
to process the waiting requests. - Add the request to the engine's
RequestTracker
. On the next background loop, this request will be sent to the underlying engine. Also, a correspondingAsyncStream
will be created. - Wait for the request outputs from
AsyncStream
and yield them.
Example
Please refer to entrypoints/api_server.py for¶
the complete example.¶
initialize the engine and the example input¶
note that engine_args here is AsyncEngineArgs instance¶
engine = AsyncLLMEngine.from_engine_args(engine_args) example_input = { "prompt": "What is LLM?", "stream": False, # assume the non-streaming case "temperature": 0.0, "request_id": 0, }
start the generation¶
results_generator = engine.generate( example_input["prompt"], SamplingParams(temperature=example_input["temperature"]), example_input["request_id"])
get the results¶
final_output = None async for request_output in results_generator: if await request.is_disconnected(): # Abort the request if the client disconnects. await engine.abort(request_id) # Return or raise an error ... final_output = request_output
Process and return the final output¶
...
Source code in vllm/engine/async_llm_engine.py
896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 |
|
get_decoding_config
async
¶
get_decoding_config() -> DecodingConfig
get_input_preprocessor
async
¶
get_input_preprocessor() -> InputPreprocessor
get_lora_config
async
¶
get_lora_config() -> LoRAConfig
get_model_config
async
¶
get_model_config() -> ModelConfig
get_parallel_config
async
¶
get_parallel_config() -> ParallelConfig
get_scheduler_config
async
¶
get_scheduler_config() -> SchedulerConfig
get_tokenizer
async
¶
get_tokenizer(
lora_request: Optional[LoRARequest] = None,
) -> AnyTokenizer
get_vllm_config
async
¶
get_vllm_config() -> VllmConfig
process_request_outputs
¶
process_request_outputs(request_outputs) -> bool
Source code in vllm/engine/async_llm_engine.py
reset_mm_cache
async
¶
reset_prefix_cache
async
¶
run_engine_loop
async
staticmethod
¶
run_engine_loop(engine_ref: ReferenceType)
We use a weakref to the engine so that the running loop doesn't prevent the engine being garbage collected.
Source code in vllm/engine/async_llm_engine.py
shutdown_background_loop
¶
Shut down the background loop.
This method needs to be called during cleanup to remove
references to self
and properly GC the resources held
by the async LLM engine (e.g., the executors as well as
their resources).
Source code in vllm/engine/async_llm_engine.py
start_background_loop
¶
Start the background loop.
Source code in vllm/engine/async_llm_engine.py
start_profile
async
¶
stop_profile
async
¶
ClassificationOutput
dataclass
¶
The output data of one classification output of a request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
probs
|
list[float]
|
The probability vector, which is a list of floats. |
required |
Source code in vllm/outputs.py
ClassificationRequestOutput
¶
Bases: PoolingRequestOutput[ClassificationOutput]
Source code in vllm/outputs.py
from_base
staticmethod
¶
from_base(request_output: PoolingRequestOutput)
Source code in vllm/outputs.py
CompletionOutput
dataclass
¶
The output data of one completion output of a request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index
|
int
|
The index of the output in the request. |
required |
text
|
str
|
The generated output text. |
required |
token_ids
|
Sequence[int]
|
The token IDs of the generated output text. |
required |
cumulative_logprob
|
Optional[float]
|
The cumulative log probability of the generated output text. |
required |
logprobs
|
Optional[SampleLogprobs]
|
The log probabilities of the top probability words at each position if the logprobs are requested. |
required |
finish_reason
|
Optional[str]
|
The reason why the sequence is finished. |
None
|
stop_reason
|
Union[int, str, None]
|
The stop string or token id that caused the completion to stop, None if the completion finished for some other reason including encountering the EOS token. |
None
|
lora_request
|
Optional[LoRARequest]
|
The LoRA request that was used to generate the output. |
None
|
Source code in vllm/outputs.py
__init__
¶
__init__(
index: int,
text: str,
token_ids: Sequence[int],
cumulative_logprob: Optional[float],
logprobs: Optional[SampleLogprobs],
finish_reason: Optional[str] = None,
stop_reason: Union[int, str, None] = None,
lora_request: Optional[LoRARequest] = None,
) -> None
EmbeddingOutput
dataclass
¶
The output data of one embedding output of a request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
embedding
|
list[float]
|
The embedding vector, which is a list of floats. |
required |
Source code in vllm/outputs.py
from_base
staticmethod
¶
from_base(pooling_output: PoolingOutput)
EmbeddingRequestOutput
¶
Bases: PoolingRequestOutput[EmbeddingOutput]
Source code in vllm/outputs.py
from_base
staticmethod
¶
from_base(request_output: PoolingRequestOutput)
Source code in vllm/outputs.py
EngineArgs
dataclass
¶
Arguments for vLLM engine.
Source code in vllm/engine/arg_utils.py
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 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 |
|
additional_config
class-attribute
instance-attribute
¶
additional_config: dict[str, Any] = get_field(
VllmConfig, "additional_config"
)
allowed_local_media_path
class-attribute
instance-attribute
¶
allowed_local_media_path: str = allowed_local_media_path
calculate_kv_scales
class-attribute
instance-attribute
¶
calculate_kv_scales: bool = calculate_kv_scales
collect_detailed_traces
class-attribute
instance-attribute
¶
collect_detailed_traces: Optional[
list[DetailedTraceModules]
] = collect_detailed_traces
compilation_config
class-attribute
instance-attribute
¶
compilation_config: CompilationConfig = get_field(
VllmConfig, "compilation_config"
)
cuda_graph_sizes
class-attribute
instance-attribute
¶
cuda_graph_sizes: list[int] = get_field(
SchedulerConfig, "cuda_graph_sizes"
)
data_parallel_address
class-attribute
instance-attribute
¶
data_parallel_backend
class-attribute
instance-attribute
¶
data_parallel_backend: str = data_parallel_backend
data_parallel_rpc_port
class-attribute
instance-attribute
¶
data_parallel_size
class-attribute
instance-attribute
¶
data_parallel_size: int = data_parallel_size
data_parallel_size_local
class-attribute
instance-attribute
¶
default_mm_loras
class-attribute
instance-attribute
¶
default_mm_loras: Optional[Dict[str, str]] = (
default_mm_loras
)
disable_async_output_proc
class-attribute
instance-attribute
¶
disable_async_output_proc: bool = not use_async_output_proc
disable_cascade_attn
class-attribute
instance-attribute
¶
disable_cascade_attn: bool = disable_cascade_attn
disable_chunked_mm_input
class-attribute
instance-attribute
¶
disable_chunked_mm_input: bool = disable_chunked_mm_input
disable_custom_all_reduce
class-attribute
instance-attribute
¶
disable_custom_all_reduce: bool = disable_custom_all_reduce
disable_hybrid_kv_cache_manager
class-attribute
instance-attribute
¶
disable_hybrid_kv_cache_manager: bool = (
disable_hybrid_kv_cache_manager
)
disable_mm_preprocessor_cache
class-attribute
instance-attribute
¶
disable_mm_preprocessor_cache: bool = (
disable_mm_preprocessor_cache
)
disable_sliding_window
class-attribute
instance-attribute
¶
disable_sliding_window: bool = disable_sliding_window
distributed_executor_backend
class-attribute
instance-attribute
¶
distributed_executor_backend: Optional[
Union[DistributedExecutorBackend, Type[ExecutorBase]]
] = distributed_executor_backend
enable_chunked_prefill
class-attribute
instance-attribute
¶
enable_chunked_prefill: Optional[bool] = (
enable_chunked_prefill
)
enable_expert_parallel
class-attribute
instance-attribute
¶
enable_expert_parallel: bool = enable_expert_parallel
enable_multimodal_encoder_data_parallel
class-attribute
instance-attribute
¶
enable_multimodal_encoder_data_parallel: bool = (
enable_multimodal_encoder_data_parallel
)
enable_prefix_caching
class-attribute
instance-attribute
¶
enable_prefix_caching: Optional[bool] = (
enable_prefix_caching
)
enable_prompt_embeds
class-attribute
instance-attribute
¶
enable_prompt_embeds: bool = enable_prompt_embeds
eplb_log_balancedness
class-attribute
instance-attribute
¶
eplb_log_balancedness: bool = eplb_log_balancedness
eplb_step_interval
class-attribute
instance-attribute
¶
eplb_step_interval: int = eplb_step_interval
fully_sharded_loras
class-attribute
instance-attribute
¶
fully_sharded_loras: bool = fully_sharded_loras
gpu_memory_utilization
class-attribute
instance-attribute
¶
gpu_memory_utilization: float = gpu_memory_utilization
guided_decoding_backend
class-attribute
instance-attribute
¶
guided_decoding_backend: GuidedDecodingBackend = backend
guided_decoding_disable_additional_properties
class-attribute
instance-attribute
¶
guided_decoding_disable_additional_properties: bool = (
disable_additional_properties
)
guided_decoding_disable_any_whitespace
class-attribute
instance-attribute
¶
guided_decoding_disable_any_whitespace: bool = (
disable_any_whitespace
)
guided_decoding_disable_fallback
class-attribute
instance-attribute
¶
guided_decoding_disable_fallback: bool = disable_fallback
hf_overrides
class-attribute
instance-attribute
¶
hf_overrides: HfOverrides = get_field(
ModelConfig, "hf_overrides"
)
ignore_patterns
class-attribute
instance-attribute
¶
interleave_mm_strings
class-attribute
instance-attribute
¶
interleave_mm_strings: bool = interleave_mm_strings
kv_events_config
class-attribute
instance-attribute
¶
kv_events_config: Optional[KVEventsConfig] = None
kv_transfer_config
class-attribute
instance-attribute
¶
kv_transfer_config: Optional[KVTransferConfig] = None
limit_mm_per_prompt
class-attribute
instance-attribute
¶
limit_mm_per_prompt: dict[str, int] = get_field(
MultiModalConfig, "limit_per_prompt"
)
logits_processor_pattern
class-attribute
instance-attribute
¶
logits_processor_pattern: Optional[str] = (
logits_processor_pattern
)
long_lora_scaling_factors
class-attribute
instance-attribute
¶
long_lora_scaling_factors: Optional[tuple[float, ...]] = (
long_lora_scaling_factors
)
long_prefill_token_threshold
class-attribute
instance-attribute
¶
long_prefill_token_threshold: int = (
long_prefill_token_threshold
)
lora_dtype
class-attribute
instance-attribute
¶
lora_dtype: Optional[Union[str, dtype]] = lora_dtype
lora_extra_vocab_size
class-attribute
instance-attribute
¶
lora_extra_vocab_size: int = lora_extra_vocab_size
max_long_partial_prefills
class-attribute
instance-attribute
¶
max_long_partial_prefills: int = max_long_partial_prefills
max_num_batched_tokens
class-attribute
instance-attribute
¶
max_num_batched_tokens: Optional[int] = (
max_num_batched_tokens
)
max_num_partial_prefills
class-attribute
instance-attribute
¶
max_num_partial_prefills: int = max_num_partial_prefills
max_parallel_loading_workers
class-attribute
instance-attribute
¶
max_parallel_loading_workers: Optional[int] = (
max_parallel_loading_workers
)
max_prompt_adapter_token
class-attribute
instance-attribute
¶
max_prompt_adapter_token: int = max_prompt_adapter_token
max_prompt_adapters
class-attribute
instance-attribute
¶
max_prompt_adapters: int = max_prompt_adapters
max_seq_len_to_capture
class-attribute
instance-attribute
¶
max_seq_len_to_capture: int = max_seq_len_to_capture
media_io_kwargs
class-attribute
instance-attribute
¶
mm_processor_kwargs
class-attribute
instance-attribute
¶
mm_processor_kwargs: Optional[Dict[str, Any]] = (
mm_processor_kwargs
)
model_loader_extra_config
class-attribute
instance-attribute
¶
model_loader_extra_config: dict = get_field(
LoadConfig, "model_loader_extra_config"
)
multi_step_stream_outputs
class-attribute
instance-attribute
¶
multi_step_stream_outputs: bool = multi_step_stream_outputs
num_gpu_blocks_override
class-attribute
instance-attribute
¶
num_gpu_blocks_override: Optional[int] = (
num_gpu_blocks_override
)
num_lookahead_slots
class-attribute
instance-attribute
¶
num_lookahead_slots: int = num_lookahead_slots
num_redundant_experts
class-attribute
instance-attribute
¶
num_redundant_experts: int = num_redundant_experts
num_scheduler_steps
class-attribute
instance-attribute
¶
num_scheduler_steps: int = num_scheduler_steps
otlp_traces_endpoint
class-attribute
instance-attribute
¶
otlp_traces_endpoint: Optional[str] = otlp_traces_endpoint
override_attention_dtype
class-attribute
instance-attribute
¶
override_attention_dtype: str = override_attention_dtype
override_generation_config
class-attribute
instance-attribute
¶
override_generation_config: dict[str, Any] = get_field(
ModelConfig, "override_generation_config"
)
override_neuron_config
class-attribute
instance-attribute
¶
override_neuron_config: dict[str, Any] = get_field(
ModelConfig, "override_neuron_config"
)
override_pooler_config
class-attribute
instance-attribute
¶
override_pooler_config: Optional[
Union[dict, PoolerConfig]
] = override_pooler_config
pipeline_parallel_size
class-attribute
instance-attribute
¶
pipeline_parallel_size: int = pipeline_parallel_size
preemption_mode
class-attribute
instance-attribute
¶
preemption_mode: Optional[str] = preemption_mode
prefix_caching_hash_algo
class-attribute
instance-attribute
¶
prefix_caching_hash_algo: PrefixCachingHashAlgo = (
prefix_caching_hash_algo
)
pt_load_map_location
class-attribute
instance-attribute
¶
pt_load_map_location: str = pt_load_map_location
quantization
class-attribute
instance-attribute
¶
quantization: Optional[QuantizationMethods] = quantization
ray_workers_use_nsight
class-attribute
instance-attribute
¶
ray_workers_use_nsight: bool = ray_workers_use_nsight
rope_scaling
class-attribute
instance-attribute
¶
rope_scaling: dict[str, Any] = get_field(
ModelConfig, "rope_scaling"
)
scheduler_cls
class-attribute
instance-attribute
¶
scheduler_cls: Union[str, Type[object]] = scheduler_cls
scheduler_delay_factor
class-attribute
instance-attribute
¶
scheduler_delay_factor: float = delay_factor
served_model_name
class-attribute
instance-attribute
¶
show_hidden_metrics_for_version
class-attribute
instance-attribute
¶
show_hidden_metrics_for_version: Optional[str] = (
show_hidden_metrics_for_version
)
skip_tokenizer_init
class-attribute
instance-attribute
¶
skip_tokenizer_init: bool = skip_tokenizer_init
speculative_config
class-attribute
instance-attribute
¶
tensor_parallel_size
class-attribute
instance-attribute
¶
tensor_parallel_size: int = tensor_parallel_size
tokenizer_revision
class-attribute
instance-attribute
¶
tokenizer_revision: Optional[str] = tokenizer_revision
worker_extension_cls
class-attribute
instance-attribute
¶
worker_extension_cls: str = worker_extension_cls
__init__
¶
__init__(
model: str = model,
served_model_name: Optional[
Union[str, List[str]]
] = served_model_name,
tokenizer: Optional[str] = tokenizer,
hf_config_path: Optional[str] = hf_config_path,
task: TaskOption = task,
skip_tokenizer_init: bool = skip_tokenizer_init,
enable_prompt_embeds: bool = enable_prompt_embeds,
tokenizer_mode: TokenizerMode = tokenizer_mode,
trust_remote_code: bool = trust_remote_code,
allowed_local_media_path: str = allowed_local_media_path,
download_dir: Optional[str] = download_dir,
load_format: str = load_format,
config_format: str = config_format,
dtype: ModelDType = dtype,
kv_cache_dtype: CacheDType = cache_dtype,
seed: Optional[int] = seed,
max_model_len: Optional[int] = max_model_len,
cuda_graph_sizes: list[int] = get_field(
SchedulerConfig, "cuda_graph_sizes"
),
distributed_executor_backend: Optional[
Union[
DistributedExecutorBackend, Type[ExecutorBase]
]
] = distributed_executor_backend,
pipeline_parallel_size: int = pipeline_parallel_size,
tensor_parallel_size: int = tensor_parallel_size,
data_parallel_size: int = data_parallel_size,
data_parallel_rank: Optional[int] = None,
data_parallel_size_local: Optional[int] = None,
data_parallel_address: Optional[str] = None,
data_parallel_rpc_port: Optional[int] = None,
data_parallel_backend: str = data_parallel_backend,
enable_expert_parallel: bool = enable_expert_parallel,
enable_eplb: bool = enable_eplb,
num_redundant_experts: int = num_redundant_experts,
eplb_window_size: int = eplb_window_size,
eplb_step_interval: int = eplb_step_interval,
eplb_log_balancedness: bool = eplb_log_balancedness,
max_parallel_loading_workers: Optional[
int
] = max_parallel_loading_workers,
block_size: Optional[BlockSize] = block_size,
enable_prefix_caching: Optional[
bool
] = enable_prefix_caching,
prefix_caching_hash_algo: PrefixCachingHashAlgo = prefix_caching_hash_algo,
disable_sliding_window: bool = disable_sliding_window,
disable_cascade_attn: bool = disable_cascade_attn,
use_v2_block_manager: bool = True,
swap_space: float = swap_space,
cpu_offload_gb: float = cpu_offload_gb,
gpu_memory_utilization: float = gpu_memory_utilization,
max_num_batched_tokens: Optional[
int
] = max_num_batched_tokens,
max_num_partial_prefills: int = max_num_partial_prefills,
max_long_partial_prefills: int = max_long_partial_prefills,
long_prefill_token_threshold: int = long_prefill_token_threshold,
max_num_seqs: Optional[int] = max_num_seqs,
max_logprobs: int = max_logprobs,
disable_log_stats: bool = False,
revision: Optional[str] = revision,
code_revision: Optional[str] = code_revision,
rope_scaling: dict[str, Any] = get_field(
ModelConfig, "rope_scaling"
),
rope_theta: Optional[float] = rope_theta,
hf_token: Optional[Union[bool, str]] = hf_token,
hf_overrides: HfOverrides = get_field(
ModelConfig, "hf_overrides"
),
tokenizer_revision: Optional[str] = tokenizer_revision,
quantization: Optional[
QuantizationMethods
] = quantization,
enforce_eager: bool = enforce_eager,
max_seq_len_to_capture: int = max_seq_len_to_capture,
disable_custom_all_reduce: bool = disable_custom_all_reduce,
limit_mm_per_prompt: dict[str, int] = get_field(
MultiModalConfig, "limit_per_prompt"
),
interleave_mm_strings: bool = interleave_mm_strings,
media_io_kwargs: dict[str, dict[str, Any]] = get_field(
MultiModalConfig, "media_io_kwargs"
),
mm_processor_kwargs: Optional[
Dict[str, Any]
] = mm_processor_kwargs,
disable_mm_preprocessor_cache: bool = disable_mm_preprocessor_cache,
enable_lora: bool = False,
enable_lora_bias: bool = bias_enabled,
max_loras: int = max_loras,
max_lora_rank: int = max_lora_rank,
default_mm_loras: Optional[
Dict[str, str]
] = default_mm_loras,
fully_sharded_loras: bool = fully_sharded_loras,
max_cpu_loras: Optional[int] = max_cpu_loras,
lora_dtype: Optional[Union[str, dtype]] = lora_dtype,
lora_extra_vocab_size: int = lora_extra_vocab_size,
long_lora_scaling_factors: Optional[
tuple[float, ...]
] = long_lora_scaling_factors,
enable_prompt_adapter: bool = False,
max_prompt_adapters: int = max_prompt_adapters,
max_prompt_adapter_token: int = max_prompt_adapter_token,
device: Device = device,
num_scheduler_steps: int = num_scheduler_steps,
multi_step_stream_outputs: bool = multi_step_stream_outputs,
ray_workers_use_nsight: bool = ray_workers_use_nsight,
num_gpu_blocks_override: Optional[
int
] = num_gpu_blocks_override,
num_lookahead_slots: int = num_lookahead_slots,
model_loader_extra_config: dict = get_field(
LoadConfig, "model_loader_extra_config"
),
ignore_patterns: Optional[
Union[str, List[str]]
] = ignore_patterns,
preemption_mode: Optional[str] = preemption_mode,
scheduler_delay_factor: float = delay_factor,
enable_chunked_prefill: Optional[
bool
] = enable_chunked_prefill,
disable_chunked_mm_input: bool = disable_chunked_mm_input,
disable_hybrid_kv_cache_manager: bool = disable_hybrid_kv_cache_manager,
guided_decoding_backend: GuidedDecodingBackend = backend,
guided_decoding_disable_fallback: bool = disable_fallback,
guided_decoding_disable_any_whitespace: bool = disable_any_whitespace,
guided_decoding_disable_additional_properties: bool = disable_additional_properties,
logits_processor_pattern: Optional[
str
] = logits_processor_pattern,
speculative_config: Optional[Dict[str, Any]] = None,
show_hidden_metrics_for_version: Optional[
str
] = show_hidden_metrics_for_version,
otlp_traces_endpoint: Optional[
str
] = otlp_traces_endpoint,
collect_detailed_traces: Optional[
list[DetailedTraceModules]
] = collect_detailed_traces,
disable_async_output_proc: bool = not use_async_output_proc,
scheduling_policy: SchedulerPolicy = policy,
scheduler_cls: Union[str, Type[object]] = scheduler_cls,
override_neuron_config: dict[str, Any] = get_field(
ModelConfig, "override_neuron_config"
),
override_pooler_config: Optional[
Union[dict, PoolerConfig]
] = override_pooler_config,
compilation_config: CompilationConfig = get_field(
VllmConfig, "compilation_config"
),
worker_cls: str = worker_cls,
worker_extension_cls: str = worker_extension_cls,
kv_transfer_config: Optional[KVTransferConfig] = None,
kv_events_config: Optional[KVEventsConfig] = None,
generation_config: str = generation_config,
enable_sleep_mode: bool = enable_sleep_mode,
override_generation_config: dict[str, Any] = get_field(
ModelConfig, "override_generation_config"
),
model_impl: str = model_impl,
override_attention_dtype: str = override_attention_dtype,
calculate_kv_scales: bool = calculate_kv_scales,
additional_config: dict[str, Any] = get_field(
VllmConfig, "additional_config"
),
reasoning_parser: str = reasoning_backend,
use_tqdm_on_load: bool = use_tqdm_on_load,
pt_load_map_location: str = pt_load_map_location,
enable_multimodal_encoder_data_parallel: bool = enable_multimodal_encoder_data_parallel,
async_scheduling: bool = async_scheduling,
) -> None
__post_init__
¶
Source code in vllm/engine/arg_utils.py
_is_v1_supported_oracle
¶
_is_v1_supported_oracle(model_config: ModelConfig) -> bool
Oracle for whether to use V0 or V1 Engine by default.
Source code in vllm/engine/arg_utils.py
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 |
|
_set_default_args_v0
¶
_set_default_args_v0(model_config: ModelConfig) -> None
Set Default Arguments for V0 Engine.
Source code in vllm/engine/arg_utils.py
1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 |
|
_set_default_args_v1
¶
_set_default_args_v1(
usage_context: UsageContext, model_config: ModelConfig
) -> None
Set Default Arguments for V1 Engine.
Source code in vllm/engine/arg_utils.py
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 |
|
add_cli_args
staticmethod
¶
add_cli_args(
parser: FlexibleArgumentParser,
) -> FlexibleArgumentParser
Shared CLI arguments for vLLM engine.
Source code in vllm/engine/arg_utils.py
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 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 |
|
create_engine_config
¶
create_engine_config(
usage_context: Optional[UsageContext] = None,
) -> VllmConfig
Create the VllmConfig.
NOTE: for autoselection of V0 vs V1 engine, we need to create the ModelConfig first, since ModelConfig's attrs (e.g. the model arch) are needed to make the decision.
This function set VLLM_USE_V1=X if VLLM_USE_V1 is unspecified by the user.
If VLLM_USE_V1 is specified by the user but the VllmConfig is incompatible, we raise an error.
Source code in vllm/engine/arg_utils.py
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 |
|
create_load_config
¶
create_load_config() -> LoadConfig
Source code in vllm/engine/arg_utils.py
create_model_config
¶
create_model_config() -> ModelConfig
Source code in vllm/engine/arg_utils.py
create_speculative_config
¶
create_speculative_config(
target_model_config: ModelConfig,
target_parallel_config: ParallelConfig,
enable_chunked_prefill: bool,
disable_log_stats: bool,
) -> Optional[SpeculativeConfig]
Initializes and returns a SpeculativeConfig object based on
speculative_config
.
This function utilizes speculative_config
to create a
SpeculativeConfig object. The speculative_config
can either be
provided as a JSON string input via CLI arguments or directly as a
dictionary from the engine.
Source code in vllm/engine/arg_utils.py
from_cli_args
classmethod
¶
from_cli_args(args: Namespace)
Source code in vllm/engine/arg_utils.py
validate_tensorizer_args
¶
Source code in vllm/engine/arg_utils.py
LLM
¶
An LLM for generating texts from given prompts and sampling parameters.
This class includes a tokenizer, a language model (possibly distributed across multiple GPUs), and GPU memory space allocated for intermediate states (aka KV cache). Given a batch of prompts and sampling parameters, this class generates texts from the model, using an intelligent batching mechanism and efficient memory management.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
model
|
str
|
The name or path of a HuggingFace Transformers model. |
required |
tokenizer
|
Optional[str]
|
The name or path of a HuggingFace Transformers tokenizer. |
None
|
tokenizer_mode
|
TokenizerMode
|
The tokenizer mode. "auto" will use the fast tokenizer if available, and "slow" will always use the slow tokenizer. |
'auto'
|
skip_tokenizer_init
|
bool
|
If true, skip initialization of tokenizer and detokenizer. Expect valid prompt_token_ids and None for prompt from the input. |
False
|
trust_remote_code
|
bool
|
Trust remote code (e.g., from HuggingFace) when downloading the model and tokenizer. |
False
|
allowed_local_media_path
|
str
|
Allowing API requests to read local images or videos from directories specified by the server file system. This is a security risk. Should only be enabled in trusted environments. |
''
|
tensor_parallel_size
|
int
|
The number of GPUs to use for distributed execution with tensor parallelism. |
1
|
dtype
|
ModelDType
|
The data type for the model weights and activations. Currently,
we support |
'auto'
|
quantization
|
Optional[QuantizationMethods]
|
The method used to quantize the model weights. Currently,
we support "awq", "gptq", and "fp8" (experimental).
If None, we first check the |
None
|
revision
|
Optional[str]
|
The specific model version to use. It can be a branch name, a tag name, or a commit id. |
None
|
tokenizer_revision
|
Optional[str]
|
The specific tokenizer version to use. It can be a branch name, a tag name, or a commit id. |
None
|
seed
|
Optional[int]
|
The seed to initialize the random number generator for sampling. |
None
|
gpu_memory_utilization
|
float
|
The ratio (between 0 and 1) of GPU memory to reserve for the model weights, activations, and KV cache. Higher values will increase the KV cache size and thus improve the model's throughput. However, if the value is too high, it may cause out-of- memory (OOM) errors. |
0.9
|
swap_space
|
float
|
The size (GiB) of CPU memory per GPU to use as swap space.
This can be used for temporarily storing the states of the requests
when their |
4
|
cpu_offload_gb
|
float
|
The size (GiB) of CPU memory to use for offloading the model weights. This virtually increases the GPU memory space you can use to hold the model weights, at the cost of CPU-GPU data transfer for every forward pass. |
0
|
enforce_eager
|
bool
|
Whether to enforce eager execution. If True, we will disable CUDA graph and always execute the model in eager mode. If False, we will use CUDA graph and eager execution in hybrid. |
False
|
max_seq_len_to_capture
|
int
|
Maximum sequence len covered by CUDA graphs. When a sequence has context length larger than this, we fall back to eager mode. Additionally for encoder-decoder models, if the sequence length of the encoder input is larger than this, we fall back to the eager mode. |
8192
|
disable_custom_all_reduce
|
bool
|
See ParallelConfig. |
False
|
disable_async_output_proc
|
bool
|
Disable async output processing. This may result in lower performance. |
False
|
hf_token
|
Optional[Union[bool, str]]
|
The token to use as HTTP bearer authorization for remote files
. If |
None
|
hf_overrides
|
Optional[HfOverrides]
|
If a dictionary, contains arguments to be forwarded to the HuggingFace config. If a callable, it is called to update the HuggingFace config. |
None
|
mm_processor_kwargs
|
Optional[dict[str, Any]]
|
Arguments to be forwarded to the model's processor
for multi-modal data, e.g., image processor. Overrides for the
multi-modal processor obtained from |
None
|
override_pooler_config
|
Optional[PoolerConfig]
|
Initialize non-default pooling config or
override default pooling config for the pooling model.
e.g. |
None
|
compilation_config
|
Optional[Union[int, dict[str, Any], CompilationConfig]]
|
Either an integer or a dictionary. If it is an integer, it is used as the level of compilation optimization. If it is a dictionary, it can specify the full compilation configuration. |
None
|
**kwargs
|
Arguments for |
{}
|
Note
This class is intended to be used for offline inference. For online serving, use the AsyncLLMEngine class instead.
Source code in vllm/entrypoints/llm.py
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 |
|
DEPRECATE_LEGACY
class-attribute
¶
DEPRECATE_LEGACY: bool = True
A flag to toggle whether to deprecate the legacy generate/encode API.
default_sampling_params
instance-attribute
¶
llm_engine
instance-attribute
¶
llm_engine = from_engine_args(
engine_args=engine_args, usage_context=LLM_CLASS
)
__init__
¶
__init__(
model: str,
*,
task: TaskOption = "auto",
tokenizer: Optional[str] = None,
tokenizer_mode: TokenizerMode = "auto",
skip_tokenizer_init: bool = False,
trust_remote_code: bool = False,
allowed_local_media_path: str = "",
tensor_parallel_size: int = 1,
dtype: ModelDType = "auto",
quantization: Optional[QuantizationMethods] = None,
revision: Optional[str] = None,
tokenizer_revision: Optional[str] = None,
seed: Optional[int] = None,
gpu_memory_utilization: float = 0.9,
swap_space: float = 4,
cpu_offload_gb: float = 0,
enforce_eager: bool = False,
max_seq_len_to_capture: int = 8192,
disable_custom_all_reduce: bool = False,
disable_async_output_proc: bool = False,
hf_token: Optional[Union[bool, str]] = None,
hf_overrides: Optional[HfOverrides] = None,
mm_processor_kwargs: Optional[dict[str, Any]] = None,
override_pooler_config: Optional[PoolerConfig] = None,
compilation_config: Optional[
Union[int, dict[str, Any], CompilationConfig]
] = None,
**kwargs,
) -> None
LLM constructor.
Source code in vllm/entrypoints/llm.py
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 |
|
_add_guided_params
¶
_add_guided_params(
params: SamplingParams,
guided_options: Optional[GuidedDecodingRequest] = None,
)
Source code in vllm/entrypoints/llm.py
_add_request
¶
_add_request(
prompt: PromptType,
params: Union[SamplingParams, PoolingParams],
tokenization_kwargs: Optional[dict[str, Any]] = None,
lora_request: Optional[LoRARequest] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
priority: int = 0,
) -> None
Source code in vllm/entrypoints/llm.py
_convert_v1_inputs
¶
_convert_v1_inputs(
prompts: Optional[Union[str, list[str]]],
prompt_token_ids: Optional[
Union[list[int], list[list[int]]]
],
)
Source code in vllm/entrypoints/llm.py
_cross_encoding_score
¶
_cross_encoding_score(
tokenizer: AnyTokenizer,
data_1: Union[list[str], list[ScoreContentPartParam]],
data_2: Union[list[str], list[ScoreContentPartParam]],
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[ScoringRequestOutput]
Source code in vllm/entrypoints/llm.py
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 |
|
_embedding_score
¶
_embedding_score(
tokenizer: AnyTokenizer,
text_1: list[Union[str, TextPrompt, TokensPrompt]],
text_2: list[Union[str, TextPrompt, TokensPrompt]],
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[ScoringRequestOutput]
Source code in vllm/entrypoints/llm.py
_get_beam_search_lora_requests
¶
_get_beam_search_lora_requests(
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
],
prompts: list[Union[TokensPrompt, TextPrompt]],
) -> list[Optional[LoRARequest]]
Get the optional lora request corresponding to each prompt.
Source code in vllm/entrypoints/llm.py
_get_modality_specific_lora_reqs
¶
_get_modality_specific_lora_reqs(
parsed_prompts: Union[PromptType, Sequence[PromptType]],
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
],
)
Source code in vllm/entrypoints/llm.py
_resolve_single_prompt_mm_lora
¶
_resolve_single_prompt_mm_lora(
parsed_prompt: PromptType,
lora_request: Optional[LoRARequest],
default_mm_loras: Optional[dict[str, str]],
)
Source code in vllm/entrypoints/llm.py
_run_engine
¶
_run_engine(
*, use_tqdm: Union[bool, Callable[..., tqdm]] = True
) -> list[Union[RequestOutput, PoolingRequestOutput]]
Source code in vllm/entrypoints/llm.py
_validate_and_add_requests
¶
_validate_and_add_requests(
prompts: Union[PromptType, Sequence[PromptType]],
params: Union[
SamplingParams,
Sequence[SamplingParams],
PoolingParams,
Sequence[PoolingParams],
],
*,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[Sequence[LoRARequest], LoRARequest]
],
prompt_adapter_request: Optional[PromptAdapterRequest],
tokenization_kwargs: Optional[dict[str, Any]] = None,
guided_options: Optional[GuidedDecodingRequest] = None,
priority: Optional[list[int]] = None,
) -> None
Source code in vllm/entrypoints/llm.py
apply_model
¶
Run a function directly on the model inside each worker, returning the result for each of them.
Source code in vllm/entrypoints/llm.py
beam_search
¶
beam_search(
prompts: list[Union[TokensPrompt, TextPrompt]],
params: BeamSearchParams,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
use_tqdm: bool = False,
) -> list[BeamSearchOutput]
Generate sequences using beam search.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
list[Union[TokensPrompt, TextPrompt]]
|
A list of prompts. Each prompt can be a string or a list of token IDs. |
required |
params
|
BeamSearchParams
|
The beam search parameters. |
required |
lora_request
|
Optional[Union[list[LoRARequest], LoRARequest]]
|
LoRA request to use for generation, if any. |
None
|
use_tqdm
|
bool
|
Whether to use tqdm to display the progress bar. |
False
|
Source code in vllm/entrypoints/llm.py
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 |
|
chat
¶
chat(
messages: Union[
list[ChatCompletionMessageParam],
list[list[ChatCompletionMessageParam]],
],
sampling_params: Optional[
Union[SamplingParams, list[SamplingParams]]
] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[LoRARequest] = None,
chat_template: Optional[str] = None,
chat_template_content_format: ChatTemplateContentFormatOption = "auto",
add_generation_prompt: bool = True,
continue_final_message: bool = False,
tools: Optional[list[dict[str, Any]]] = None,
chat_template_kwargs: Optional[dict[str, Any]] = None,
mm_processor_kwargs: Optional[dict[str, Any]] = None,
) -> list[RequestOutput]
Generate responses for a chat conversation.
The chat conversation is converted into a text prompt using the tokenizer and calls the [generate][] method to generate the responses.
Multi-modal inputs can be passed in the same way you would pass them to the OpenAI API.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
Union[list[ChatCompletionMessageParam], list[list[ChatCompletionMessageParam]]]
|
A list of conversations or a single conversation.
|
required |
sampling_params
|
Optional[Union[SamplingParams, list[SamplingParams]]]
|
The sampling parameters for text generation. If None, we use the default sampling parameters. When it is a single value, it is applied to every prompt. When it is a list, the list must have the same length as the prompts and it is paired one by one with the prompt. |
None
|
use_tqdm
|
Union[bool, Callable[..., tqdm]]
|
If |
True
|
lora_request
|
Optional[LoRARequest]
|
LoRA request to use for generation, if any. |
None
|
chat_template
|
Optional[str]
|
The template to use for structuring the chat. If not provided, the model's default chat template will be used. |
None
|
chat_template_content_format
|
ChatTemplateContentFormatOption
|
The format to render message content.
|
'auto'
|
add_generation_prompt
|
bool
|
If True, adds a generation template to each message. |
True
|
continue_final_message
|
bool
|
If True, continues the final message in
the conversation instead of starting a new one. Cannot be
|
False
|
chat_template_kwargs
|
Optional[dict[str, Any]]
|
Additional kwargs to pass to the chat template. |
None
|
mm_processor_kwargs
|
Optional[dict[str, Any]]
|
Multimodal processor kwarg overrides for this chat request. Only used for offline requests. |
None
|
Returns:
Type | Description |
---|---|
list[RequestOutput]
|
A list of |
list[RequestOutput]
|
responses in the same order as the input messages. |
Source code in vllm/entrypoints/llm.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 |
|
classify
¶
classify(
prompts: Union[PromptType, Sequence[PromptType]],
/,
*,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[ClassificationRequestOutput]
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:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
Union[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 prompts. |
required |
use_tqdm
|
Union[bool, Callable[..., tqdm]]
|
If |
True
|
lora_request
|
Optional[Union[list[LoRARequest], LoRARequest]]
|
LoRA request to use for generation, if any. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
Prompt Adapter request to use for generation, if any. |
None
|
Returns:
Type | Description |
---|---|
list[ClassificationRequestOutput]
|
A list of |
list[ClassificationRequestOutput]
|
embedding vectors in the same order as the input prompts. |
Source code in vllm/entrypoints/llm.py
collective_rpc
¶
collective_rpc(
method: Union[str, Callable[..., _R]],
timeout: Optional[float] = None,
args: tuple = (),
kwargs: Optional[dict[str, Any]] = None,
) -> list[_R]
Execute an RPC call on all workers.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
method
|
Union[str, Callable[..., _R]]
|
Name of the worker method to execute, or a callable that is serialized and sent to all workers to execute. If the method is a callable, it should accept an additional
|
required |
timeout
|
Optional[float]
|
Maximum time in seconds to wait for execution. Raises a
|
None
|
args
|
tuple
|
Positional arguments to pass to the worker method. |
()
|
kwargs
|
Optional[dict[str, Any]]
|
Keyword arguments to pass to the worker method. |
None
|
Returns:
Type | Description |
---|---|
list[_R]
|
A list containing the results from each worker. |
Note
It is recommended to use this API to only pass control messages, and set up data-plane communication to pass data.
Source code in vllm/entrypoints/llm.py
deprecate_legacy_api
classmethod
¶
embed
¶
embed(
prompts: Union[PromptType, Sequence[PromptType]],
/,
*,
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[EmbeddingRequestOutput]
Generate an embedding vector 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:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
Union[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 prompts. |
required |
pooling_params
|
Optional[Union[PoolingParams, Sequence[PoolingParams]]]
|
The pooling parameters for pooling. If None, we use the default pooling parameters. |
None
|
use_tqdm
|
Union[bool, Callable[..., tqdm]]
|
If |
True
|
lora_request
|
Optional[Union[list[LoRARequest], LoRARequest]]
|
LoRA request to use for generation, if any. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
Prompt Adapter request to use for generation, if any. |
None
|
Returns:
Type | Description |
---|---|
list[EmbeddingRequestOutput]
|
A list of |
list[EmbeddingRequestOutput]
|
embedding vectors in the same order as the input prompts. |
Source code in vllm/entrypoints/llm.py
encode
¶
encode(
prompts: Union[PromptType, Sequence[PromptType]],
/,
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
*,
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
encode(
prompts: str,
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
prompt_token_ids: Optional[list[int]] = None,
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
encode(
prompts: list[str],
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
prompt_token_ids: Optional[list[list[int]]] = None,
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
encode(
prompts: Optional[str] = None,
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
*,
prompt_token_ids: list[int],
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
encode(
prompts: Optional[list[str]] = None,
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
*,
prompt_token_ids: list[list[int]],
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
encode(
prompts: None,
pooling_params: None,
prompt_token_ids: Union[list[int], list[list[int]]],
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
encode(
prompts: Union[
Union[PromptType, Sequence[PromptType]],
Optional[Union[str, list[str]]],
] = None,
pooling_params: Optional[
Union[PoolingParams, Sequence[PoolingParams]]
] = None,
prompt_token_ids: Optional[
Union[list[int], list[list[int]]]
] = None,
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[PoolingRequestOutput]
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:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
Union[Union[PromptType, Sequence[PromptType]], Optional[Union[str, list[str]]]]
|
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 prompts. |
None
|
pooling_params
|
Optional[Union[PoolingParams, Sequence[PoolingParams]]]
|
The pooling parameters for pooling. If None, we use the default pooling parameters. |
None
|
use_tqdm
|
Union[bool, Callable[..., tqdm]]
|
If |
True
|
lora_request
|
Optional[Union[list[LoRARequest], LoRARequest]]
|
LoRA request to use for generation, if any. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
Prompt Adapter request to use for generation, if any. |
None
|
Returns:
Type | Description |
---|---|
list[PoolingRequestOutput]
|
A list of |
list[PoolingRequestOutput]
|
pooled hidden states in the same order as the input prompts. |
Note
Using prompts
and prompt_token_ids
as keyword parameters is
considered legacy and may be deprecated in the future. You should
instead pass them via the inputs
parameter.
Source code in vllm/entrypoints/llm.py
1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 |
|
generate
¶
generate(
prompts: Union[PromptType, Sequence[PromptType]],
/,
sampling_params: Optional[
Union[SamplingParams, Sequence[SamplingParams]]
] = None,
*,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
) -> list[RequestOutput]
generate(
prompts: str,
sampling_params: Optional[
Union[SamplingParams, list[SamplingParams]]
] = None,
prompt_token_ids: Optional[list[int]] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
) -> list[RequestOutput]
generate(
prompts: list[str],
sampling_params: Optional[
Union[SamplingParams, list[SamplingParams]]
] = None,
prompt_token_ids: Optional[list[list[int]]] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
) -> list[RequestOutput]
generate(
prompts: Optional[str] = None,
sampling_params: Optional[
Union[SamplingParams, list[SamplingParams]]
] = None,
*,
prompt_token_ids: list[int],
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
) -> list[RequestOutput]
generate(
prompts: Optional[list[str]] = None,
sampling_params: Optional[
Union[SamplingParams, list[SamplingParams]]
] = None,
*,
prompt_token_ids: list[list[int]],
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
) -> list[RequestOutput]
generate(
prompts: None,
sampling_params: None,
prompt_token_ids: Union[list[int], list[list[int]]],
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
) -> list[RequestOutput]
generate(
prompts: Union[
Union[PromptType, Sequence[PromptType]],
Optional[Union[str, list[str]]],
] = None,
sampling_params: Optional[
Union[SamplingParams, Sequence[SamplingParams]]
] = None,
prompt_token_ids: Optional[
Union[list[int], list[list[int]]]
] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
guided_options_request: Optional[
Union[LLMGuidedOptions, GuidedDecodingRequest]
] = None,
priority: Optional[list[int]] = None,
) -> list[RequestOutput]
Generates the completions for 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:
Name | Type | Description | Default |
---|---|---|---|
prompts
|
Union[Union[PromptType, Sequence[PromptType]], Optional[Union[str, list[str]]]]
|
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 prompts. |
None
|
sampling_params
|
Optional[Union[SamplingParams, Sequence[SamplingParams]]]
|
The sampling parameters for text generation. If None, we use the default sampling parameters. When it is a single value, it is applied to every prompt. When it is a list, the list must have the same length as the prompts and it is paired one by one with the prompt. |
None
|
use_tqdm
|
Union[bool, Callable[..., tqdm]]
|
If |
True
|
lora_request
|
Optional[Union[list[LoRARequest], LoRARequest]]
|
LoRA request to use for generation, if any. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
Prompt Adapter request to use for generation, if any. |
None
|
priority
|
Optional[list[int]]
|
The priority of the requests, if any. Only applicable when priority scheduling policy is enabled. |
None
|
Returns:
Type | Description |
---|---|
list[RequestOutput]
|
A list of |
list[RequestOutput]
|
generated completions in the same order as the input prompts. |
Note
Using prompts
and prompt_token_ids
as keyword parameters is
considered legacy and may be deprecated in the future. You should
instead pass them via the inputs
parameter.
Source code in vllm/entrypoints/llm.py
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 |
|
get_default_sampling_params
¶
get_default_sampling_params() -> SamplingParams
Source code in vllm/entrypoints/llm.py
get_metrics
¶
Return a snapshot of aggregated metrics from Prometheus.
Returns:
Type | Description |
---|---|
list[Metric]
|
A |
list[Metric]
|
of all aggregated metrics from Prometheus. |
Note
This method is only available with the V1 LLM engine.
Source code in vllm/entrypoints/llm.py
get_tokenizer
¶
get_tokenizer(
lora_request: Optional[LoRARequest] = None,
) -> AnyTokenizer
reset_prefix_cache
¶
score
¶
score(
data_1: Union[
SingletonPrompt,
Sequence[SingletonPrompt],
ScoreMultiModalParam,
],
data_2: Union[
SingletonPrompt,
Sequence[SingletonPrompt],
ScoreMultiModalParam,
],
/,
*,
truncate_prompt_tokens: Optional[int] = None,
use_tqdm: Union[bool, Callable[..., tqdm]] = True,
lora_request: Optional[
Union[list[LoRARequest], LoRARequest]
] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
) -> list[ScoringRequestOutput]
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:
Name | Type | Description | Default |
---|---|---|---|
data_1
|
Union[SingletonPrompt, Sequence[SingletonPrompt], ScoreMultiModalParam]
|
Can be a single prompt, a list of prompts or
|
required |
data_2
|
Union[SingletonPrompt, Sequence[SingletonPrompt], ScoreMultiModalParam]
|
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. |
required |
use_tqdm
|
Union[bool, Callable[..., tqdm]]
|
If |
True
|
lora_request
|
Optional[Union[list[LoRARequest], LoRARequest]]
|
LoRA request to use for generation, if any. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
Prompt Adapter request to use for generation, if any. |
None
|
Returns:
Type | Description |
---|---|
list[ScoringRequestOutput]
|
A list of |
list[ScoringRequestOutput]
|
generated scores in the same order as the input prompts. |
Source code in vllm/entrypoints/llm.py
1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 |
|
set_tokenizer
¶
set_tokenizer(tokenizer: AnyTokenizer) -> None
Source code in vllm/entrypoints/llm.py
sleep
¶
sleep(level: int = 1)
Put the engine to sleep. The engine should not process any requests.
The caller should guarantee that no requests are being processed
during the sleep period, before wake_up
is called.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
level
|
int
|
The sleep level. Level 1 sleep will offload the model weights and discard the kv cache. The content of kv cache is forgotten. Level 1 sleep is good for sleeping and waking up the engine to run the same model again. The model weights are backed up in CPU memory. Please make sure there's enough CPU memory to store the model weights. Level 2 sleep will discard both the model weights and the kv cache. The content of both the model weights and kv cache is forgotten. Level 2 sleep is good for sleeping and waking up the engine to run a different model or update the model, where previous model weights are not needed. It reduces CPU memory pressure. |
1
|
Source code in vllm/entrypoints/llm.py
start_profile
¶
stop_profile
¶
wake_up
¶
Wake up the engine from sleep mode. See the [sleep][] method for more details.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
tags
|
Optional[list[str]]
|
An optional list of tags to reallocate the engine memory
for specific memory allocations. Values must be in
|
None
|
Source code in vllm/entrypoints/llm.py
LLMEngine
¶
An LLM engine that receives requests and generates texts.
This is the main class for the vLLM engine. It receives requests from clients and generates texts from the LLM. It includes a tokenizer, a language model (possibly distributed across multiple GPUs), and GPU memory space allocated for intermediate states (aka KV cache). This class utilizes iteration-level scheduling and efficient memory management to maximize the serving throughput.
The LLM
class wraps this class for offline batched inference
and the AsyncLLMEngine
class wraps this class for online serving.
The config arguments are derived from EngineArgs
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
vllm_config
|
VllmConfig
|
The configuration for initializing and running vLLM. |
required |
executor_class
|
Type[ExecutorBase]
|
The model executor class for managing distributed execution. |
required |
log_stats
|
bool
|
Whether to log statistics. |
required |
usage_context
|
UsageContext
|
Specified entry point, used for usage info collection. |
ENGINE_CONTEXT
|
Source code in vllm/engine/llm_engine.py
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 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 |
|
DO_VALIDATE_OUTPUT
class-attribute
¶
DO_VALIDATE_OUTPUT: bool = False
A flag to toggle whether to validate the type of request output.
async_callbacks
instance-attribute
¶
async_callbacks = [
partial(
process_model_outputs, ctx=scheduler_contexts[v_id]
)
for v_id in range(pipeline_parallel_size)
]
cached_scheduler_outputs
instance-attribute
¶
cached_scheduler_outputs = [
SchedulerOutputState()
for _ in range(pipeline_parallel_size)
]
generation_config_fields
instance-attribute
¶
input_preprocessor
instance-attribute
¶
input_preprocessor = InputPreprocessor(
model_config, tokenizer, mm_registry
)
observability_config
instance-attribute
¶
observability_config = (
observability_config or ObservabilityConfig()
)
output_processor
instance-attribute
¶
output_processor = create_output_processor(
scheduler_config,
detokenizer,
scheduler,
seq_counter,
get_tokenizer_for_seq,
stop_checker=StopChecker(
max_model_len, get_tokenizer_for_seq
),
)
process_request_outputs_callback
instance-attribute
¶
scheduler
instance-attribute
¶
scheduler = [
Scheduler(
scheduler_config,
cache_config,
lora_config,
pipeline_parallel_size,
async_callbacks[v_id]
if use_async_output_proc
else None,
)
for v_id in range(pipeline_parallel_size)
]
scheduler_contexts
instance-attribute
¶
scheduler_contexts = [
SchedulerContext(
multi_step_stream_outputs=multi_step_stream_outputs
)
for _ in range(pipeline_parallel_size)
]
__del__
¶
__init__
¶
__init__(
vllm_config: VllmConfig,
executor_class: Type[ExecutorBase],
log_stats: bool,
usage_context: UsageContext = ENGINE_CONTEXT,
stat_loggers: Optional[
Dict[str, StatLoggerBase]
] = None,
mm_registry: MultiModalRegistry = MULTIMODAL_REGISTRY,
use_cached_outputs: bool = False,
) -> None
Source code in vllm/engine/llm_engine.py
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 |
|
__reduce__
¶
_abort_and_cache_schedule
¶
_abort_and_cache_schedule(
request_id: str,
virtual_engine: int,
seq_group_metadata_list: List[SequenceGroupMetadata],
scheduler_outputs: SchedulerOutputs,
allow_async_output_proc: bool,
) -> None
Aborts a single request, and caches the scheduler outputs minus that request. This allows the next step to continue processing the remaining requests without having to re-run the scheduler.
Source code in vllm/engine/llm_engine.py
_add_processed_request
¶
_add_processed_request(
request_id: str,
processed_inputs: ProcessorInputs,
params: Union[SamplingParams, PoolingParams],
arrival_time: float,
lora_request: Optional[LoRARequest],
prompt_adapter_request: Optional[PromptAdapterRequest],
trace_headers: Optional[Mapping[str, str]] = None,
priority: int = 0,
) -> Optional[SequenceGroup]
Add a processed request to the engine's request pool. return the created sequence group.
Source code in vllm/engine/llm_engine.py
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 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
|
_advance_to_next_step
¶
_advance_to_next_step(
output: SamplerOutput,
seq_group_metadata_list: List[SequenceGroupMetadata],
scheduled_seq_groups: List[ScheduledSequenceGroup],
) -> None
Given model output from a single run, append the tokens to the sequences. This is normally done inside output processor, but it is required if the worker is to perform async forward pass to next step.
Source code in vllm/engine/llm_engine.py
_build_logits_processors
¶
_build_logits_processors(
sampling_params: SamplingParams,
lora_request: Optional[LoRARequest],
) -> SamplingParams
Constructs logits processors based on the guided_decoding, logits_bias, and allowed_token_ids fields in sampling_params. Deletes those fields and adds the constructed logits processors to the logits_processors field. Returns the modified sampling params.
Source code in vllm/engine/llm_engine.py
2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 |
|
_cache_scheduler_outputs_for_multi_step
¶
_cache_scheduler_outputs_for_multi_step(
virtual_engine: int,
seq_group_metadata_list: Optional[
List[SequenceGroupMetadata]
],
scheduler_outputs: SchedulerOutputs,
allow_async_output_proc: bool,
) -> None
Source code in vllm/engine/llm_engine.py
_create_sequence_group_with_pooling
¶
_create_sequence_group_with_pooling(
request_id: str,
seq: Sequence,
pooling_params: PoolingParams,
arrival_time: float,
lora_request: Optional[LoRARequest],
prompt_adapter_request: Optional[PromptAdapterRequest],
encoder_seq: Optional[Sequence] = None,
priority: int = 0,
) -> SequenceGroup
Creates a SequenceGroup with PoolingParams.
Source code in vllm/engine/llm_engine.py
_create_sequence_group_with_sampling
¶
_create_sequence_group_with_sampling(
request_id: str,
seq: Sequence,
sampling_params: SamplingParams,
arrival_time: float,
lora_request: Optional[LoRARequest],
trace_headers: Optional[Mapping[str, str]] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
encoder_seq: Optional[Sequence] = None,
priority: int = 0,
) -> SequenceGroup
Creates a SequenceGroup with SamplingParams.
Source code in vllm/engine/llm_engine.py
_get_executor_cls
classmethod
¶
_get_executor_cls(
engine_config: VllmConfig,
) -> Type[ExecutorBase]
Source code in vllm/engine/llm_engine.py
_get_last_sampled_token_ids
¶
Source code in vllm/engine/llm_engine.py
_get_stats
¶
_get_stats(
scheduler_outputs: Optional[SchedulerOutputs],
model_output: Optional[List[SamplerOutput]] = None,
finished_before: Optional[List[int]] = None,
skip: Optional[List[int]] = None,
) -> Stats
Get Stats to be Logged to Prometheus.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scheduler_outputs
|
Optional[SchedulerOutputs]
|
Optional, used to populate metrics related to the scheduled batch, |
required |
model_output
|
Optional[List[SamplerOutput]]
|
Optional, used to emit speculative decoding metrics which are created by the workers. |
None
|
finished_before
|
Optional[List[int]]
|
Optional, indices of sequences that were finished before. These sequences will be ignored. |
None
|
skip
|
Optional[List[int]]
|
Optional, indices of sequences that were preempted. These sequences will be ignored. |
None
|
Source code in vllm/engine/llm_engine.py
1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 |
|
_has_remaining_steps
¶
_has_remaining_steps(
seq_group_metadata_list: Optional[
List[SequenceGroupMetadata]
],
) -> bool
Source code in vllm/engine/llm_engine.py
_init_tokenizer
¶
_init_tokenizer() -> TokenizerGroup
_initialize_kv_caches
¶
Initialize the KV cache in the worker(s).
The workers will determine the number of blocks in both the GPU cache and the swap CPU cache.
Source code in vllm/engine/llm_engine.py
_process_model_outputs
¶
_process_model_outputs(
ctx: SchedulerContext, request_id: Optional[str] = None
) -> None
Apply the model output to the sequences in the scheduled seq groups and return responses.
ctx: The virtual engine context to work on request_id: If provided, then only this request is going to be processed
Source code in vllm/engine/llm_engine.py
935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 |
|
_process_sequence_group_outputs
staticmethod
¶
_process_sequence_group_outputs(
seq_group: SequenceGroup,
outputs: List[PoolingSequenceGroupOutput],
) -> None
Source code in vllm/engine/llm_engine.py
_update_cached_scheduler_output
¶
_update_cached_scheduler_output(
virtual_engine: int,
output: List[Optional[SamplerOutput]],
) -> None
Source code in vllm/engine/llm_engine.py
_update_num_computed_tokens_for_multi_step_prefill
¶
_update_num_computed_tokens_for_multi_step_prefill(
seq_group: SequenceGroup,
seq_group_meta: SequenceGroupMetadata,
is_first_step_output: Optional[bool],
)
This function updates num_computed_tokens for prompt sequences when Multi-Step is enabled.
seq_group: SequenceGroup to update the num_computed_tokens for. seq_group_meta: Metadata of the given SequenceGroup. is_first_step_output: Optional[bool] - When available, is_first_step_output indicates if the appended output token is the output of the first-step in multi-step. A value of None indicates that outputs from all steps in in multi-step are submitted in a single burst.
Source code in vllm/engine/llm_engine.py
_validate_model_input
¶
_validate_model_input(
prompt_inputs: SingletonInputs,
lora_request: Optional[LoRARequest],
*,
prompt_type: Literal["encoder", "decoder"],
)
Source code in vllm/engine/llm_engine.py
_validate_model_inputs
¶
_validate_model_inputs(
inputs: ProcessorInputs,
lora_request: Optional[LoRARequest],
)
Source code in vllm/engine/llm_engine.py
_verify_args
¶
Source code in vllm/engine/llm_engine.py
abort_request
¶
Aborts a request(s) with the given ID.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
Union[str, Iterable[str]]
|
The ID(s) of the request to abort. |
required |
Details
Example
initialize engine and add a request with request_id¶
request_id = str(0)
abort the request¶
engine.abort_request(request_id)
Source code in vllm/engine/llm_engine.py
add_logger
¶
add_logger(
logger_name: str, logger: StatLoggerBase
) -> None
Source code in vllm/engine/llm_engine.py
add_lora
¶
add_lora(lora_request: LoRARequest) -> bool
add_prompt_adapter
¶
add_prompt_adapter(
prompt_adapter_request: PromptAdapterRequest,
) -> bool
add_request
¶
add_request(
request_id: str,
prompt: PromptType,
params: Union[SamplingParams, PoolingParams],
arrival_time: Optional[float] = None,
lora_request: Optional[LoRARequest] = None,
tokenization_kwargs: Optional[dict[str, Any]] = None,
trace_headers: Optional[Mapping[str, str]] = None,
prompt_adapter_request: Optional[
PromptAdapterRequest
] = None,
priority: int = 0,
) -> None
Add a request to the engine's request pool.
The request is added to the request pool and will be processed by the
scheduler as engine.step()
is called. The exact scheduling policy is
determined by the scheduler.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
str
|
The unique ID of the request. |
required |
prompt
|
PromptType
|
The prompt to the LLM. See PromptType for more details about the format of each input. |
required |
params
|
Union[SamplingParams, PoolingParams]
|
Parameters for sampling or pooling. SamplingParams for text generation. PoolingParams for pooling. |
required |
arrival_time
|
Optional[float]
|
The arrival time of the request. If None, we use the current monotonic time. |
None
|
lora_request
|
Optional[LoRARequest]
|
The LoRA request to add. |
None
|
trace_headers
|
Optional[Mapping[str, str]]
|
OpenTelemetry trace headers. |
None
|
prompt_adapter_request
|
Optional[PromptAdapterRequest]
|
The prompt adapter request to add. |
None
|
priority
|
int
|
The priority of the request. Only applicable with priority scheduling. |
0
|
Details
- Set arrival_time to the current time if it is None.
- Set prompt_token_ids to the encoded prompt if it is None.
- Create
n
number of [Sequence][vllm.Sequence] objects. - Create a [SequenceGroup][vllm.SequenceGroup] object from the list of [Sequence][vllm.Sequence].
- Add the [SequenceGroup][vllm.SequenceGroup] object to the scheduler.
Example
initialize engine¶
engine = LLMEngine.from_engine_args(engine_args)
set request arguments¶
example_prompt = "Who is the president of the United States?" sampling_params = SamplingParams(temperature=0.0) request_id = 0
add the request to the engine¶
engine.add_request( str(request_id), example_prompt, SamplingParams(temperature=0.0))
continue the request processing¶
...
Source code in vllm/engine/llm_engine.py
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 |
|
check_health
¶
collective_rpc
¶
collective_rpc(
method: Union[str, Callable[..., _R]],
timeout: Optional[float] = None,
args: tuple = (),
kwargs: Optional[dict[str, Any]] = None,
) -> list[_R]
Source code in vllm/engine/llm_engine.py
create_trace_span
¶
create_trace_span(seq_group: SequenceGroup) -> None
Source code in vllm/engine/llm_engine.py
do_log_stats
¶
do_log_stats(
scheduler_outputs: Optional[SchedulerOutputs] = None,
model_output: Optional[List[SamplerOutput]] = None,
finished_before: Optional[List[int]] = None,
skip: Optional[List[int]] = None,
) -> None
Forced log when no requests active.
Source code in vllm/engine/llm_engine.py
do_tracing
¶
do_tracing(
scheduler_outputs: SchedulerOutputs,
finished_before: Optional[List[int]] = None,
) -> None
Source code in vllm/engine/llm_engine.py
enable_output_validation
classmethod
¶
from_engine_args
classmethod
¶
from_engine_args(
engine_args: EngineArgs,
usage_context: UsageContext = ENGINE_CONTEXT,
stat_loggers: Optional[
Dict[str, StatLoggerBase]
] = None,
) -> LLMEngine
Creates an LLM engine from the engine arguments.
Source code in vllm/engine/llm_engine.py
from_vllm_config
classmethod
¶
from_vllm_config(
vllm_config: VllmConfig,
usage_context: UsageContext = ENGINE_CONTEXT,
stat_loggers: Optional[
Dict[str, StatLoggerBase]
] = None,
disable_log_stats: bool = False,
) -> LLMEngine
Source code in vllm/engine/llm_engine.py
get_decoding_config
¶
get_decoding_config() -> DecodingConfig
get_lora_config
¶
get_lora_config() -> LoRAConfig
get_model_config
¶
get_model_config() -> ModelConfig
get_parallel_config
¶
get_parallel_config() -> ParallelConfig
get_scheduler_config
¶
get_scheduler_config() -> SchedulerConfig
get_tokenizer
¶
get_tokenizer(
lora_request: Optional[LoRARequest] = None,
) -> AnyTokenizer
get_tokenizer_group
¶
get_tokenizer_group() -> TokenizerGroup
get_vllm_config
¶
get_vllm_config() -> VllmConfig
has_unfinished_requests_for_virtual_engine
¶
Returns True if there are unfinished requests for the virtual engine.
list_loras
¶
list_prompt_adapters
¶
pin_lora
¶
remove_logger
¶
remove_logger(logger_name: str) -> None
Source code in vllm/engine/llm_engine.py
remove_lora
¶
remove_prompt_adapter
¶
reset_prefix_cache
¶
Reset prefix cache for all devices.
Source code in vllm/engine/llm_engine.py
start_profile
¶
step
¶
step() -> List[Union[RequestOutput, PoolingRequestOutput]]
Performs one decoding iteration and returns newly generated results.

Details: - Step 1: Schedules the sequences to be executed in the next iteration and the token blocks to be swapped in/out/copy.
- Depending on the scheduling policy,
sequences may be `preempted/reordered`.
- A Sequence Group (SG) refer to a group of sequences
that are generated from the same prompt.
- Step 2: Calls the distributed executor to execute the model.
-
Step 3: Processes the model output. This mainly includes:
- Decodes the relevant outputs.
- Updates the scheduled sequence groups with model outputs
based on its
sampling parameters
(use_beam_search
or not). - Frees the finished sequence groups.
-
Finally, it creates and returns the newly generated results.
Example:
# Please see the example/ folder for more detailed examples.
# initialize engine and request arguments
engine = LLMEngine.from_engine_args(engine_args)
example_inputs = [(0, "What is LLM?",
SamplingParams(temperature=0.0))]
# Start the engine with an event loop
while True:
if example_inputs:
req_id, prompt, sampling_params = example_inputs.pop(0)
engine.add_request(str(req_id),prompt,sampling_params)
# continue the request processing
request_outputs = engine.step()
for request_output in request_outputs:
if request_output.finished:
# return or show the request output
if not (engine.has_unfinished_requests() or example_inputs):
break
Source code in vllm/engine/llm_engine.py
1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 |
|
stop_profile
¶
stop_remote_worker_execution_loop
¶
validate_output
classmethod
¶
Source code in vllm/engine/llm_engine.py
validate_outputs
classmethod
¶
Source code in vllm/engine/llm_engine.py
wake_up
¶
PoolingOutput
dataclass
¶
The output data of one pooling output of a request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data
|
Tensor
|
The extracted hidden states. |
required |
Source code in vllm/outputs.py
__eq__
¶
PoolingParams
¶
Bases: Struct
API parameters for pooling models. This is currently a placeholder.
Attributes:
Name | Type | Description |
---|---|---|
dimensions |
Optional[int]
|
Reduce the dimensions of embeddings if model support matryoshka representation. |
additional_data |
Optional[Any]
|
Any additional data needed for pooling. |
Source code in vllm/pooling_params.py
__post_init__
¶
verify
¶
verify(model_config: ModelConfig) -> None
Source code in vllm/pooling_params.py
PoolingRequestOutput
¶
The output data of a pooling request to the LLM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
str
|
A unique identifier for the pooling request. |
required |
outputs
|
PoolingOutput
|
The pooling results for the given input. |
required |
prompt_token_ids
|
list[int]
|
A list of token IDs used in the prompt. |
required |
finished
|
bool
|
A flag indicating whether the pooling is completed. |
required |
Source code in vllm/outputs.py
__init__
¶
__repr__
¶
from_seq_group
staticmethod
¶
from_seq_group(
seq_group: SequenceGroup,
) -> PoolingRequestOutput
Source code in vllm/outputs.py
RequestOutput
¶
The output data of a completion request to the LLM.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request_id
|
str
|
The unique ID of the request. |
required |
prompt
|
Optional[str]
|
The prompt string of the request. For encoder/decoder models, this is the decoder input prompt. |
required |
prompt_token_ids
|
Optional[list[int]]
|
The token IDs of the prompt. For encoder/decoder models, this is the decoder input prompt token ids. |
required |
prompt_logprobs
|
Optional[PromptLogprobs]
|
The log probabilities to return per prompt token. |
required |
outputs
|
list[CompletionOutput]
|
The output sequences of the request. |
required |
finished
|
bool
|
Whether the whole request is finished. |
required |
metrics
|
Optional[RequestMetrics]
|
Metrics associated with the request. |
None
|
lora_request
|
Optional[LoRARequest]
|
The LoRA request that was used to generate the output. |
None
|
encoder_prompt
|
Optional[str]
|
The encoder prompt string of the request. None if decoder-only. |
None
|
encoder_prompt_token_ids
|
Optional[list[int]]
|
The token IDs of the encoder prompt. None if decoder-only. |
None
|
num_cached_tokens
|
Optional[int]
|
The number of tokens with prefix cache hit. |
None
|
kv_transfer_params
|
Optional[dict[str, Any]]
|
The params for remote K/V transfer. |
None
|
Source code in vllm/outputs.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 |
|
multi_modal_placeholders
instance-attribute
¶
__init__
¶
__init__(
request_id: str,
prompt: Optional[str],
prompt_token_ids: Optional[list[int]],
prompt_logprobs: Optional[PromptLogprobs],
outputs: list[CompletionOutput],
finished: bool,
metrics: Optional[RequestMetrics] = None,
lora_request: Optional[LoRARequest] = None,
encoder_prompt: Optional[str] = None,
encoder_prompt_token_ids: Optional[list[int]] = None,
num_cached_tokens: Optional[int] = None,
*,
multi_modal_placeholders: Optional[
MultiModalPlaceholderDict
] = None,
kv_transfer_params: Optional[dict[str, Any]] = None,
**kwargs: Any,
) -> None
Source code in vllm/outputs.py
__repr__
¶
__repr__() -> str
Source code in vllm/outputs.py
add
¶
add(next_output: RequestOutput, aggregate: bool) -> None
Merge subsequent RequestOutput into this one
Source code in vllm/outputs.py
from_seq_group
classmethod
¶
from_seq_group(
seq_group: SequenceGroup,
use_cache: bool,
seq_id_to_seq_group: dict[str, SequenceGroupBase],
) -> Optional[RequestOutput]
Source code in vllm/outputs.py
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 |
|
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
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 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 |
|
_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
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 |
|
_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
Source code in vllm/sampling_params.py
ScoringOutput
dataclass
¶
The output data of one scoring output of a request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
score
|
float
|
The similarity score, which is a scalar value. |
required |
Source code in vllm/outputs.py
from_base
staticmethod
¶
from_base(pooling_output: PoolingOutput)
Source code in vllm/outputs.py
ScoringRequestOutput
¶
Bases: PoolingRequestOutput[ScoringOutput]
Source code in vllm/outputs.py
from_base
staticmethod
¶
from_base(request_output: PoolingRequestOutput)
Source code in vllm/outputs.py
TextPrompt
¶
Bases: TypedDict
Schema for a text prompt.
Source code in vllm/inputs/data.py
cache_salt
instance-attribute
¶
cache_salt: NotRequired[str]
Optional cache salt to be used for prefix caching.
mm_processor_kwargs
instance-attribute
¶
mm_processor_kwargs: NotRequired[dict[str, Any]]
Optional multi-modal processor kwargs to be forwarded to the multimodal input mapper & processor. Note that if multiple modalities have registered mappers etc for the model being considered, we attempt to pass the mm_processor_kwargs to each of them.
multi_modal_data
instance-attribute
¶
multi_modal_data: NotRequired[MultiModalDataDict]
Optional multi-modal data to pass to the model, if the model supports it.
TokensPrompt
¶
Bases: TypedDict
Schema for a tokenized prompt.
Source code in vllm/inputs/data.py
cache_salt
instance-attribute
¶
cache_salt: NotRequired[str]
Optional cache salt to be used for prefix caching.
mm_processor_kwargs
instance-attribute
¶
mm_processor_kwargs: NotRequired[dict[str, Any]]
Optional multi-modal processor kwargs to be forwarded to the multimodal input mapper & processor. Note that if multiple modalities have registered mappers etc for the model being considered, we attempt to pass the mm_processor_kwargs to each of them.
multi_modal_data
instance-attribute
¶
multi_modal_data: NotRequired[MultiModalDataDict]
Optional multi-modal data to pass to the model, if the model supports it.
prompt_token_ids
instance-attribute
¶
A list of token IDs to pass to the model.
token_type_ids
instance-attribute
¶
token_type_ids: NotRequired[list[int]]
A list of token type IDs to pass to the cross encoder model.
__getattr__
¶
Source code in vllm/__init__.py
initialize_ray_cluster
¶
initialize_ray_cluster(
parallel_config: ParallelConfig,
ray_address: Optional[str] = None,
)
Initialize the distributed cluster with Ray.
it will connect to the Ray cluster and create a placement group for the workers, which includes the specification of the resources for each distributed worker.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
parallel_config
|
ParallelConfig
|
The configurations for parallel execution. |
required |
ray_address
|
Optional[str]
|
The address of the Ray cluster. If None, uses the default Ray cluster address. |
None
|
Source code in vllm/executor/ray_utils.py
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 |
|