Skip to content

Commit

Permalink
Update numpy version to latest (#1094)
Browse files Browse the repository at this point in the history
* Update numpy version to latest

* Update problem line to use a helper that takes care of numpy raising ValueErrors when trying to convert ragged sequences
  • Loading branch information
rahul-tuli authored and horheynm committed Jul 6, 2023
1 parent c39f061 commit 0bd7898
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _parse_requirements_file(file_path):


_deps = [
"numpy>=1.16.3,<=1.21.6",
"numpy>=1.16.3",
"onnx>=1.5.0,<1.15.0",
"pydantic>=1.8.2",
"requests>=2.0.0",
Expand Down
18 changes: 17 additions & 1 deletion src/deepsparse/transformers/pipelines/question_answering.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def process_inputs(
span_engine_inputs = []
span_extra_info = []
num_spans = len(tokenized_example["input_ids"])

for span in range(num_spans):
span_input = [
numpy.array(tokenized_example[key][span])
Expand All @@ -259,7 +260,7 @@ def process_inputs(

span_extra_info.append(
{
key: numpy.array(tokenized_example[key][span])
key: _convert_to_numpy_array(tokenized_example[key][span])
for key in tokenized_example.keys()
if key not in self.onnx_input_names
}
Expand Down Expand Up @@ -583,3 +584,18 @@ def _save_predictions(self, all_predictions, all_nbest_json, scores_diff_json):
mode = "a" if os.path.exists(null_odds_file) else "w"
with open(null_odds_file, mode) as writer:
writer.write(json.dumps(scores_diff_json, indent=4) + "\n")


def _convert_to_numpy_array(array):
"""
Convert a list to a numpy array. If the list contains non-numeric values,
convert to an array of objects.
:param array: The list to convert
:return: The converted numpy array
"""
try:
return numpy.array(array)
except ValueError:
# If the array contains non-numeric values, convert to an array of objects
return numpy.array(array, dtype=object)

0 comments on commit 0bd7898

Please sign in to comment.