From 2ae910ed88121d7c3acdcb9bab14cd968257b6e6 Mon Sep 17 00:00:00 2001 From: Izik Golan <47969623+izikgo@users.noreply.github.com> Date: Wed, 20 May 2026 06:16:07 +0300 Subject: [PATCH] [Perf] Avoid forward scan for async output placeholders (#42938) --- vllm/v1/worker/gpu_input_batch.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/vllm/v1/worker/gpu_input_batch.py b/vllm/v1/worker/gpu_input_batch.py index 31571e9db2..89d69c0bde 100644 --- a/vllm/v1/worker/gpu_input_batch.py +++ b/vllm/v1/worker/gpu_input_batch.py @@ -1050,7 +1050,12 @@ class InputBatch: # output placeholders (tokens can be discarded after kv-load # failure) or a larger number (async spec decode adds optimistic # placeholders that may exceed the actual acceptance count). - first_placeholder = req_output_token_ids.index(-1) + first_placeholder = len(req_output_token_ids) + while ( + first_placeholder > 0 + and req_output_token_ids[first_placeholder - 1] == -1 + ): + first_placeholder -= 1 num_placeholders = len(req_output_token_ids) - first_placeholder num_to_replace = min(num_sampled_ids, num_placeholders) del new_ids[num_to_replace:]