Skip to content

Commit

Permalink
Add warning for stop string edge case (huggingface#33169)
Browse files Browse the repository at this point in the history
* Add warning for edge case

* make fixup
  • Loading branch information
Rocketknight1 authored and itazap committed Sep 20, 2024
1 parent 1900d40 commit f51e442
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/transformers/generation/stopping_criteria.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,14 @@ def _stop_string_create_embedding_vec(token_list, token_indices, stop_strings) -
# we need a fallback to handle this case
max_valid_positions = max(all_valid_positions) if all_valid_positions else 1
# There should always be at least one valid end_len, however, so no fallback needed here
max_valid_end_lens = max(len(val) for positions in token_end_overlaps.values() for val in positions.values())
valid_end_lens = [len(val) for positions in token_end_overlaps.values() for val in positions.values()]
if not valid_end_lens:
raise ValueError(
"Stop string preprocessing was unable to identify tokens matching one or more of the "
"supplied stop string(s). This is most often caused by the stop "
"strings containing unusual characters that are not in the tokenizer vocabulary."
)
max_valid_end_lens = max(valid_end_lens)
vec_size = len(stop_strings) * (max_valid_positions + max_valid_end_lens) + 1
gather_vec = np.full((len(token_list), vec_size), dtype=np.int32, fill_value=-1)

Expand Down

0 comments on commit f51e442

Please sign in to comment.