-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix schema type constraint for custom operators (#17497)
### Description onnxruntime may raise an error "type inference failed" but when a custom operator sets IsHomogeneous to false in its schema. This change make sure that TypeInferenceFunction and schema type constraints are aligned to prevent that from happening. --------- Co-authored-by: Xavier Dupre <[email protected]@orttrainingdev9.d32nl1ml4oruzj4qz3bqlggovf.px.internal.cloudapp.net> Co-authored-by: Scott McKay <[email protected]>
- Loading branch information
1 parent
011b562
commit 889b1ef
Showing
12 changed files
with
478 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
onnxruntime/test/testdata/custom_op_local_function/custom_op_local_function.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#include "custom_op_local_function.h" | ||
|
||
#include <cmath> | ||
#include <mutex> | ||
#include <utility> | ||
#include <vector> | ||
|
||
#include "core/common/common.h" | ||
#include "core/framework/ortdevice.h" | ||
#include "core/framework/ortmemoryinfo.h" | ||
#include "dummy_gemm.h" | ||
|
||
static const char* c_OpDomain = "onnx_extented.ortops.tutorial.cpu"; | ||
|
||
static void AddOrtCustomOpDomainToContainer(Ort::CustomOpDomain&& domain) { | ||
static std::vector<Ort::CustomOpDomain> ort_custom_op_domain_container; | ||
static std::mutex ort_custom_op_domain_mutex; | ||
std::lock_guard<std::mutex> lock(ort_custom_op_domain_mutex); | ||
ort_custom_op_domain_container.push_back(std::move(domain)); | ||
} | ||
|
||
OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, | ||
const OrtApiBase* api_base) { | ||
Ort::InitApi(api_base->GetApi(ORT_API_VERSION)); | ||
Ort::UnownedSessionOptions session_options(options); | ||
|
||
// An instance remaining available until onnxruntime unload the library. | ||
static Cpu::CustomGemmOp c_CustomGemmFloat( | ||
"CustomGemmFloat", ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, | ||
ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, | ||
false); | ||
static Cpu::CustomGemmOp c_CustomGemmFloat8E4M3FN( | ||
"CustomGemmFloat8E4M3FN", ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT8E4M3FN, | ||
ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, ONNX_TENSOR_ELEMENT_DATA_TYPE_FLOAT, | ||
false); | ||
OrtStatus* result = nullptr; | ||
|
||
ORT_TRY { | ||
Ort::CustomOpDomain domain{c_OpDomain}; | ||
|
||
domain.Add(&c_CustomGemmFloat); | ||
domain.Add(&c_CustomGemmFloat8E4M3FN); | ||
|
||
session_options.Add(domain); | ||
AddOrtCustomOpDomainToContainer(std::move(domain)); | ||
} | ||
ORT_CATCH(const std::exception& e) { | ||
ORT_HANDLE_EXCEPTION([&]() { | ||
Ort::Status status{e}; | ||
result = status.release(); | ||
}); | ||
} | ||
|
||
return result; | ||
} |
3 changes: 3 additions & 0 deletions
3
onnxruntime/test/testdata/custom_op_local_function/custom_op_local_function.def
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
LIBRARY "custom_op_local_function.dll" | ||
EXPORTS | ||
RegisterCustomOps @1 |
15 changes: 15 additions & 0 deletions
15
onnxruntime/test/testdata/custom_op_local_function/custom_op_local_function.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
#pragma once | ||
#include "onnxruntime_c_api.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
ORT_EXPORT OrtStatus* ORT_API_CALL RegisterCustomOps(OrtSessionOptions* options, const OrtApiBase* api); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif |
Oops, something went wrong.