mirror of
https://github.com/huggingface/transformers.git
synced 2025-07-31 02:02:21 +06:00
Add warning for stop string edge case (#33169)
* Add warning for edge case * make fixup
This commit is contained in:
parent
e259d6d1e0
commit
fbff27623a
@ -348,7 +348,14 @@ class StopStringCriteria(StoppingCriteria):
|
||||
# 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)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user