File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Expand file tree Collapse file tree 2 files changed +11
-5
lines changed Original file line number Diff line number Diff line change @@ -9,4 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
10
10
### Added
11
11
12
- - Added first version of the changelog
12
+ - Added first version of the changelog
13
+
14
+ ### Fixed
15
+
16
+ - Performance bug in stop sequence check slowing down streaming.
Original file line number Diff line number Diff line change @@ -775,20 +775,22 @@ def _create_completion(
775
775
break
776
776
777
777
if stream :
778
+ remaining_tokens = completion_tokens [returned_tokens :]
779
+ remaining_text = self .detokenize (remaining_tokens )
780
+ remaining_length = len (remaining_text )
781
+
778
782
# We want to avoid yielding any characters from
779
783
# the generated text if they are part of a stop
780
784
# sequence.
781
785
first_stop_position = 0
782
786
for s in stop_sequences :
783
- for i in range (len (s ), 0 , - 1 ):
784
- if all_text .endswith (s [:i ]):
787
+ for i in range (min ( len (s ), remaining_length ), 0 , - 1 ):
788
+ if remaining_text .endswith (s [:i ]):
785
789
if i > first_stop_position :
786
790
first_stop_position = i
787
791
break
788
792
789
793
token_end_position = 0
790
- remaining_tokens = completion_tokens [returned_tokens :]
791
- remaining_length = len (self .detokenize (remaining_tokens ))
792
794
for token in remaining_tokens :
793
795
token_end_position += len (self .detokenize ([token ]))
794
796
# Check if stop sequence is in the token
You can’t perform that action at this time.
0 commit comments