Skip to content

Commit e55533f

Browse files
committed
refactor processor
Signed-off-by: Sungjae Lee <[email protected]> Signed-off-by: Sungjae Lee <[email protected]>
1 parent 91ab9fd commit e55533f

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

vllm/v1/sample/logits_processor/builtin.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -417,43 +417,48 @@ def _update_think_state(self, state: dict[str, Any]):
417417
if not state["in_end"]:
418418
if recent_start_pos >= 0 and recent_end_pos >= 0:
419419
if recent_start_pos > recent_end_pos:
420-
# Case: ...<end>...<start>...
420+
# Case: ...<end>...<start>... - entering think mode
421421
absolute_start_pos = check_start_idx + recent_start_pos
422+
new_think_count = current_length - (absolute_start_pos +
423+
start_len)
422424
state["in_think"] = True
423-
state["think_count"] = current_length - (
424-
absolute_start_pos + start_len)
425-
state["check_count_down"] = state[
426-
"thinking_token_budget"] - state["think_count"]
425+
state["think_count"] = new_think_count
427426
else:
428-
# Case: ...<start>...<end>...
427+
# Case: ...<start>...<end>... - exiting think mode
429428
state["in_think"] = False
430429
state["think_count"] = 0
431430
elif recent_start_pos >= 0:
432-
# Found think start in recent tokens
431+
# Found think start - entering think mode
433432
absolute_start_pos = check_start_idx + recent_start_pos
433+
new_think_count = current_length - (absolute_start_pos +
434+
start_len)
434435
state["in_think"] = True
435-
state["think_count"] = current_length - (absolute_start_pos +
436-
start_len)
437-
state["check_count_down"] = state[
438-
"thinking_token_budget"] - state["think_count"]
436+
state["think_count"] = new_think_count
439437
elif recent_end_pos >= 0:
440-
# Found think end in recent tokens
438+
# Found think end - exiting think mode
441439
state["in_think"] = False
442440
state["think_count"] = 0
443-
state["check_count_down"] = state["thinking_token_budget"]
444441
elif state["in_think"]:
445442
# Continue thinking mode, increment count by new tokens
446443
state["think_count"] += len(new_tokens)
447444

448-
if state["in_think"] and state["think_count"] \
449-
>= state["thinking_token_budget"]:
450-
state.update({
451-
"in_think": False,
452-
"in_end": True,
453-
"end_count": 0,
454-
"check_count_down": state["thinking_token_budget"]
455-
})
445+
# Set countdown based on current state
446+
if state["in_think"]:
447+
remaining_budget = max(
448+
0, state["thinking_token_budget"] - state["think_count"])
449+
state["check_count_down"] = remaining_budget
450+
else:
451+
state["check_count_down"] = state["thinking_token_budget"]
452+
453+
# Check if need to transition to end mode
454+
if state["in_think"] and state["think_count"] >= state[
455+
"thinking_token_budget"]:
456+
state["in_think"] = False
457+
state["in_end"] = True
458+
state["end_count"] = 0
459+
state["check_count_down"] = state["thinking_token_budget"]
456460
else:
461+
# In end mode
457462
state["end_count"] += 1
458463
if state["end_count"] >= len(self.think_end_token_ids):
459464
state.update({

0 commit comments

Comments
 (0)