.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gyexamples/plot_onnx_benchmark.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_gyexamples_plot_onnx_benchmark.py: .. _l-example-onnx-benchmark: Measure ONNX runtime performances ================================= The following example shows how to use the command line to compare one or two runtimes with :epkg:`scikit-learn`. It relies on function :func:`validate_runtime ` which can be called from *python* or through a command line described in page :ref:`l-CMD2`. .. contents:: :local: Run the benchmark +++++++++++++++++ The following line creates a folder used to dump information about models which failed during the benchmark. .. GENERATED FROM PYTHON SOURCE LINES 24-31 .. code-block:: default import os import matplotlib.image as mpimg import matplotlib.pyplot as plt import pandas if not os.path.exists("dump_errors"): os.mkdir("dump_errors") .. GENERATED FROM PYTHON SOURCE LINES 32-45 The benchmark can be run with a python instruction or a command line: :: python -m mlprodict validate_runtime -v 1 --out_raw data.csv --out_summary summary.csv -b 1 --dump_folder dump_errors --runtime python,onnxruntime1 --models LinearRegression,DecisionTreeRegressor --n_features 4,10 --out_graph bench_png -t "{\"1\":{\"number\":10,\"repeat\":10},\"10\":{\"number\":5,\"repeat\":5}}" We use the python instruction in this example. .. GENERATED FROM PYTHON SOURCE LINES 45-64 .. code-block:: default from mlprodict.cli import validate_runtime validate_runtime( verbose=1, out_raw="data.csv", out_summary="summary.csv", benchmark=True, dump_folder="dump_errors", runtime=['python', 'onnxruntime1'], models=['LinearRegression', 'DecisionTreeRegressor'], n_features=[4, 10], dtype="32", out_graph="bench.png", time_kwargs={ 1: {"number": 100, "repeat": 100}, 10: {"number": 50, "repeat": 50}, 100: {"number": 40, "repeat": 50}, 1000: {"number": 40, "repeat": 40}, 10000: {"number": 20, "repeat": 20}, } ) .. image-sg:: /gyexamples/images/sphx_glr_plot_onnx_benchmark_001.png :alt: RT/SKL-N=1, N=10, N=100, N=1000, N=10000 :srcset: /gyexamples/images/sphx_glr_plot_onnx_benchmark_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none time_kwargs={1: {'number': 100, 'repeat': 100}, 10: {'number': 50, 'repeat': 50}, 100: {'number': 40, 'repeat': 50}, 1000: {'number': 40, 'repeat': 40}, 10000: {'number': 20, 'repeat': 20}} [enumerate_validated_operator_opsets] opset in [17, None]. 0%| | 0/2 [00:00
0 1
name DecisionTreeRegressor DecisionTreeRegressor
problem b-reg b-reg
scenario default default
optim NaN NaN
method_name predict predict
output_index 0 0
conv_options {} {}
inst {"random_state": 42} {"random_state": 42}
n_features 4 4
runtime onnxruntime1 python
skl_version 1.2.1 1.2.1
skl_nop 1 1
skl_ncoef -1.0 -1.0
skl_nlin -1.0 -1.0
skl_nnodes 223.0 223.0
skl_ntrees 1.0 1.0
skl_max_depth 13.0 13.0
onx_size 8943 8943
onx_nnodes 1 1
onx_ninits 0 0
onx_producer_name skl2onnx skl2onnx
onx_producer_version 1.13.1 1.13.1
onx_ai.onnx.ml 3 3
onx_size_optim 8943 8943
onx_nnodes_optim 1 1
onx_ninits_optim 0 0
opset17 OK 17/3 OK 17/3
RT/SKL-N=1 0.724179 0.311947
N=10 0.730205 0.316873
N=100 0.762137 31.396165
N=1000 0.586674 70.842404
N=10000 0.317246 122.252102
RT/SKL-N=1-min 0.673482 0.303278
RT/SKL-N=1-max 1.126067 0.316214
N=10-min 0.714238 0.311731
N=10-max 0.740292 0.322754
N=100-min 0.700777 0.395965
N=100-max 2.601827 75.713904
N=1000-min 0.56944 0.728227
N=1000-max 0.667581 311.160683
N=10000-min 0.312533 40.025484
N=10000-max 0.32857 587.093982


.. GENERATED FROM PYTHON SOURCE LINES 70-71 Let's display the graph generated by the function. .. GENERATED FROM PYTHON SOURCE LINES 71-78 .. code-block:: default img = mpimg.imread('bench.png') fig = plt.imshow(img) fig.axes.get_xaxis().set_visible(False) fig.axes.get_yaxis().set_visible(False) plt.show() .. image-sg:: /gyexamples/images/sphx_glr_plot_onnx_benchmark_002.png :alt: plot onnx benchmark :srcset: /gyexamples/images/sphx_glr_plot_onnx_benchmark_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 10 minutes 43.597 seconds) .. _sphx_glr_download_gyexamples_plot_onnx_benchmark.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_onnx_benchmark.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_onnx_benchmark.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_