Skip to content

Commit

Permalink
Remove one of the duplicate bos tokens (#2708)
Browse files Browse the repository at this point in the history
* Remove one of the duplicate bos tokens

* Update tokenizer.py
  • Loading branch information
AllentDan authored Nov 12, 2024
1 parent 4a8d745 commit 67a8538
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lmdeploy/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,14 @@ def encode(self,
Returns:
list[int]: token ids
"""
return self.model.encode(s, add_bos, add_special_tokens, **kwargs)
encoded = self.model.encode(s, add_bos, add_special_tokens, **kwargs)
if encoded[:2] == [self.bos_token_id] * 2:
get_logger('lmdeploy').warn(
f'Detected duplicate bos token {self.bos_token_id} in prompt, '
'this will likely reduce response quality, one of them will be'
'removed')
encoded = encoded[1:]
return encoded

def decode(
self,
Expand Down

0 comments on commit 67a8538

Please sign in to comment.