Model Usability Checker

Der Model Usability Checker analysiert ein ONNX-Modell hinsichtlich seiner Eignung für die Verwendung mit ORT Mobile, NNAPI und CoreML.

Inhalt

Verwendung

python -m onnxruntime.tools.check_onnx_model_mobile_usability --help
usage: check_onnx_model_mobile_usability.py [-h] [--log_level {debug,info}] model_path

Analyze an ONNX model to determine how well it will work in mobile scenarios.

positional arguments:
  model_path            Path to ONNX model to check

optional arguments:
  -h, --help            show this help message and exit
  --log_level {debug,info}
                        Logging level (default: info)

Verwendung mit NNAPI und CoreML

Das Skript prüft, ob die Operatoren im Modell vom NNAPI Execution Provider (EP) und CoreML EP von ORT unterstützt werden. Abhängig davon, wie viele Operatoren unterstützt werden und wo sie sich im Modell befinden, wird geschätzt, ob die Verwendung von NNAPI oder CoreML vorteilhaft sein wird. Es wird immer empfohlen, Leistungstests zur Validierung durchzuführen.

Ein Beispiel für die Ausgabe dieser Prüfung sieht wie folgt aus

INFO:  Checking resnet50-v1-7.onnx for usability with ORT Mobile.
INFO:  Checking NNAPI
INFO:  1 partitions with a total of 121/122 nodes can be handled by the NNAPI EP.
INFO:   Partition sizes: [121]
INFO:  Unsupported nodes due to operator=0
INFO:   Caveats that have not been checked and may result in a node not actually being supported:
     ai.onnx:Conv:Only 2D Conv is supported. Weights and bias should be constant.
     ai.onnx:Gemm:If input B is not constant, transB should be 1.
     ai.onnx:GlobalAveragePool:Only 2D Pool is supported.
     ai.onnx:MaxPool:Only 2D Pool is supported.
INFO:  Unsupported nodes due to input having a dynamic shape=1
INFO:  NNAPI should work well for this model as there is one partition covering 99.2% of the nodes in the model.
INFO:  Model should perform well with NNAPI as is: YES

Wenn das Modell dynamische Eingabeformen hat, wird eine zusätzliche Prüfung durchgeführt, um abzuschätzen, ob die Festlegung fester Formen helfen würde. Weitere Informationen finden Sie unter onnxruntime.tools.make_dynamic_shape_fixed.

Beispielhafte Ausgabe dieser Prüfung

INFO:  Checking resnet50-v1-7.onnx for usability with ORT Mobile.
...
INFO:  Checking CoreML MLProgram
INFO:  2 partitions with a total of 120/122 nodes can be handled by the CoreML MLProgram EP.
INFO:   Partition sizes: [119, 1]
INFO:  Unsupported nodes due to operator=1
INFO:   Unsupported ops: ai.onnx:Flatten
INFO:   Caveats that have not been checked and may result in a node not actually being supported:
     ai.onnx:Conv:Only 1D/2D Conv is supported. Bias if provided must be constant.
     ai.onnx:Gemm:Input B must be constant.
     ai.onnx:GlobalAveragePool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed.
     ai.onnx:MaxPool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed.
INFO:  Unsupported nodes due to input having a dynamic shape=1
INFO:  CoreML MLProgram can be considered for this model as there are two partitions covering 98.4% of the nodes. Performance testing is required to validate.
INFO:  Model should perform well with CoreML MLProgram as is: MAYBE
INFO:  --------
INFO:  Checking if model will perform better if the dynamic shapes are fixed...
INFO:  Partition information if the model was updated to make the shapes fixed:
INFO:  2 partitions with a total of 121/122 nodes can be handled by the CoreML MLProgram EP.
INFO:   Partition sizes: [120, 1]
INFO:  Unsupported nodes due to operator=1
INFO:   Unsupported ops: ai.onnx:Flatten
INFO:   Caveats that have not been checked and may result in a node not actually being supported:
     ai.onnx:Conv:Only 1D/2D Conv is supported. Bias if provided must be constant.
     ai.onnx:Gemm:Input B must be constant.
     ai.onnx:GlobalAveragePool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed.
     ai.onnx:MaxPool:Only 2D Pool is supported currently. 3D and 5D support can be added if needed.
INFO:  CoreML MLProgram can be considered for this model as there are two partitions covering 99.2% of the nodes. Performance testing is required to validate.
INFO:  Model should perform well with CoreML MLProgram if modified to have fixed input shapes: MAYBE
INFO:  Shapes can be altered using python -m onnxruntime.tools.make_dynamic_shape_fixed

Es gibt diagnostische Ausgaben, die detaillierte Informationen darüber liefern, warum die Empfehlungen gegeben wurden.

Dies beinhaltet

  • Informationen zu einzelnen Operatoren, die von den NNAPI- und CoreML-EPs unterstützt oder nicht unterstützt werden
  • Informationen darüber, in wie viele Gruppen (auch Partitionen genannt) die unterstützten Operatoren aufgeteilt sind
    • je mehr Gruppen, desto schlechter die Leistung, da wir jedes Mal zwischen der NPU (Neural Processing Unit) und der CPU wechseln müssen, wenn wir zwischen einer unterstützten und einer nicht unterstützten Gruppe von Knoten wechseln

Empfehlung

Schließlich gibt das Skript eine Empfehlung ab, welcher EP verwendet werden soll.

INFO:  As NNAPI or CoreML may provide benefits with this model it is recommended to compare the performance of the model using the NNAPI EP on Android, and the CoreML EP on iOS, against the performance using the CPU EP.