Skip to content

Commit

Permalink
io_binding to handle optional input of sequence type_proto (#19273)
Browse files Browse the repository at this point in the history
  • Loading branch information
liqunfu authored Jan 30, 2024
1 parent ffc3431 commit b84cb24
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion onnxruntime/python/onnxruntime_pybind_mlvalue.cc
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,12 @@ static bool CheckIfInputIsSequenceType(const std::string& name_input,
if (!temp) {
throw std::runtime_error("Corresponding type_proto is null");
} else {
type_proto = *temp;
if (temp->has_optional_type()) {
const ::onnx::TypeProto_Optional& optional_type_proto = temp->optional_type();
type_proto = optional_type_proto.elem_type();
} else {
type_proto = *temp;
}
}

return type_proto.has_sequence_type();
Expand Down
8 changes: 8 additions & 0 deletions onnxruntime/test/python/onnxruntime_test_python.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,14 @@ def do_test_get_and_set_tuning_results(ep):
if "ROCMExecutionProvider" in onnxrt.get_available_providers():
do_test_get_and_set_tuning_results("ROCMExecutionProvider")

def test_run_model_with_optional_sequence_input(self):
sess = onnxrt.InferenceSession(get_name("identity_opt.onnx"))
x = [np.array([1, 2, 3, 4, 5]).astype(np.float32)]
input_name = sess.get_inputs()[0].name
output_name = sess.get_outputs()[0].name
res = sess.run([output_name], {input_name: x})
np.testing.assert_allclose(res[0], x)

def test_run_model(self):
sess = onnxrt.InferenceSession(get_name("mul_1.onnx"), providers=available_providers)
x = np.array([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]], dtype=np.float32)
Expand Down
Binary file added onnxruntime/test/testdata/identity_opt.onnx
Binary file not shown.

0 comments on commit b84cb24

Please sign in to comment.