Skip to content

Commit 6efad85

Browse files
committed
refactor processor
Signed-off-by: Sungjae Lee <[email protected]> Signed-off-by: Sungjae Lee <[email protected]>
1 parent 7b2dcc5 commit 6efad85

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

vllm/v1/sample/logits_processor/builtin.py

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -352,43 +352,48 @@ def _update_think_state(self, state: dict[str, Any]):
352352
if not state["in_end"]:
353353
if recent_start_pos >= 0 and recent_end_pos >= 0:
354354
if recent_start_pos > recent_end_pos:
355-
# Case: ...<end>...<start>...
355+
# Case: ...<end>...<start>... - entering think mode
356356
absolute_start_pos = check_start_idx + recent_start_pos
357+
new_think_count = current_length - (absolute_start_pos +
358+
start_len)
357359
state["in_think"] = True
358-
state["think_count"] = current_length - (
359-
absolute_start_pos + start_len)
360-
state["check_count_down"] = state[
361-
"thinking_token_budget"] - state["think_count"]
360+
state["think_count"] = new_think_count
362361
else:
363-
# Case: ...<start>...<end>...
362+
# Case: ...<start>...<end>... - exiting think mode
364363
state["in_think"] = False
365364
state["think_count"] = 0
366365
elif recent_start_pos >= 0:
367-
# Found think start in recent tokens
366+
# Found think start - entering think mode
368367
absolute_start_pos = check_start_idx + recent_start_pos
368+
new_think_count = current_length - (absolute_start_pos +
369+
start_len)
369370
state["in_think"] = True
370-
state["think_count"] = current_length - (absolute_start_pos +
371-
start_len)
372-
state["check_count_down"] = state[
373-
"thinking_token_budget"] - state["think_count"]
371+
state["think_count"] = new_think_count
374372
elif recent_end_pos >= 0:
375-
# Found think end in recent tokens
373+
# Found think end - exiting think mode
376374
state["in_think"] = False
377375
state["think_count"] = 0
378-
state["check_count_down"] = state["thinking_token_budget"]
379376
elif state["in_think"]:
380377
# Continue thinking mode, increment count by new tokens
381378
state["think_count"] += len(new_tokens)
382379

383-
if state["in_think"] and state["think_count"] \
384-
>= state["thinking_token_budget"]:
385-
state.update({
386-
"in_think": False,
387-
"in_end": True,
388-
"end_count": 0,
389-
"check_count_down": state["thinking_token_budget"]
390-
})
380+
# Set countdown based on current state
381+
if state["in_think"]:
382+
remaining_budget = max(
383+
0, state["thinking_token_budget"] - state["think_count"])
384+
state["check_count_down"] = remaining_budget
385+
else:
386+
state["check_count_down"] = state["thinking_token_budget"]
387+
388+
# Check if need to transition to end mode
389+
if state["in_think"] and state["think_count"] >= state[
390+
"thinking_token_budget"]:
391+
state["in_think"] = False
392+
state["in_end"] = True
393+
state["end_count"] = 0
394+
state["check_count_down"] = state["thinking_token_budget"]
391395
else:
396+
# In end mode
392397
state["end_count"] += 1
393398
if state["end_count"] >= len(self.think_end_token_ids):
394399
state.update({
@@ -503,4 +508,3 @@ def process_dict_updates(
503508
req_entries[a_index] = b_entry
504509

505510
return updated
506-

0 commit comments

Comments
 (0)