STM32 model benchmarking ¶
The ST Edge AI Model Bench is a powerful tool that enables users to evaluate the performance of models built with TensorFlow Lite (.tflite), Keras (.keras), or ONNX (.onnx). Users can upload a model and configure settings to generate metrics such as memory footprints and inference time. Benchmark on STM32 target devices with the ST Edge AI Model Bench, or use STEdgeAI Core to estimate memory footprints locally.
1. Configure the YAML file ¶
Start from the use case’s
user_config.yaml
or its example benchmarking configuration. These files provide the use-case-specific model, dataset, preprocessing, and target settings. The steps below describe the settings common to the benchmarking workflow.
1.1 Set the model and the operation mode ¶
Set
operation_mode
to
benchmarking. You can either set
model_path
to your own model file or to a model file from the STM32 model zoo, or select a pretrained model by setting
model_name
and its required parameters:
operation_mode: benchmarking
model:
model_path: <path-to-your-model>
# Alternatively:
# model_name: <model-name>
# input_shape: <model-input-shape>
# pretrained: True
# pretrained_dataset_name: <pretraining-dataset>
# model_precision: <model-precision> example : w8a8_ptq
1.2 Set benchmarking tools and parameters ¶
The
ST Edge AI Model Bench
allows you to benchmark your model and estimate its footprints and inference time for different STM32 target devices. To use this feature, set the
on_cloud
attribute to True. Alternatively, you can use
STEdgeAI Core
to benchmark your model and estimate its footprints for STM32 target devices locally. To do this, make sure to add the path to the
stedgeai
executable under the
path_to_stedgeai
attribute and set the
on_cloud
attribute to False.
The
optimization
defines the optimization used to generate the C model, options: “balanced”, “time”, “ram”.
The
board
attribute is used to provide the name of the STM32 board to benchmark the model on. The available boards are ‘STM32N6570-DK’, ‘STM32H747I-DISCO’, ‘STM32H7B3I-DK’, ‘STM32F469I-DISCO’, ‘B-U585I-IOT02A’, ‘STM32L4R9I-DISCO’, ‘NUCLEO-H743ZI2’, ‘STM32H735G-DK’, ‘STM32F769I-DISCO’, ‘NUCLEO-G474RE’, ‘NUCLEO-F401RE’ and ‘STM32F746G-DISCO’.
tools:
stedgeai:
optimization: balanced
on_cloud: True
path_to_stedgeai: C:/ST/STEdgeAI/<x.y>/Utilities/windows/stedgeai.exe
path_to_cubeIDE: C:/ST/STM32CubeIDE_<*.*.*>/STM32CubeIDE/stm32cubeide.exe
benchmarking:
board: STM32H747I-DISCO # Name of the STM32 board to benchmark the model on
1.3 Hydra and MLflow settings ¶
The
mlflow
and
hydra
sections must always be present in the YAML configuration file. The
hydra
section can be used to specify the name of the directory where experiment directories are saved and/or the pattern used to name experiment directories. With the YAML code below, every time you run the Model Zoo, an experiment directory is created that contains all the directories and files created during the run. The names of experiment directories are all unique as they are based on the date and time of the run.
hydra:
run:
dir: ./experiments_outputs/${now:%Y_%m_%d_%H_%M_%S}
The
mlflow
section is used to specify the location and name of the directory where MLflow files are saved, as shown below:
mlflow:
uri: ./experiments_outputs/mlruns
2. Benchmark your model ¶
Run the command from the root directory of the use case you are benchmarking. To use its main configuration file, run:
python stm32ai_main.py
To use the use case’s example benchmarking configuration, run:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name benchmarking_config.yaml
Note that you can provide YAML attributes as arguments in the command, as shown below:
python stm32ai_main.py operation_mode='benchmarking'
3. Visualize benchmark results ¶
To view the detailed benchmarking results, you can access the log file
stm32ai_main.log
located in the directory
experiments_outputs/<date-and-time>. Additionally, you can navigate to the
experiments_outputs
directory and use the MLflow Webapp to view the metrics saved for each trial or launch. To access the MLflow Webapp, run the following command:
mlflow ui
This opens the MLflow interface, where you can inspect metrics and results. The exact output directory is controlled by the
hydra.run.dir
setting in your configuration.
4. Quantize and benchmark with chain_qb ¶
Many use cases support the
chain_qb
operation mode. It runs quantization on a float model and then benchmarks the resulting quantized model on the selected STM32 target. Use it when you want to measure the deployed, quantized model without launching quantization and benchmarking as separate runs.
Start from the use case’s
chain_qb
example configuration when available, or adapt its user configuration. The configuration must include:
operation_mode: chain_qb.A float model source, configured with
model_pathor the model-selection fields supported by that model.The quantization settings required by the use case and model format.
The benchmarking tool settings and a supported target board.
Any use-case-specific dataset, preprocessing, or other required sections.
Run the command from the use case’s root directory. If that use case provides a
chain_qb_config.yaml
example in
config_file_examples, run:
python stm32ai_main.py --config-path ./config_file_examples/ --config-name chain_qb_config.yaml
If the example has a different filename or location, substitute its actual config path and name. The quantized model and benchmark results are written to the experiment output directory configured by
hydra.run.dir.