Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
General Constant Folding for Onnx and Caffe2 Operators in Loader (#3141)
Summary: **Summary** - Add constant folding of operators to ONNXModelLoader: - Add constant folding of operators to Caffe2Loader - Made Constant folding of Operators an optional feature controlled by command line option const-fold-ops - Added constant folding test based on gather and reshape to OnnxImporterTests and Caffe2ImporterTest - Add constant folding test to OnnxImporterTests **Documentation** First check if the folding is enabled. If yes, check if current operator is foldable. If yes get the output of a graph where all the inputs are constant and current operator is the only operator in the graph. Run the graph and instead of loading the original opreator load the constant operator with value calculated. When done sequentially during the loader this can fold not just a single operator but a whole subgraph as long as all the inputs to the subgraphs are constants. **Optional Fixes** - Fix an issue with batchboxCox batchBoxCox.onnxtxt (needed for general onnx operator folding test) **Test Plan** (Test constant folding of ONNX operators with ONNXImporterTest) First replace placeholders in the original onnx model with constants. After loading the graph get the graph output values without running the GraphProto. If this output is same as output of original graph after running constant folding, the test passes. A simple network in caffe2 and onnx which requires constant fold to work: The test gatherOpConstantFoldingAndReshape in ONNxImportertest and Caffe2ImporterTest verifies that Gather gets constant-folded, so that the argument of the reshape becomes constant. Related to #2168 Pull Request resolved: #3141 Reviewed By: opti-mix Differential Revision: D15910349 Pulled By: jfix71 fbshipit-source-id: 32fd3aed51c36fadf0bc6bf461a0a548ed8e0c6e
- Loading branch information
1 parent
cb7c305
commit 99b6571
Showing
16 changed files
with
676 additions
and
42 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
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
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
Oops, something went wrong.