Selective load ONNX schema by specific opset_version#3266
Selective load ONNX schema by specific opset_version#3266askhade merged 63 commits intoonnx:masterfrom
Conversation
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
|
This pull request introduces 1 alert when merging 7396ccb into 1cbd549 - view on LGTM.com new alerts:
|
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
| option(ONNX_USE_LITE_PROTO "Use lite protobuf instead of full." OFF) | ||
| option(ONNXIFI_ENABLE_EXT "Enable onnxifi extensions." OFF) | ||
| option(ONNX_DISABLE_EXCEPTIONS "Disable exception handling." OFF) | ||
| option(ONNX_DISABLE_STATIC_REGISTRATION "Do not create static registration." OFF) |
There was a problem hiding this comment.
nit: change comment to : Disable static registration for onnx operator schemas
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
| endif() | ||
|
|
||
| if(ONNX_DISABLE_STATIC_REGISTRATION) | ||
| target_compile_definitions(${target} PUBLIC "__ONNX_DISABLE_STATIC_REGISTRATION=1") |
There was a problem hiding this comment.
I followed the same logic as ONNX_ML and ONNX_USE_LITE_PROTO, but yes I think pure __ONNX_DISABLE_STATIC_REGISTRATION should be also workable. Let's try it.
|
|
||
| void RegisterCustomFuncFloatSchema() { | ||
| ONNX_NAMESPACE::OpSchema schema; | ||
| #ifdef __ONNX_DISABLE_STATIC_REGISTRATION |
There was a problem hiding this comment.
I was also considering whether to revert it... Just in case if someone wants to test C++ ONNX with ONNX_DISABLE_STATIC_REGISTRATION=ON and bumps into issue here. However, even if that is the case, the whole test will still fail with schema_test.cc anyway... So I will remove it. Thanks.
There was a problem hiding this comment.
what would be the issue in that case?
There was a problem hiding this comment.
oh you mean this test and schema_registration_test cannot go together?
There was a problem hiding this comment.
Yes, then it will still fail so the if condition here is useless
| static int loaded_schema_version; | ||
|
|
||
| public: | ||
| static OpName_Domain_Version_Schema_Map& map(); |
There was a problem hiding this comment.
why are you changing the accessibility from private to public?
| */ | ||
|
|
||
| #include <iostream> | ||
| #include "gtest/gtest.h" |
There was a problem hiding this comment.
nit: rename file schema_registration_test.cc
| namespace Test { | ||
|
|
||
| TEST(SchemaTest, RegisterCertainOpsetSchema) { | ||
| #ifdef __ONNX_DISABLE_STATIC_REGISTRATION |
There was a problem hiding this comment.
add some comments explaining why this test is run only when static registration is disabled
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
|
All updated. Thank you @askhade for all the reviews |
| // is compared against the number of calls to schema registration macros. | ||
| #ifndef NDEBUG | ||
| size_t dbg_initial_schema_count = GetRegisteredSchemaCount(); | ||
| size_t dbg_initial_schema_count = OpSchemaRegistry::GetRegisteredSchemaCount(); |
There was a problem hiding this comment.
this needs to move back under private right?
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
Signed-off-by: Chun-Wei Chen <jacky82226@gmail.com>
|
Hi @jcwchen , thank you very much for introducing this change. Per my understanding, this allows a Runtime to register ONLY the specific opset schema. However, turning on If so, I want to get your thought on introducing an ONNX API to "offload" schema at runtime. The goal is to reduce MaxRSS in Runtime framework - granted that a Runtime may not need ONNX schema after model loading stage, but still needs to reserve aside RSS for it. Do you think there's obvious reason against adding such a feature? If not, i'm happy to contribute and would appreciate any pointer. So far the "registration" looks like it's inserting pairs into the static |
|
Hi @q-ycong-p, |
|
Thank you @jcwchen for the detailed reply. We have a runtime inference framework that depends on ONNX as one of the supported model formats. However unlike ONNXRuntime, we do not rely on ONNX graph representation for inference, hence this will be a beneficial ONNX-level feature for us, and for other similar downstream runtimes I think. I will experiment on my side and update further. If easy I'll open a PR, if tricky for me, I may seek community help as a feature request. |
|
Hi @jcwchen, I'd like to ask for your thoughts on a few items:
Moving forward, to expose the appropriate handles to runtime, I'm thinking (naively), in order of importance:
Will this seem to make sense? Any advise against pitfall is appreciated here! |
Personally I vote for 2) in ONNX-level. And we can have additional API to remove registered schema (all or specified). In principle, I prefer keeping ONNX simple and providing runtime sufficient onload/offload API for complex scenario. That is to say, we can still use multiple functions from ONNX to achieve 1) in runtime as well.
Yes, I think we might need another standalone registration function without that error (or enabling an option to ignore that error in the same function if feasible). I will take a closer look at your PR and we can continue the discussion there. |
|
I agree that the principle is to keep ONNX simple and provide runtime sufficient onload/offload APIs. Concretely I think this means ONNX to provide APIs for runtime to:
pull#5221 simply de-registers all, for a quick turn-around to measure runtime-side memory delta on my side. I will try iterate in the PR there to expand. Also would really appreciate your input there! Ty! |
Description
Motivation
To reduce memory usage in Runtime, make ONNX schema load specific opset_version.