-
Notifications
You must be signed in to change notification settings - Fork 140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Generic model export pipeline + torch to ONNX and ONNX to deepsparse refactor #1192
Merged
Conversation
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
* initial commit * PR comments * initial commit * Delete test_fold_identity_initializers.py * Delete __init__.py * Delete __init__.py * Update src/sparseml/exporters/transforms/base_transform.py * fix docstrings * few improvements and tests Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
* Adding onnx graph structural matching * Styling * Adding missing init.py * Update src/sparseml/exporters/transforms/utils/matching.py Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com> * Updating docstring of structural_matches * Adding __all__ * Addressing review comments * Removing extra file from merge Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com>
* initial commit * PR comments * initial commit * Delete test_fold_identity_initializers.py * Delete __init__.py * Delete __init__.py * Adding onnx graph structural matching * Styling * Update src/sparseml/exporters/transforms/base_transform.py * fix docstrings * Adding missing init.py * Update src/sparseml/exporters/transforms/utils/matching.py Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com> * Updating docstring of structural_matches * Adding __all__ * ready for review * Update src/sparseml/exporters/transforms/fold_identity_initializers.py Co-authored-by: corey-nm <109536191+corey-nm@users.noreply.github.com> * some nits according to Bens comments Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com> Co-authored-by: Corey Lowman <corey@neuralmagic.com> Co-authored-by: corey-nm <109536191+corey-nm@users.noreply.github.com>
* Adding InitializersToUint8 transform * Update src/sparseml/exporters/transforms/initializers_to_uint8.py
* Adding onnx graph structural matching * Styling * Adding missing init.py * Update src/sparseml/exporters/transforms/utils/matching.py Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com> * Updating docstring of structural_matches * Adding __all__ * initial commit * Update convert_quantizable_conv_integer.py Co-authored-by: Corey Lowman <corey@neuralmagic.com> Co-authored-by: corey-nm <109536191+corey-nm@users.noreply.github.com> Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
* Adding onnx graph structural matching * Styling * Adding missing init.py * Update src/sparseml/exporters/transforms/utils/matching.py Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com> * Updating docstring of structural_matches * Adding __all__ * initial commit * Delete base_exporter.py * Update src/sparseml/exporters/transforms/convert_quantizable_matmul.py * beautify * check for initializers * add docstring Co-authored-by: Corey Lowman <corey@neuralmagic.com> Co-authored-by: corey-nm <109536191+corey-nm@users.noreply.github.com> Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
* Adding ConvToQLinearConv transform * Responding to review comments * Respond to reviews
* Adding FlattenQParams transform * Respond to review
* Adding ConvToQLinearConv transform * Responding to review comments * Adding GemmToQLinearMatMul * Styling
* initial commit * intiial commit * PR comments * fix errors * Apply suggestions from code review * upadte heleprs * matching of conv integer pass * second implementation done, needs some polishing * Adding match_structure and iter_structural_matches * Using structural matching for quantizable_conv_integer * initial commit * Adding onnx graph structural matching * Styling * Adding missing init.py * Update src/sparseml/exporters/transforms/utils/matching.py Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com> * Updating docstring of structural_matches * Adding __all__ * initial commit * ready for PR * beautify * Delete test_helpers.py * Delete base_exporter.py Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com> Co-authored-by: Corey Lowman <corey@neuralmagic.com> Co-authored-by: corey-nm <109536191+corey-nm@users.noreply.github.com>
* Adding FoldConvDivBn * Expanding docstring
* initial commit * get transform into the correct format * ready for review * fix naming in test * Fixing trivial onnx adds Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com> Co-authored-by: corey-nm <109536191+corey-nm@users.noreply.github.com> Co-authored-by: Corey Lowman <corey@neuralmagic.com>
* Adding QuantizeResiduals transform * Adding tests
* Adding DeleteRepeatedQdq transform * Adding unit test for delete repeated qdq * Using assert_node_type * Update src/sparseml/exporters/transforms/delete_repeated_qdq.py
* Adding SkipInputQuantize transform * add tests Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com>
* Fixing matching logic of qlinear transforms * Adding folding of input/output quants to qlinears
…_pipeline_refactor
…1249) * Initial comit of exporters * Styling * Fixing SkipInputQuantize * Adding validation methods * Clean up ONNXToDeepsparse * Moving TorchToONNX to pytorch * Adding inplace and saving pre optimized model to ONNXToDeepsparse * Adding sketch of tests * Regression tests against simple models * resnet50 regression tests passing * resnet50 exporters are all equivalent * Moving FoldConvDivBn under initializer folding * Adding yolov5 tests * Apply suggestions from code review Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com> * Review response * Adding notes from review * uncomment asserts... oops * yolo & resnet tests passing Co-authored-by: dbogunowicz <97082108+dbogunowicz@users.noreply.github.com>
…_pipeline_refactor
…tchResult to str (#1262) * Addin any_of and MatchResult to str * Fixing docstring of get_structural_matches
* Standardization of some transforms * Adding logging methods to OnnxTransform class
* Standardizing transforms with node removals * Using log_match
* Standardizing MatMulToQLinearMatMul * Using log_match
* Standardizing ConvToConvIntegerAddCastMul * Using log_match
* Standardizing qlinear transforms * Using log_match
#1269) * Standardizing MatMulIntegerAddCastMul transforms * Using log_match and any_of
* Standardizing QuantizeQATEmbedding * Add log_match
* initial commit * Apply suggestions from code review * Update tests/sparseml/pytorch/test_torch_to_onnx_exporter.py * Fixing bert exporters Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com> Co-authored-by: Corey Lowman <corey@neuralmagic.com>
* initial commit * PR edits * Delete recipe.yaml * fix onnx problem * Fixing torch import issue and numpy attr error * Another attempt at fixing get_numpy_dtype * Fix numpy.float usage Co-authored-by: bogunowicz@arrival.com <bogunowicz@arrival.com> Co-authored-by: Corey Lowman <corey@neuralmagic.com>
bfineran
changed the title
[Exporter Refactor] Feature Branch
Generic model export pipeline + torch to ONNX and ONNX to deepsparse refactor
Dec 20, 2022
bfineran
approved these changes
Dec 20, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
KSGulin
approved these changes
Dec 20, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@corey-nm great job! I like the PR message. |
I think @bfineran would have to force merge it |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR reworks all of the onnx optimization passes contained in src/sparseml/pytorch/sparsification/quantization/quantize_qat_export.py.
The new classes/functions are introduced:
class BaseTransform
andclass OnnxTransform(BaseTransform)
, which represent abstract transforms that act on onnx graphsclass BaseExporter(BaseTransform)
,class TorchToONNX(BaseExporter)
, andclass ONNXToDeepsparse(BaseExporter)
, which represent transforms that can also save things to diskIn addition, every transform from quantize_qat_export (and other files), has been added as a
OnnxTransform
. This includes:The
get_structural_matches
utility function was also added to aid in the implementation of these transforms. Notably it allows callees to match sub-graphs in any onnx graph, which makes implementation details more clear/explicit.Test Plan
As mentioned in the summary, every transform has a unit test associated with it. Additionally, regression tests were added against the old module exporter logic for the following models:
So both the graph structure and numerical output match exactly for both the new exporters and the old exporters.