vLLM Logits Processor
LogitsLoggingProcessor
Bases: LogitsProcessor
Custom vLLM logits processor that logs normalization constants and entropy to Valkey.
This processor intercepts logits during generation to calculate and store normalization constants and entropy values. These values are stored in Valkey for retrieval by the main process after generation completes.
Attributes:
| Name | Type | Description |
|---|---|---|
active_req_ids |
Dict[int, sampling_params]
|
Dictionary mapping request indices to their sampling parameters. |
valkey_client |
Valkey client for storing computed values. |
|
temperature |
Default temperature value. |
Source code in pita/inference/vllm_logits_processor.py
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 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 | |
__init__(vllm_config: VllmConfig, device: torch.device, is_pin_memory: bool) -> None
Initialize the LogitsLoggingProcessor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
vllm_config
|
VllmConfig
|
vLLM configuration object. |
required |
device
|
device
|
PyTorch device for tensor operations. |
required |
is_pin_memory
|
bool
|
Whether to use pinned memory for tensors. |
required |
Source code in pita/inference/vllm_logits_processor.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
apply(logits: torch.Tensor) -> torch.Tensor
Process logits to calculate and log normalization constants and entropy.
This method is called by vLLM for each token generation step. It calculates normalization constants (logsumexp) and entropy values, then stores them in Redis for later retrieval.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Raw logits tensor of shape (batch_size, vocab_size). |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The unmodified logits tensor (this processor only observes, doesn't modify). |
Source code in pita/inference/vllm_logits_processor.py
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 | |
is_argmax_invariant() -> bool
Indicate whether this processor changes which token has the highest probability.
Returns:
| Type | Description |
|---|---|
bool
|
False to ensure apply() is always called, even when it doesn't change argmax. |
Source code in pita/inference/vllm_logits_processor.py
86 87 88 89 90 91 92 93 | |
update_state(batch_update: Optional[BatchUpdate]) -> None
Update processor state when requests are added, removed, or moved in the batch.
This method is called by vLLM to notify the processor of batch changes. It tracks request IDs and their associated sampling parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch_update
|
Optional[BatchUpdate]
|
Information about requests added, removed, or moved in the batch. Can be None if no updates occurred. |
required |
Source code in pita/inference/vllm_logits_processor.py
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 | |
sampling_params
dataclass
Sampling parameters for logits processing requests.
Attributes:
| Name | Type | Description |
|---|---|---|
req_id |
str
|
Unique identifier for the request. |
normalization_constants |
bool
|
Whether to calculate normalization constants. |
temperature |
float
|
Sampling temperature value. |
entropy |
bool
|
Whether to calculate entropy. |
entropy_inference |
bool
|
Whether entropy is used for inference decisions. |
gradient_steps |
int
|
Number of gradient steps for optimization. |
learning_rate |
float
|
Learning rate for optimization. |
delta |
float
|
Delta value for optimization adjustments. |
Source code in pita/inference/vllm_logits_processor.py
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | |