Skip to content

Commit dd127d8

Browse files
authored
[Core][Engine] only materialize tokens when thinking budget is in req (#47053)
Signed-off-by: walterbm <walter.beller.morales@gmail.com>
1 parent 0ca6eee commit dd127d8

2 files changed

Lines changed: 29 additions & 5 deletions

File tree

tests/v1/worker/test_gpu_model_runner.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
VllmConfig,
1919
set_current_vllm_config,
2020
)
21+
from vllm.config.reasoning import ReasoningConfig
2122
from vllm.distributed.parallel_state import (
2223
init_distributed_environment,
2324
initialize_model_parallel,
@@ -255,6 +256,31 @@ def test_select_common_block_size_uses_largest_shared_int():
255256
assert selected_size == 64
256257

257258

259+
def test_reasoning_config_without_custom_logitsprocs_does_not_need_output_token_ids(
260+
dist_init,
261+
):
262+
vllm_config = get_vllm_config()
263+
assert vllm_config.model_config.logits_processors is None
264+
reasoning_config = ReasoningConfig(
265+
reasoning_start_str="<think>", reasoning_end_str="</think>"
266+
)
267+
reasoning_config._reasoning_start_token_ids = [1]
268+
reasoning_config._reasoning_end_token_ids = [2]
269+
vllm_config.reasoning_config = reasoning_config
270+
271+
with set_current_vllm_config(vllm_config):
272+
model_config = vllm_config.model_config
273+
num_heads = model_config.get_num_kv_heads(vllm_config.parallel_config)
274+
head_size = model_config.get_head_size()
275+
vllm_config.compilation_config.static_forward_context["layer.0"] = Attention(
276+
num_heads, head_size, 0.1
277+
)
278+
runner = GPUModelRunner(vllm_config, torch.device("cpu"))
279+
280+
assert runner.input_batch.thinking_budget_state_holder is not None
281+
assert runner.input_batch.logitsprocs_need_output_token_ids is False
282+
283+
258284
@pytest.mark.skip_global_cleanup
259285
@pytest.mark.parametrize(
260286
("world_size", "is_last_rank", "expected_calls"),

vllm/v1/worker/gpu_model_runner.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -702,11 +702,9 @@ def __init__(
702702
custom_logitsprocs,
703703
),
704704
# We currently don't know whether a particular custom logits processor
705-
# uses output token ids so we set this conservatively.
706-
# ThinkingTokenBudgetLogitsProcessor also needs output token ids to
707-
# correctly track think start/end token sequences in async scheduling.
708-
logitsprocs_need_output_token_ids=bool(custom_logitsprocs)
709-
or self.vllm_config.reasoning_config is not None,
705+
# uses output token ids so we set this conservatively. Thinking-budget
706+
# tracking is requested dynamically when a budgeted request is in the batch.
707+
logitsprocs_need_output_token_ids=bool(custom_logitsprocs),
710708
is_pooling_model=self.is_pooling_model,
711709
cp_kv_cache_interleave_size=self.parallel_config.cp_kv_cache_interleave_size,
712710
reasoning_config=self.vllm_config.reasoning_config,

0 commit comments

Comments
 (0)