vllm.v1.sample.logits_processor
Modules:
Name | Description |
---|---|
builtin | |
interface | |
state | |
BUILTIN_LOGITS_PROCESSORS module-attribute
¶
BUILTIN_LOGITS_PROCESSORS: list[type[LogitsProcessor]] = [
MinTokensLogitsProcessor,
LogitBiasLogitsProcessor,
MinPLogitsProcessor,
]
STR_POOLING_REJECTS_LOGITSPROCS module-attribute
¶
__all__ module-attribute
¶
__all__ = [
"LogitsProcessor",
"LogitBiasLogitsProcessor",
"MinPLogitsProcessor",
"MinTokensLogitsProcessor",
"BatchUpdate",
"BatchUpdateBuilder",
"MoveDirectionality",
"LogitsProcessors",
"build_logitsprocs",
"STR_POOLING_REJECTS_LOGITSPROCS",
"LOGITSPROCS_GROUP",
]
BatchUpdate dataclass
¶
Persistent batch state change info for logitsprocs
Source code in vllm/v1/sample/logits_processor/interface.py
__init__ ¶
__init__(
batch_size: int,
removed: Sequence[RemovedRequest],
moved: Sequence[MovedRequest],
added: Sequence[AddedRequest],
) -> None
BatchUpdateBuilder ¶
Helps track persistent batch state changes and build a batch update data structure for logitsprocs Assumptions: * All information about requests removed from persistent batch during a step is aggregated in self._removed through calls to self.removed_append() at the beginning of a step. This must happen before the first time that self.removed, self.pop_removed() or self.peek_removed() are invoked in a given step * After the first time that self.removed, self.pop_removed() or self.peek_removed() are read in a step, no new removals are registered using self.removed_append() * Elements of self._removed are never directly modified, added or removed (i.e. modification is only via self.removed_append() and self.pop_removed()) Guarantees under above assumptions: * self.removed is always sorted in descending order * self.pop_removed() and self.peek_removed() both return the lowest removed request index in the current step
Source code in vllm/v1/sample/logits_processor/state.py
16 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 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 |
|
__init__ ¶
__init__(
removed: Optional[list[RemovedRequest]] = None,
moved: Optional[list[MovedRequest]] = None,
added: Optional[list[AddedRequest]] = None,
) -> None
Source code in vllm/v1/sample/logits_processor/state.py
_ensure_removed_sorted ¶
Sort removed request indices in descending order. Idempotent after first call in a given step, until reset.
Source code in vllm/v1/sample/logits_processor/state.py
get_and_reset ¶
get_and_reset(batch_size: int) -> Optional[BatchUpdate]
Generate a logitsprocs batch update data structure and reset internal batch update builder state.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
batch_size | int | current persistent batch size | required |
Returns:
Type | Description |
---|---|
Optional[BatchUpdate] | Frozen logitsprocs batch update instance; |
Source code in vllm/v1/sample/logits_processor/state.py
peek_removed ¶
pop_removed ¶
removed_append ¶
removed_append(index: int) -> None
Register the removal of a request from the persistent batch.
Must not be called after the first time self.removed, self.pop_removed() or self.peek_removed() are invoked.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
index | int | request index | required |
Source code in vllm/v1/sample/logits_processor/state.py
LogitBiasLogitsProcessor ¶
Bases: LogitsProcessor
Source code in vllm/v1/sample/logits_processor/builtin.py
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 |
|
logits_slice instance-attribute
¶
__init__ ¶
Source code in vllm/v1/sample/logits_processor/builtin.py
_device_tensor ¶
apply ¶
is_argmax_invariant ¶
is_argmax_invariant() -> bool
Logit bias can rebalance token probabilities and change the outcome of argmax in greedy sampling.
update_state ¶
update_state(batch_update: Optional[BatchUpdate])
Source code in vllm/v1/sample/logits_processor/builtin.py
LogitsProcessor ¶
Bases: ABC
Source code in vllm/v1/sample/logits_processor/interface.py
__init__ abstractmethod
¶
__init__(
vllm_config: VllmConfig,
device: device,
is_pin_memory: bool,
) -> None
apply abstractmethod
¶
is_argmax_invariant abstractmethod
¶
is_argmax_invariant() -> bool
True if logits processor has no impact on the argmax computation in greedy sampling. NOTE: may or may not have the same value for all instances of a given LogitsProcessor subclass, depending on subclass implementation.
Source code in vllm/v1/sample/logits_processor/interface.py
update_state abstractmethod
¶
update_state(batch_update: Optional[BatchUpdate]) -> None
Called when there are new output tokens, prior to each forward pass.
Source code in vllm/v1/sample/logits_processor/interface.py
LogitsProcessors ¶
Encapsulates initialized logitsproc objects.
Source code in vllm/v1/sample/logits_processor/state.py
__init__ ¶
__init__(
logitsprocs: Optional[Iterator[LogitsProcessor]] = None,
) -> None
Source code in vllm/v1/sample/logits_processor/state.py
MinPLogitsProcessor ¶
Bases: LogitsProcessor
Source code in vllm/v1/sample/logits_processor/builtin.py
16 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 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
min_p_cpu_tensor instance-attribute
¶
min_p_cpu_tensor = zeros(
(max_num_reqs,),
dtype=float32,
device="cpu",
pin_memory=is_pin_memory,
)
min_p_device instance-attribute
¶
__init__ ¶
__init__(
vllm_config: VllmConfig,
device: device,
is_pin_memory: bool,
)
Source code in vllm/v1/sample/logits_processor/builtin.py
apply ¶
Source code in vllm/v1/sample/logits_processor/builtin.py
get_min_p_by_index ¶
update_state ¶
update_state(batch_update: Optional[BatchUpdate])
Source code in vllm/v1/sample/logits_processor/builtin.py
MinTokensLogitsProcessor ¶
Bases: LogitsProcessor
Source code in vllm/v1/sample/logits_processor/builtin.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 |
|
logits_slice instance-attribute
¶
__init__ ¶
__init__(
vllm_config: VllmConfig,
device: device,
is_pin_memory: bool,
)
Source code in vllm/v1/sample/logits_processor/builtin.py
_device_tensor ¶
apply ¶
is_argmax_invariant ¶
is_argmax_invariant() -> bool
By censoring stop tokens, min-tokens can change the outcome of the argmax operation in greedy sampling.
update_state ¶
update_state(batch_update: Optional[BatchUpdate])
Source code in vllm/v1/sample/logits_processor/builtin.py
_load_custom_logitsprocs ¶
_load_custom_logitsprocs(
logits_processors: Optional[
Sequence[Union[str, type[LogitsProcessor]]]
],
) -> list[type[LogitsProcessor]]
Load all custom logits processors.
- First load all installed logitproc plugins
- Second load custom logitsprocs pass by the user at initialization time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logits_processors | Optional[Sequence[Union[str, type[LogitsProcessor]]]] | potentially mixed list of logitproc types and logitproc type fully-qualified names (FQCNs) which need to be loaded | required |
Returns:
Type | Description |
---|---|
list[type[LogitsProcessor]] | A list of all loaded logitproc types |
Source code in vllm/v1/sample/logits_processor/__init__.py
_load_logitsprocs_by_fqcns ¶
_load_logitsprocs_by_fqcns(
logits_processors: Optional[
Sequence[Union[str, type[LogitsProcessor]]]
],
) -> list[type[LogitsProcessor]]
Load logit processor types, identifying them by fully-qualified class names (FQCNs).
Effectively, a mixed list of logitproc types and FQCN strings is converted into a list of entirely logitproc types, by loading from the FQCNs.
FQCN syntax is
Already-loaded logitproc types must be subclasses of LogitsProcessor
Parameters:
Name | Type | Description | Default |
---|---|---|---|
logits_processors | Optional[Sequence[Union[str, type[LogitsProcessor]]]] | Potentially mixed list of logitsprocs types and FQCN strings for logitproc types | required |
Returns:
Type | Description |
---|---|
list[type[LogitsProcessor]] | List of logitproc types |
Source code in vllm/v1/sample/logits_processor/__init__.py
_load_logitsprocs_plugins ¶
_load_logitsprocs_plugins() -> list[type[LogitsProcessor]]
Load all installed logit processor plugins
Source code in vllm/v1/sample/logits_processor/__init__.py
build_logitsprocs ¶
build_logitsprocs(
vllm_config: VllmConfig,
device: device,
is_pin_memory: bool,
is_pooling_model: bool,
custom_logitsprocs: Sequence[
Union[str, type[LogitsProcessor]]
] = (),
) -> LogitsProcessors