Skip to content

Commit

Permalink
[Cherry-Pick][Fix] deepsparse – tokenizer stride size issue with orig…
Browse files Browse the repository at this point in the history
…inal transformers (#1426)

* [Fix] Remove erronous LIB.kv_cache input when using external kv cache management (#1337)

* initial commit

* initial commit

* cleanup

* cleanup2

* initial commit

* final solution
  • Loading branch information
dbogunowicz committed Nov 22, 2023
1 parent 0d5c7b7 commit 65a38cc
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/deepsparse/transformers/pipelines/question_answering.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import json
import logging
import os
import warnings
from typing import Any, Dict, List, Optional, Tuple, Type

import numpy
Expand Down Expand Up @@ -504,6 +505,20 @@ def route_input_to_bucket(
def _tokenize(self, example: SquadExample, *args):
# The logic here closely matches the tokenization step performed
# on evaluation dataset in the SparseML question answering training script

added_special_tokens = self.tokenizer.num_special_tokens_to_add()
effective_max_length = self.sequence_length - added_special_tokens
if self.doc_stride >= effective_max_length:
new_doc_stride = effective_max_length
warnings.warn(
f"Tokenizer stride set to {self.doc_stride}, "
f"which is greater than or equal to its effective max length "
f"of {effective_max_length} (= {self.sequence_length} "
f"original max length - {added_special_tokens} added special tokens). "
f"Capping the doc stride to {new_doc_stride}"
)
self._doc_stride = new_doc_stride

if not self.tokenizer.is_fast:
raise ValueError(
"This example script only works for models that have a fast tokenizer."
Expand Down

0 comments on commit 65a38cc

Please sign in to comment.