Reduce binary size of libraries consuming ONNX (part 1/2)#2643
Reduce binary size of libraries consuming ONNX (part 1/2)#2643gramalingam merged 24 commits intoonnx:masterfrom
Conversation
| 11, | ||
| OpSchema() | ||
| .SetDoc(std::string(BitShift_ver11_doc) + GenerateBroadcastingDocMul()) | ||
| .SetDoc(GetBitShiftDoc()) |
There was a problem hiding this comment.
The addition of the output from GenerateBroadcastingDocMul() inhibits the linker from throwing away BitShift_ver11_doc. Hence the introduction of the function GetBitShiftDoc().
| std::function<void(OpSchema&)> BinaryLogicDocGenerator_opset1( | ||
| const char* name) { | ||
| return [=](OpSchema& schema) { | ||
| #ifndef __ONNX_NO_DOC_STRINGS |
There was a problem hiding this comment.
This kind of setup of the doc doesn't help in removing these strings from the binary. Hence the check for __ONNX_NO_DOC_STRINGS here.
| } | ||
|
|
||
| OpSchema& SetDoc(std::string doc); | ||
| OpSchema& SetDoc(const std::string& doc) { |
There was a problem hiding this comment.
Changed to const-ref. No need to pay for the copy of doc/description if we're not going to copy it. Ditto for Input() and Output() functions.
|
cc @linkerzhang |
|
Can this make it to 1.7 release? |
|
Is there any existing issue going on with CircleCI? I see that ci/circleci: py3.6-clang7-ubuntu16.04 is failing for other PRs too that were a day or so old. |
|
circleci is not a required ci for onnx, which may be ignored. @spandantiwari for the awareness of the failure, btw. |
|
Any more comments that need to be addressed here? |
|
Unfortunately, there appears to be some conflicts to be resolved. |
|
Can this be merged once CI is complete? |
* Fix Greater/LessOrEqual function definition (#2645) * Fix Greater/LessOrEqual function definition * Update test data Co-authored-by: Ke Zhang <kezhan@microsoft.com> * Suppress a warning in unsqueeze (#2637) I keep getting this warning when building PyTorch: ``` In file included from /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/utils.h:6, from /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc:4: /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc: In lambda function: /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc:1414:22: warning: unnecessary parentheses in declaration of â��iâ�� [-Wparentheses] for (size_t(i) = 0; i < axes.size(); ++i) { ^ /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/schema.h:959:12: note: in definition of macro â��ONNX_OPERATOR_SET_SCHEMA_EXâ�� return impl.SetName(#name) \ ^~~~ /home/hong/wsrc/pytorch/third_party/onnx/onnx/defs/tensor/defs.cc:1369:1: note: in expansion of macro â��ONNX_OPERATOR_SET_SCHEMAâ�� ONNX_OPERATOR_SET_SCHEMA( ``` This commit should fix it and modernize the code a bit. Co-authored-by: Ke Zhang <kezhan@microsoft.com> * [Training] Add Adagrad optimizer operator (#1955) * Adagrad draft * MIMO * Support multiple tensors to be optimized * Address comments * Move optimizers to a new place Remove copied Add momentum Save Remove momentum Fix Move constants to attributes * Fix build * Add shape test Add two node tests Update test coverage * Fix shape inf * Fix shape inf * fix shape inf * Format * Add function type * Merge lines * Format * Fix version number * Update op version in model files * Fix a test function and update related test files * Update onnx/backend/test/case/node/adagrad.py * Remove unused file * sync docs * Fix shape test * sync doc * sync with master * Update onnx/defs/training/defs.cc Co-Authored-By: Michał Karzyński <postrational@users.noreply.github.com> * sync doc * address comments * address a minor comment * Polish one line Co-authored-by: Michał Karzyński <postrational@users.noreply.github.com> * [Training] SG with Momentum Optimizer (#1959) * SG with Momentum * Registrate Op Fix Update other docs * Add shape inference code and polish definition * Update docs * Add test cases and fix several bugs * Remove accidently added copy * Alpha -> alpha & Beta -> beta * Clarify an attribute * Fix an attribute * Fix bug * Fix missing attributes * sync doc * Remove unused domain * sync with master Co-authored-by: Chin Huang <chhuang@us.ibm.com> * Change type of label tensor to int32/int64 in SoftmaxCrossEntropyLoss spec. (#2667) * Update Pow input types in Opset 12 (#2666) * Update Pow input types in Opset 12 * gen doc and tests * remove uints and 8 bit ints * add tests * remove uint int x tets * Adding CI for ONNX Debug mode (Linux, OSX) (#2651) * adding an osx build, linux build, with and without onnx_ml for debug mode * test debug mode with ONNX_ML=1 * Rename OPTIONAL to OPTIONAL_VALUE (#2682) Co-authored-by: G. Ramalingam <grama@microsoft.com> * Update Batchnorm test (#2674) * Update Batchnorm test * relax shape inference on scalar * Remove unnecessary copies and std::move (#2684) * Update sequence test case so input is not scalar and splits are specified (#2675) * Update sequence test case to input is not scalar and splits are specified * Add spaces to make the checker happy * Use cmake GNUInstallDirs (#2661) https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html this make allow install the libraries (and headers) in different location than `lib` (Gentoo uses lib64 for 64-bits libs) also change the .cmake files for avoid conclicts if build both 32-bis and 64-bits (avoids conflict/overwrite files) Co-authored-by: Ke Zhang <kezhan@microsoft.com> * Add 'ignore_index' input in the spec for SoftmaxCrossEntropyLoss and NLLLoss. (#2680) * Add 'ignore_index' input in the spec for SoftmaxCrossEntropyLoss and NLLLoss. * Add tests. * build break. * build break. * clean up. * build break. * Change ignore_index to attribute. * Change ignore_index to attribute. * PR feedback. * PR feedback. * Make ignore_index optional in NLLLoss. * Build break. * remove trailing spaces to fix build break. * Build break. * Update spec doc. * Fix NLLLoss function definition to fix test: test_negative_log_likelihood_loss_input_shape_is_NCd1d2_with_weight_reduction_sum_ignore_index_expanded * PR feedback. * Fix test for softmax cross entropy loss to exclude ignored_index'ed weights from the sum of weights. * Build break. * Reduce binary size of libraries consuming ONNX (part 1/2) (#2643) * Change the return type for the zipmap operator to match the description in the spec. * Reduce binary size of libraries consuming ONNX (part 1/2) * Fix build error * Replace separate Get*Doc() functions with easy macro for greater convenience * Add one more macro for complicated operator doc documentation. Co-authored-by: Ke Zhang <kezhan@microsoft.com> * Update pybind (#2340) (#2688) * Change version number for release verification Change version number for release verification Co-authored-by: Takeshi Watanabe <take-cheeze@users.noreply.github.com> Co-authored-by: Ke Zhang <kezhan@microsoft.com> Co-authored-by: Hong Xu <hong@topbug.net> Co-authored-by: Wei-Sheng Chin <wschin@outlook.com> Co-authored-by: Michał Karzyński <postrational@users.noreply.github.com> Co-authored-by: M. Zeeshan Siddiqui <mzs@microsoft.com> Co-authored-by: Lara Haidar <haidar.lara@gmail.com> Co-authored-by: Vinitra Swamy <vinitras@gmail.com> Co-authored-by: Changming Sun <chasun@microsoft.com> Co-authored-by: G. Ramalingam <grama@microsoft.com> Co-authored-by: Changming Sun <me@sunchangming.com> Co-authored-by: Scott McKay <skottmckay@gmail.com> Co-authored-by: Gustavo Alvarez <462213+sl1pkn07@users.noreply.github.com> Co-authored-by: Pranav Sharma <prs@microsoft.com>
|
This change broke raspberrypi build. |
|
This change also break the build on ubuntu 14.04. |
* Change the return type for the zipmap operator to match the description in the spec. * Reduce binary size of libraries consuming ONNX (part 1/2) * Fix build error * Replace separate Get*Doc() functions with easy macro for greater convenience * Add one more macro for complicated operator doc documentation. Co-authored-by: Ke Zhang <kezhan@microsoft.com>
Several parts of the op sec like the main op description, attributes, input and output descriptions become part of the binary that consumes ONNX e.g. onnxruntime causing an increase in its size due to strings that take no part in the execution of the model or its verification.
Setting __ONNX_NO_DOC_STRINGS doesn't really help here since (1) it's not used in the SetDoc(string) overload (see https://github.com/onnx/onnx/blob/master/onnx/defs/schema.cc#L444) and (2) it's not used at all for attributes, inputs and outputs. We should do something similar to https://github.com/onnx/onnx/blob/master/onnx/defs/schema.h#L322 to fix these things.
This PR takes care of the SetDoc calls and inputs/outputs. I'll send a separate PR for the attributes since they're a bit more involved and this PR is already big. These and the attribute changes together reduce the binary size of onnxruntime by at least 95k (tested using vs2017) with LTO enabled.
Reference: #2628