[MRV2][Performance] Skip no-op FP32 logits materialization (#47711)
Signed-off-by: jesse <szxfml@gmail.com> Signed-off-by: Song Zhixin <szxfml@gmail.com> Co-authored-by: Wentao Ye <44945378+yewentao256@users.noreply.github.com> Co-authored-by: Jee Jee Li <pandaleefree@gmail.com>
Song Zhixin committed
Jul 27, 2026 at 23:31 UTC
d2ca3002d93314a08bbddf9c6eb6ee78b1343407
1 file changed
+21
vllm/v1/worker/gpu/sample/sampler.py
+21
@@ -152,6 +152,9 @@ class Sampler:
152
expanded_local_pos: torch.Tensor,
153
skip_top_k_top_p: bool = False,
154
) -> torch.Tensor:
155
+ if not self._requires_logits_processing(idx_mapping_np):
156
+ return logits
157
+
158
# Copy logits to a new FP32 tensor.
159
logits = torch.empty_like(logits, dtype=torch.float32).copy_(logits)
160
@@ -194,6 +197,24 @@ class Sampler:
197
logits, expanded_idx_mapping, idx_mapping_np
198
)
199
200
+ def _requires_logits_processing(self, idx_mapping_np: np.ndarray) -> bool:
201
+ if np.any(self.logit_bias_state.use_logit_bias[idx_mapping_np]):
202
+ return True
203
+ if np.any(self.penalties_state.use_penalty[idx_mapping_np]):
204
+ return True
205
+ if np.any(self.bad_words_state.num_bad_words.np[idx_mapping_np] > 0):
206
+ return True
207
+
208
+ states = self.sampling_states
209
+ temperatures = states.temperature.np[idx_mapping_np]
210
+ if np.any((temperatures != 0.0) & (temperatures != 1.0)):
211
+ return True
212
+ if np.any(states.min_p.np[idx_mapping_np] != 0.0):
213
+ return True
214
+ if np.any(states.top_k.np[idx_mapping_np] != states.vocab_size):
215
+ return True
216
+ return bool(np.any(states.top_p.np[idx_mapping_np] != 1.0))
217
+
218
def sample(
219
self,
220
logits: torch.Tensor,