- Notifications
You must be signed in to change notification settings - Fork0
Add class to yield results form onnx model and computes differences between two runs#71
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
6eb6adf update requirements
xadupre4f0a994 Merge branch 'main' of https://github.com/sdpython/onnx-array-api
xaduprec7bb055 Merge branch 'main' of https://github.com/sdpython/onnx-array-api
xaduprecc7ab30 Merge branch 'main' of https://github.com/sdpython/onnx-array-api int…
xadupred520cfa Add class to yield results
xadupred616c58 black
xaduprefe32241 add sumarry
xaduprea8c2932 add distance
xadupre09e79d2 text
xadupree1e30dc compare function
xadupre12b1031 fix FusedMatMul
xadupre0986399 fix alpha
xadupred1f276b example
xadupre42c5e69 documentation
xadupree222441 fix length
xadupre04418d4 doc
xadupreFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
1 change: 1 addition & 0 deletionsCHANGELOGS.rst
This file contains hidden or 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
30 changes: 30 additions & 0 deletions_doc/api/reference.rst
This file contains hidden or 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
52 changes: 52 additions & 0 deletions_doc/command_lines.rst
This file contains hidden or 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,52 @@ | ||
| ============= | ||
| command lines | ||
| ============= | ||
| compare | ||
| ======= | ||
| The function convers an onnx file into some code. | ||
| :: | ||
| python -m compare -m1 model1.onnx -m2 model2.onnx -v 1 | ||
| Output example:: | ||
| [compare_onnx_execution] got 2 inputs | ||
| [compare_onnx_execution] execute first model | ||
| [compare_onnx_execution] got 5 results | ||
| [compare_onnx_execution] execute second model | ||
| [compare_onnx_execution] got 5 results | ||
| [compare_onnx_execution] compute edit distance | ||
| [compare_onnx_execution] got 4 pairs | ||
| [compare_onnx_execution] done | ||
| = | INPUT float32 5x6 AAAA X | INPUT float32 5x6 AAAA X | ||
| = | INPUT float32 5x6 AAAA Y | INPUT float32 5x6 AAAA Y | ||
| = | RESULT float32 5x6 AABB Add res | RESULT float32 5x6 AABB Add res | ||
| = | RESULT float32 5x6 AAAA Cos Z | RESULT float32 5x6 AAAA Cos Z | ||
| .. runpython:: | ||
| from onnx_array_api._command_lines_parser import get_parser_compare | ||
| get_parser_compare().print_help() | ||
| See function :func:`onnx_array_api.reference.compare_onnx_execution`. | ||
| translate | ||
| ========= | ||
| The function convers an onnx file into some code. | ||
| :: | ||
| python -m translate ... | ||
| Output example:: | ||
| not yet ready | ||
| .. runpython:: | ||
| from onnx_array_api._command_lines_parser import get_parser_translate | ||
| get_parser_translate().print_help() |
68 changes: 68 additions & 0 deletions_doc/examples/plot_onnx_diff.py
This file contains hidden or 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,68 @@ | ||
| """ | ||
| .. _l-onnx-diff-example: | ||
| Compares the conversions of the same model with different options | ||
| ================================================================= | ||
| The script compares two onnx models obtained with the same trained | ||
| scikit-learn models but converted with different options. | ||
| A model | ||
| +++++++ | ||
| """ | ||
| from sklearn.mixture import GaussianMixture | ||
| from sklearn.datasets import load_iris | ||
| from sklearn.model_selection import train_test_split | ||
| from skl2onnx import to_onnx | ||
| from onnx_array_api.reference import compare_onnx_execution | ||
| from onnx_array_api.plotting.text_plot import onnx_simple_text_plot | ||
| data = load_iris() | ||
| X_train, X_test = train_test_split(data.data) | ||
| model = GaussianMixture() | ||
| model.fit(X_train) | ||
| ################################# | ||
| # Conversion to onnx | ||
| # ++++++++++++++++++ | ||
| onx = to_onnx( | ||
| model, X_train[:1], options={id(model): {"score_samples": True}}, target_opset=12 | ||
| ) | ||
| print(onnx_simple_text_plot(onx)) | ||
| ################################## | ||
| # Conversion to onnx without ReduceLogSumExp | ||
| # ++++++++++++++++++++++++++++++++++++++++++ | ||
| onx2 = to_onnx( | ||
| model, | ||
| X_train[:1], | ||
| options={id(model): {"score_samples": True}}, | ||
| black_op={"ReduceLogSumExp"}, | ||
| target_opset=12, | ||
| ) | ||
| print(onnx_simple_text_plot(onx2)) | ||
| ############################################# | ||
| # Differences | ||
| # +++++++++++ | ||
| # | ||
| # Function :func:`onnx_array_api.reference.compare_onnx_execution` | ||
| # compares the intermediate results of two onnx models. Then it finds | ||
| # the best alignmet between the two models using an edit distance. | ||
| res1, res2, align, dc = compare_onnx_execution(onx, onx2, verbose=1) | ||
| print("------------") | ||
| text = dc.to_str(res1, res2, align) | ||
| print(text) | ||
| ############################### | ||
| # The display shows that ReduceSumSquare was replaced by Mul + ReduceSum, | ||
| # and ReduceLogSumExp by ReduceMax + Sub + Exp + Log + Add. |
1 change: 1 addition & 0 deletions_doc/index.rst
This file contains hidden or 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
1 change: 1 addition & 0 deletions_doc/tutorial/index.rst
This file contains hidden or 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 |
|---|---|---|
| @@ -10,4 +10,5 @@ Tutorial | ||
| graph_api | ||
| light_api | ||
| numpy_api | ||
| tools | ||
| benchmarks | ||
20 changes: 20 additions & 0 deletions_doc/tutorial/tools.rst
This file contains hidden or 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,20 @@ | ||
| ===== | ||
| Tools | ||
| ===== | ||
| Some of useful tools. | ||
| Text representation | ||
| =================== | ||
| Plotting a graph is great but difficult to read when | ||
| the graph is big and it is slow. | ||
| :func:`onnx_array_api.plotting.text_plot.onnx_simple_text_plot` | ||
| prints out a text representation. | ||
| Differences between two models | ||
| ============================== | ||
| How to understand the differences between two models | ||
| assuming they are producing the same outputs? | ||
| Example :ref:`l-onnx-diff-example` shows how to do it. |
26 changes: 25 additions & 1 deletion_unittests/ut_reference/test_array_tensor.py
This file contains hidden or 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.
Uh oh!
There was an error while loading.Please reload this page.
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.