From 28026148467dcbfca05a87e51535db9b92532f10 Mon Sep 17 00:00:00 2001 From: RandySheriffH <48490400+RandySheriffH@users.noreply.github.com> Date: Tue, 30 May 2023 16:43:22 -0700 Subject: [PATCH] Condition the usage of variadic callback by version (#16112) For older versions of custom ops, optional and variadic callbacks are null pointers, hence adding conditions to scope the usage. --------- Co-authored-by: Randy Shuai --- onnxruntime/core/session/custom_ops.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/onnxruntime/core/session/custom_ops.cc b/onnxruntime/core/session/custom_ops.cc index c510308da0..390d9b35f2 100644 --- a/onnxruntime/core/session/custom_ops.cc +++ b/onnxruntime/core/session/custom_ops.cc @@ -21,6 +21,11 @@ #include "core/session/inference_session.h" #include "core/session/ort_apis.h" +#if !defined(ORT_MINIMAL_BUILD) +static constexpr uint32_t min_ort_version_with_optional_io_support = 8; +static constexpr uint32_t min_ort_version_with_variadic_io_support = 14; +#endif + ORT_API_STATUS_IMPL(OrtApis::KernelInfoGetAttribute_float, _In_ const OrtKernelInfo* info, _In_ const char* name, _Out_ float* out) { API_IMPL_BEGIN auto status = reinterpret_cast(info)->GetAttr(name, out); @@ -467,9 +472,6 @@ KernelCreateInfo CreateKernelCreateInfo(const std::string& domain, const OrtCust } ONNX_NAMESPACE::OpSchema CreateSchema(const std::string& domain, const OrtCustomOp* op) { - constexpr uint32_t min_ort_version_with_optional_io_support = 8; - constexpr uint32_t min_ort_version_with_variadic_io_support = 14; - const size_t input_count = op->GetInputTypeCount(op); const size_t output_count = op->GetOutputTypeCount(op); int undefined = 0; @@ -562,7 +564,8 @@ Status IsCompatible(const ONNX_NAMESPACE::OpSchema& schema, const OrtCustomOp* o const auto characteristic = op->GetInputCharacteristic(op, i); const auto& formal_parameter = input_parameters[i]; if (characteristic == OrtCustomOpInputOutputCharacteristic::INPUT_OUTPUT_OPTIONAL) { - ORT_RETURN_IF_NOT(formal_parameter.GetOption() == onnx::OpSchema::FormalParameterOption::Optional, + ORT_RETURN_IF_NOT(op->version < min_ort_version_with_optional_io_support || + formal_parameter.GetOption() == onnx::OpSchema::FormalParameterOption::Optional, "custom op schemas mismatch, expecting ", i + 1, i == 0 ? "st" : (i == 1 ? "nd" : "th"), " input to be of optional type"); @@ -571,7 +574,8 @@ Status IsCompatible(const ONNX_NAMESPACE::OpSchema& schema, const OrtCustomOp* o "custom op schemas mismatch, expecting ", i + 1, i == 0 ? "st" : (i == 1 ? "nd" : "th"), " input to be of variadic type"); - ORT_RETURN_IF_NOT(formal_parameter.GetIsHomogeneous() == (op->GetVariadicInputHomogeneity(op) != 0), + ORT_RETURN_IF_NOT(op->version < min_ort_version_with_variadic_io_support || + formal_parameter.GetIsHomogeneous() == (op->GetVariadicInputHomogeneity(op) != 0), "custom op schemas mismatch, expecting ", i + 1, i == 0 ? "st" : (i == 1 ? "nd" : "th"), " input to keep same homogeneity");