Skip to content

Commit

Permalink
Remove the stripping of the prefix space (and any other mangling that
Browse files Browse the repository at this point in the history
tokenizers might do).

Superseed #1024

Co-Authored-By: bangoz <[email protected]>
  • Loading branch information
Narsil and chxie-pku committed Sep 26, 2023
1 parent ae623b8 commit 76d5bbb
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
6 changes: 4 additions & 2 deletions server/text_generation_server/models/causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,8 +641,10 @@ def generate_token(
if i % self.world_size == self.rank:
if stop:
# Decode generated tokens
output_text = self.decode(
all_input_ids[-stopping_criteria.current_tokens :, 0]
output_text, _, _ = self.decode_token(
all_input_ids[:, 0],
prefix_offset=len(all_input_ids) - stopping_criteria.current_tokens - 1,
read_offset=len(all_input_ids) - stopping_criteria.current_tokens,
)
# Get seed
if isinstance(next_token_chooser.choice, Sampling):
Expand Down
6 changes: 4 additions & 2 deletions server/text_generation_server/models/flash_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1008,8 +1008,10 @@ def generate_token(
if i % self.world_size == self.rank:
if stop:
# Decode generated tokens
output_text = self.decode(
all_input_ids[-stopping_criteria.current_tokens :]
output_text, _, _ = self.decode_token(
all_input_ids,
prefix_offset=len(all_input_ids) - stopping_criteria.current_tokens - 1,
read_offset=len(all_input_ids) - stopping_criteria.current_tokens,
)
generated_text = GeneratedText(
output_text,
Expand Down
11 changes: 4 additions & 7 deletions server/text_generation_server/models/idefics_causal_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -611,11 +611,6 @@ def __init__(
def batch_type(self) -> Type[IdeficsCausalLMBatch]:
return IdeficsCausalLMBatch

def decode(self, generated_ids: List[int]) -> str:
return self.tokenizer.decode(
generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=False
)

def forward(
self,
input_ids,
Expand Down Expand Up @@ -728,8 +723,10 @@ def generate_token(
if i % self.world_size == self.rank:
if stop:
# Decode generated tokens
output_text = self.decode(
all_input_ids[-stopping_criteria.current_tokens :, 0]
output_text, _, _ = self.decode_token(
all_input_ids[:, 0],
prefix_offset=len(all_input_ids) - stopping_criteria.current_tokens - 1,
read_offset=len(all_input_ids) - stopping_criteria.current_tokens,
)
# Get seed
if isinstance(next_token_chooser.choice, Sampling):
Expand Down
6 changes: 4 additions & 2 deletions server/text_generation_server/models/seq2seq_lm.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,8 +710,10 @@ def generate_token(
if stop:
# Slice with decoder_input_length to remove padding
# Decode all tokens
output_text = self.decode(
all_decoder_input_ids[-decoder_input_length:]
output_text, _, _ = self.decode_token(
all_decoder_input_ids,
prefix_offset=len(all_decoder_input_ids) - decoder_input_length - 1,
read_offset=len(all_decoder_input_ids) - decoder_input_length,
)

# Get seed
Expand Down

0 comments on commit 76d5bbb

Please sign in to comment.