Skip to content

Commit 80a6920

Browse files
fix: slice stopping criteria buffer
1 parent 083c2de commit 80a6920

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

server/text_generation_server/utils/tokens.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def __init__(
112112
self.stop_sequence_criterias = stop_sequence_criterias
113113
self.max_new_tokens = max_new_tokens
114114
self.current_tokens = 0
115-
self.current_output = ""
115+
self.current_output = "test"
116116
self.ignore_eos_token = ignore_eos_token
117117

118118
def __call__(self, last_token: int, last_output: str) -> Tuple[bool, Optional[str]]:
@@ -124,6 +124,10 @@ def __call__(self, last_token: int, last_output: str) -> Tuple[bool, Optional[st
124124
return True, FinishReason.FINISH_REASON_EOS_TOKEN
125125

126126
self.current_output += last_output
127+
# There is no need to keep an output that is too long
128+
if len(self.current_output) > 300:
129+
# Slice to -200 to avoid doing it all the time
130+
self.current_output = self.current_output[-200:]
127131
for stop_sequence_criteria in self.stop_sequence_criterias:
128132
if stop_sequence_criteria(self.current_output):
129133
return True, FinishReason.FINISH_REASON_STOP_SEQUENCE

0 commit comments

Comments
 (0)