Skip to content

Commit 1dd9190

Browse files
committed
Fixed: Only compare the 0 index after ensuring that the content exists.
1 parent ed502c5 commit 1dd9190

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

llama_cpp/llama.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2565,16 +2565,16 @@ def longest_token_prefix(current_ids: Sequence[int], new_tokens: Sequence[int])
25652565
if not current_ids or not new_tokens:
25662566
return 0
25672567

2568-
# Probe inspection: Use Python to quickly compare the first token
2569-
# If the tokens are different from the beginning, return immediately to avoid any NumPy overhead.
2570-
if current_ids[0] != new_tokens[0]:
2571-
return 0
2572-
25732568
# Determine the comparison range (limited by the shorter sequence)
25742569
min_len = min(len(current_ids), len(new_tokens))
25752570
if min_len == 0:
25762571
return 0
25772572

2573+
# Probe inspection: Use Python to quickly compare the first token
2574+
# If the tokens are different from the beginning, return immediately to avoid any NumPy overhead.
2575+
if current_ids[0] != new_tokens[0]:
2576+
return 0
2577+
25782578
# Accelerating SIMD for Large Data Volumes
25792579
# Only transform necessary slices, avoid processing irrelevant data
25802580
# Use asarray to ensure zero-copy (if the input is already an array)

0 commit comments

Comments
 (0)