Skip to main content

A simple tool to measure the performance of ONNX models in Python.

Project description

onnx-perf-test - ONNX Performance Test PyPI

A simple Python tool to measure the performance of ONNX models. onnx_perf_test_results

Installation

pip install onnx-perf-test
  • onnxruntime is installed with the package, for other execution providers, make sure to install the appropriate version of onnxruntime.

Usage

python onnx_perf_test.py {onnx_model} [--provider {provider}] [--num_runs {num_runs}] [--output_dir {output_dir}] [--draw] [--keep_profiling_file]

Arguments:

  • onnx_model: Path to the ONNX model file.
  • --provider: Provider to use for inferencing. Default is uses onnxruntime.get_available_providers() to get the available providers. Options: TENSORRT, CUDA, CPU...
  • --num_runs: Number of runs to average the performance. Default is 10.
  • --output_dir: Output directory to save the results. Does not save the results if not provided.
  • --draw: Draw the performance graph. Requires matplotlib to be installed. Default is False.
  • --keep_profiling_file: Keep the profiling file generated by onnxruntime. Default is False.

Example

python onnx_perf_test.py model.onnx --provider CUDA --num_runs 20 --output_dir results --draw

Output

Running performance test on .\model.onnx with provider DEFAULT
Model inputs:
        input.1 - Shape: [1, 3, 32, 32], Type: tensor(float)
Model outputs:
        22 - Shape: [1, 10], Type: tensor(float)

Warming up the session...
Starting performance test...
Run 1: 0.53 ms
Run 2: 0.41 ms
Run 3: 0.39 ms
Run 4: 0.40 ms
Run 5: 0.39 ms
Run 6: 0.41 ms
Run 7: 0.39 ms
Run 8: 0.41 ms
Run 9: 0.42 ms
Run 10: 0.39 ms

model_run: 0.39530000000000004 ± 0.033970739042757235 ms
        model_run: 0.39530000000000004 ± 0.033970739042757235 ms

SequentialExecutor::Execute: 0.3592 ± 0.02518288660534724 ms
        SequentialExecutor::Execute: 0.3592 ± 0.02518288660534726 ms

FusedConv: 0.0977 ± 0.013367040726270638 ms
        /conv1/Conv_kernel_time: 0.056999999999999995 ± 0.010749676997731395 ms
        /conv2/Conv_kernel_time: 0.0407 ± 0.003301514803843834 ms
        /conv2/Conv_fence_before: 0.0 ± 0.0 ms
        /conv2/Conv_fence_after: 0.0 ± 0.0 ms
        /conv1/Conv_fence_before: 0.0 ± 0.0 ms
        /conv1/Conv_fence_after: 0.0 ± 0.0 ms

Gemm: 0.0967 ± 0.00279085809185793 ms
        /fc1/Gemm_kernel_time: 0.038400000000000004 ± 0.0027568097504180435 ms
        /fc3/Gemm_kernel_time: 0.029800000000000004 ± 0.0016193277068654818 ms
        /fc2/Gemm_kernel_time: 0.028500000000000004 ± 0.0009718253158075512 ms
        /fc2/Gemm_fence_before: 0.0 ± 0.0 ms
        /fc3/Gemm_fence_before: 0.0 ± 0.0 ms
        /fc3/Gemm_fence_after: 0.0 ± 0.0 ms
        /fc2/Gemm_fence_after: 0.0 ± 0.0 ms
        /fc1/Gemm_fence_after: 0.0 ± 0.0 ms
        /fc1/Gemm_fence_before: 0.0 ± 0.0 ms

MaxPool: 0.049 ± 0.0024944382578492947 ms
        /pool/MaxPool_kernel_time: 0.026600000000000002 ± 0.0015776212754932302 ms
        /pool_1/MaxPool_kernel_time: 0.0224 ± 0.0014298407059684809 ms
        /pool_1/MaxPool_fence_after: 0.0 ± 0.0 ms
        /pool/MaxPool_fence_before: 0.0 ± 0.0 ms
        /pool_1/MaxPool_fence_before: 0.0 ± 0.0 ms
        /pool/MaxPool_fence_after: 0.0 ± 0.0 ms

Relu: 0.043199999999999995 ± 0.002699794230842212 ms
        /Relu_3_kernel_time: 0.0217 ± 0.0018885620632287062 ms
        /Relu_2_kernel_time: 0.0215 ± 0.001178511301977579 ms
        /Relu_3_fence_before: 0.0 ± 0.0 ms
        /Relu_3_fence_after: 0.0 ± 0.0 ms
        /Relu_2_fence_before: 0.0 ± 0.0 ms
        /Relu_2_fence_after: 0.0 ± 0.0 ms

Flatten: 0.0172 ± 0.0020439612955674524 ms
        /Flatten_kernel_time: 0.0172 ± 0.0020439612955674524 ms
        /Flatten_fence_after: 0.0 ± 0.0 ms
        /Flatten_fence_before: 0.0 ± 0.0 ms

Analyze ONNX Profiling File

Additionally, you can analyze your own .json profiling file generated by ONNXRuntime using the analyze_onnx_profiling.py script.

python analyze_onnx_profiling.py {onnx_profile_file} [--output_dir {output_dir}] [--draw]

Arguments:

  • onnx_profile_file: Path to the ONNX profiling file.
  • --output_dir: Output directory to save the results. Does not save the results if not provided.
  • --draw: Draw the performance graph. Requires matplotlib to be installed. Default is False.

Example

python analyze_onnx_profiling.py model_profile.json --output_dir results --draw

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onnx_perf_test-0.4.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

onnx_perf_test-0.4.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file onnx_perf_test-0.4.0.tar.gz.

File metadata

  • Download URL: onnx_perf_test-0.4.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.0

File hashes

Hashes for onnx_perf_test-0.4.0.tar.gz
Algorithm Hash digest
SHA256 e6ea09382643900e1af540521267c4ed831b9e3ce9d8f7031a4481bf45f2c229
MD5 b28cd2882e21456e66484d5e2ce86803
BLAKE2b-256 f33a3afe05b347a1493537eb394d6e21fbfadab305c5550f85babde2e85589d0

See more details on using hashes here.

File details

Details for the file onnx_perf_test-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for onnx_perf_test-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 df1930d7aa37c937ddebf725fe97f7c70f87ac8439c24c6509c4d6c3870ed5c0
MD5 981894d4a1d62cbe3ef8144b7ec061a4
BLAKE2b-256 f0405367637b017ee496fac55a1071d8c91085776fe7bf4c2ad04ada4129b225

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page