vLLM Backend
check_token_metric_compatibility(sampler: AutoregressiveSampler, token_metric: str)
Check that the vLLM engine can support the given token metric with the given configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sampler
|
AutoregressiveSampler
|
The sampler object containing sampling parameters and the LLM engine. |
required |
token_metric
|
str
|
The token metric to check compatibility for. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If logits_per_token is not set. |
ValueError
|
If vLLM engine logprobs_mode is not 'raw_logits'. |
ValueError
|
If 'req_id' is not in extra_args. |
Source code in pita/inference/vllm_backend.py
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 | |
create_LLM_object(model_name: str, model_type: str | None = None, dtype: str = 'auto', gpu_memory_utilization: float = 0.85, max_model_len: int = 2048, max_probs: int = 1000, logits_processor: bool = False, **kwargs: Any) -> LLM
Create the LLM object given the model name and engine parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_name
|
str
|
The name of the model to load. |
required |
model_type
|
str
|
The type of model (e.g., 'safetensors', 'gguf'). Defaults to None. |
None
|
dtype
|
str
|
The data type to use. Defaults to "auto". |
'auto'
|
gpu_memory_utilization
|
float
|
The fraction of GPU memory to use. Defaults to 0.85. |
0.85
|
max_model_len
|
int
|
The maximum length of the model context. Defaults to 2048. |
2048
|
max_probs
|
int
|
Controls how many logprobs or logits are stored for each token. Defaults to 1000. |
1000
|
logits_processor
|
bool
|
Whether to enable the Redis logging logits processor. Defaults to False. |
False
|
**kwargs
|
Any
|
Additional keyword arguments passed to the LLM constructor. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
LLM |
LLM
|
The initialized vLLM LLM object. |
Source code in pita/inference/vllm_backend.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 | |
create_vllm_engine_params() -> SamplingParams
Create the vLLM SamplingParams object from the common Sampling_Params.
Returns:
| Name | Type | Description |
|---|---|---|
SamplingParams |
SamplingParams
|
A new instance of vLLM SamplingParams. |
Source code in pita/inference/vllm_backend.py
142 143 144 145 146 147 148 149 150 151 | |
sample(self, context: str | list[str], **kwargs: Any) -> Output
Generate text from the given context using the vLLM engine.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
str | list[str]
|
The input context string to generate from. |
required |
**kwargs
|
Any
|
Additional keyword arguments passed to the vLLM generate function. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Output |
Output
|
An Output object containing: - tokens: The generated token IDs. - top_k_logits: The top_k logits (if logits_per_token is set). - top_k_logprobs: The top_k logprobs (if logprobs is set). - unprocessed_log_normalization_constant: The log(Normalization Constants - Unprocessed) for each token. - temp_processed_log_normalization_constant: The log(Normalization Constants - Temperature Processed) for each token. - entropy: The entropy for each token. |
Source code in pita/inference/vllm_backend.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 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 | |