Copyright (c) 2023-2026 Antmicro
This project provides a set of tools and libraries for running and evaluating ML models on boards running Zephyr RTOS, providing a unified API for different inference frameworks such as LiteRT, microTVM or IREE.
Website | Kenning Documentation | Zephyr Runtime chapter of the Documentation | Kenning tutorials
This project is an integral part of the Kenning framework for optimizing, deploying and evaluating ML models on target devices. It provides a runtime-agnostic unified API that allows seamless switching between runtimes without making any changes in code except for minor configuration adjustments. It can be used separately for running provided models in production, or used in tandem with Kenning for model optimization, deployment and benchmarking (see Model evaluation with Kenning).
For detailed documentation, see the Kenning Zephyr Runtime chapter of the general Kenning documentation.
For a list of supported boards, check Kenning demos in Renode Zephyr Dashboard.
This repository provides:
kenning_inference_lib- a Zephyr RTOS library providing a unifiedmodelAPI, allowing for executing ML models with the following runtimes:- LiteRT/TFLite Micro
- microTVM
- IREE
- emlearn
- ExecuTorch
- AI8X for Analog Devices MAX78xxx platforms
app- a Zephyr application used with Kenning for evaluating models and runtimes on devices. For more information on available evaluation features, see the Model evaluation with Kenning section of this document.- demo application (
demo_app) - a Zephyr application that useskenning_inference_libto run gesture recognition on sample data. It is meant to showcase the usage ofkenning_inference_libas a standalone production solution, without communication with Kenning.
This is the minimal list of steps to build and run the demo_app.
To be able to build and use the project, you need the following dependencies:
- Zephyr dependencies
jqcurlwestpatchCMake
The easiest way to obtain an environment with all dependencies is to use the prepared Docker image:
mkdir zephyr-workspace && cd zephyr-workspace
docker run --rm -it -v $(pwd):$(pwd) -w $(pwd) ghcr.io/antmicro/kenning-zephyr-runtime:latest /bin/bash
Alternatively, on Debian-based Linux distributions, you may instead install the dependencies as follows:
sudo apt update
sudo apt install -y --no-install-recommends ccache curl device-tree-compiler dfu-util file \
g++-multilib gcc gcc-multilib git jq libmagic1 libsdl2-dev make ninja-build \
python3-dev python3-pip python3-setuptools python3-tk python3-wheel python3-venv \
wget xxd xz-utils patch cmake npmNow clone this repository:
git clone https://github.com/antmicro/kenning-zephyr-runtime
cd kenning-zephyr-runtime/
It is recommended to use the uv package manager instead of pip, whenever using Kenning.
You can install uv on Linux or macOS with:
curl -LsSf https://astral.sh/uv/install.sh | shTo make uv available in PATH, restart the shell or run:
source $HOME/.local/bin/envAnd install Python dependencies and Zephyr SDK:
./scripts/prepare_zephyr_env.sh
source .venv/bin/activateTo use a different Zephyr revision, set ZEPHYR_VERSION=v4.4.1 prior to running ./scripts/prepare_zephyr_env.sh.
This script runs ./scripts/set_zephyr_version.sh to set the appropriate Zephyr version and compatible dependency versions.
You can also execute ./scripts/set_zephyr_version.sh or re-run ./scripts/prepare_zephyr_env.sh.
Then, to install additional Zephyr modules:
./scripts/prepare_modules.shIf you're going to be using Renode for simulations, install Renode with:
source ./scripts/prepare_renode.shNOTE The prepare_renode.sh script provides environmental variables, that allow Kenning to find Renode.
It has to be ran every time a new shell is used.
At this point you should be able to build the demo app.
In this example, we're building the app for the stm32f746g_disco board.
west build -p always -b stm32f746g_disco demo_app -- -DEXTRA_CONF_FILE=litert.confThen run the Renode simulation (before that we also need to generate a REPL configuration file for Renode)
west build -t board-repl
python ./scripts/run_renode.pyAlternatively, you may run the demo on a physical board, using the west flash command.
The output should look like this:
*** Booting Zephyr OS build v4.3.0 ***
I: model output: [wing: 1.000000, ring: 0.000000, slope: 0.000000, negative: 0.000000]
I: model output: [wing: 0.000000, ring: 0.000000, slope: 0.000000, negative: 1.000000]
I: model output: [wing: 0.000000, ring: 0.000000, slope: 1.000000, negative: 0.000000]
I: model output: [wing: 1.000000, ring: 0.000000, slope: 0.000000, negative: 0.000000]
I: model output: [wing: 0.000000, ring: 0.997465, slope: 0.000000, negative: 0.002535]
I: model output: [wing: 0.000000, ring: 0.000000, slope: 1.000000, negative: 0.000000]
I: model output: [wing: 1.000000, ring: 0.000000, slope: 0.000000, negative: 0.000000]
I: model output: [wing: 1.000000, ring: 0.000000, slope: 0.000000, negative: 0.000000]
I: model output: [wing: 1.000000, ring: 0.000000, slope: 0.000000, negative: 0.000000]
I: model output: [wing: 0.000000, ring: 0.000000, slope: 1.000000, negative: 0.000000]
I: inference session statistics:
I: total inference time: 1478 ms
I: inference time per batch: 147 ms
I: peak_allocated: 16288
I: inference finished successfully
Kenning, along with its ecosystem of useful tools and applications, is meant to support ML engineers in every step of the model development and deployment process. It includes a model benchmarking functionality, that makes it easy to asses performance of models across various ML inference frameworks, and generate comprehensive reports from those evaluations.
A fragment of such report can be seen below:
Kenning, however, is primarily a Linux CLI application.
Kenning Zephyr Runtime brings the evaluation functionality to devices running Zephyr RTOS.
The user runs Kenning commands on a PC, which communicates with Kenning Zephyr Runtime evaluation app (e.g. over UART).
This app is running on an edge device (such as the stm32f746g_disco board).
Kenning compiles the model locally, using the Optimizer appropriate for the chosen runtime, for example TVMCompiler for the microTVM runtime.
Model weights, test data, and other information are sent to the app using selected Kenning Protocol, for example UARTProtocol.
Model output is sent back, along with inference measurements (such as time and memory usage - the exact details depend on the runtime). If the evaluation is being run in a Renode simulation - additional statistics are extracted from Renode.
All of that data is then used by Kenning to generate a report.
Kenning reports from Kenning Zephyr Runtime evaluations include details such as inference time, memory usage, and quality metrics specific to a given model.
Dynamic switching of models and runtimes is supported through LLEXT.
Entire runtimes can be compiled as LLEXT extensions, sent over Kenning Protocol, and linked dynamically into the kenning_inference_lib.
This way the user can change the runtime, that is currently in use, without restarting the board or re-compiling the entire app.
Detailed information about this feature is available in a dedicated section of the Kenning documentation.
Thanks to the integration of Zephelin library into Kenning, it is also possible to look inside your model - examine its performance layer-by-layer, and fine-tune it to your device of choice.
A sample interactive tracing report is available here. A fragment of the report can be seen below:
All of the aforementioned evaluation capabilities are fully integrated with other Kenning functionalities, such as the automated fine-tuning of model optimizers, or the AutoML support.
In one of our examples, we use Kenning's AutoML functionality to generate and train several model architectures, while taking into account memory constraints of the intended deployment environment. Then we automatically test and compare the performance of top five created models.
Fragment of the report from that example, showing inference time statistics, can be seen below, full interactive report is available here.
In this example, we will optimize and evaluate a small CNN classifier on STM32f746g Discovery kit. The model has been previously trained in TensorFlow, on the MagicWand dataset (accelerometer data), using Kenning.
We will use the kenning-scenarios/magic-wand-inference/tflite/renode-stm32f746g.yml configuration file.
Kenning is build out of configurable blocks.
In this configuration file, in order to facilitate the optimization, we define dataset, model_wrapper and optimizer blocks:
dataset:
type: MagicWandDataset
parameters:
dataset_root: ./output/MagicWandDataset
model_wrapper:
type: MagicWandModelWrapper
parameters:
model_path: kenning:///models/classification/magic_wand.h5
optimizers:
- type: TFLiteCompiler
parameters:
compiled_model_path: ./output/magic-wand.tflite
inference_input_type: float32
inference_output_type: float32We point our MagicWandModelWrapper to download the model from Kenning's online repository of samples: model_path: kenning:///models/classification/magic_wand.h5.
We also declare a platform, describing our target board:
platform:
type: ZephyrPlatform
parameters:
name: stm32f746g_disco
simulated: true
zephyr_build_path: ./buildKenning has a set of platforms defined in an extendable YAML file. This is, in some instances, used to infer correct settings for the optimizer.
First we optimize the model:
kenning optimize --cfg kenning-scenarios/magic-wand-inference/tflite/renode-stm32f746g.ymlThen we build the evaluation app with the model:
west build -p -b stm32f746g_disco app -- -DEXTRA_CONF_FILE=litert.conf -DCONFIG_KENNING_MODEL_PATH=\"$(realpath ./output/magic-wand.tflite)\"By default it will be built into the ./build directory.
Therefore in the platform we set zephyr_build_path: ./build.
Setting simulated: True means, that the evaluation will be performed in a Renode simulation.
For that reason we also need to build a Renode configuration file for the board:
west build -t board-replFinally, we can run the test and generate the report:
kenning test report \
--cfg kenning-scenarios/magic-wand-inference/tflite/renode-stm32f746g.yml \
--measurements results.json \
--report-path reports/stm32-renode-tflite-magic-wand/report.md \
--to-htmlThe report, detailing both quality and performance of the model, will be placed at reports/stm32-renode-tflite-magic-wand/report/report.html.
In this example, we will use Kenning's AutoML support to create a VAE anomaly detection model. Then we will optimize it for TFLite, evaluate it with Kenning Zephyr Runtime, and generate:
- A full AutoML report, detailing the search process and comparing quality and performance of top 5 models generated during the process.
- An evaluation report for the best model, including detailed Zephelin trace.
We will be using the kenning-scenarios/renode-auto-tflite-automl-vae-max32690.yml configuration file
We define an AutoPyTorchML block as our AutoML engine, and set the search parameters:
automl:
# Implementation of the AutoML flow using AutoPyTorch
type: AutoPyTorchML
parameters:
# Time limit for AutoML task (in minutes)
time_limit: 5
# List of model architectures used for AutoML,
# represented by ModelWrapper (has to implement AutoMLModel class)
use_models:
- PyTorchAnomalyDetectionVAE
output_directory: ./workspace/automl-results
# Maximum number of models returned by the flow
n_best_models: 5
optimize_metric: f1
# Type of budget for training models, either epochs or time limit
budget_type: epochs
# Lower and upper limit of the budget
min_budget: 1
max_budget: 5
# Size of the application that will use generated models
application_size: 85Parameter application_size is the size, in kilobytes, of the application that is going to run the resulting model on the device.
For example; If you're building an intelligent sensor that reports detected anomalies over a network, then this is the size of the entire application (sensor drivers, network stack, data preprocessing) except of the model itself.
Then we define the target platform:
# Chooses the platform to run
platform:
type: ZephyrPlatform
parameters:
# Chooses MAX32690 Evaluation Kit
name: max32690evkit/max32690/m4
# Use Renode to simulate the platform
simulated: TrueKenning has a set of platforms defined in an extendable YAML file.
I will take the available memory of the platform, subtract the provided application size, and use the result as a maximum size constraint for the autogenerated model.
Setting simulated: True means, that the evaluation will be performed in a Renode simulation.
We also need to define a runtime_builder - a Kenning block, that will be automatically building the Kenning Zephyr Runtime evaluation app for each model that needs to be evaluated.
runtime_builder:
type: ZephyrRuntimeBuilder
parameters:
workspace: ./kenning-zephyr-runtime
venv_dir: ../.venv
output_path: ./workspace/kzr_build
run_west_update: false
extra_targets: [board-repl]The board-repl extra target is only needed for simulations, since it generates a Renode configuration file for the selected board.
Finally, we need a dataset for training and the LiteRTCompiler for optimizing and deploying the best models:
dataset:
type: AnomalyDetectionDataset
parameters:
dataset_root: ./workspace/CATS
csv_file: kenning:///datasets/anomaly_detection/cats_nano.csv
split_fraction_test: 0.1
split_seed: 12345
inference_batch_size: 1
optimizers:
- type: LiteRTCompiler
parameters:
target: default
compiled_model_path: ./workspace/automl-results/vae.tflite
inference_input_type: float32
inference_output_type: float32The AutoML run will generate multiple models. The best one will be saved at ./workspace/automl-results/vae.0.tflite.
Other ones will be saved under vae.1.tflite, vae.2.tflite, and so on.
Now we can run Kenning.
Since the renode-auto-tflite-automl-vae-max32690.yml config file has been written to be ran from outside the Kenning Zephyr Runtime root directory, we need to override workspace parameter of the ZephyrRuntimeBuilder block with a --workspace . flag:
kenning automl optimize test report \
--cfg ./kenning-scenarios/renode-auto-tflite-automl-vae-max32690.yml \
--report-path ./workspace/automl-report/report.md \
--allow-failures --to-html \
--verbosity INFO --skip-general-information \
--workspace .Kenning will perform a search for optimal model architecture, with a 5 minute time limit, discard models that are too large for the chosen board, and then test performance of the models. Models that crash during training or fail to deploy, will be discarded without interrupting the run.
At the end generated models will be placed under ./workspace/automl-results, and the HTML report page at workspace/automl-report/report/report.html.
Now we will run an evaluation of the best-quality model, and generate a more detailed report.
First we need to install Zephelin dependencies, for the report to render correctly:
uv pip install -r ../zephelin/requirements.txtThen run:
kenning test report \
--cfg ./kenning-scenarios/renode-auto-tflite-automl-vae-max32690.yml \
--report-path ./report-vae/report.md --measurements results.json \
--to-html --verbosity INFO --workspace . --skip-general-information \
--MarkdownReport:--compiled-model-path ./workspace/automl-results/vae.0.tflite \
--modelwrapper-cls PyTorchAnomalyDetectionVAE --model-path _ \
--enable-zephelin \
--report-types \
classification \
performance \
renode_stats \
zephyr_tracesKenning can infer needed report types from context, but doesn't include renode_stats by default - so we use --report-types to override it.
We also need to add a ModelWrapper with --modelwrapper-cls flag, since is not in the configuration file (it was not needed for the AutoML process).
HTML report is saved at report-vae/report/report.html.
The process can be easily reproduced for another problem, by writing a Dataset class for another dataset.
More detailed instructions are available in the Kenning documentation.
For more information on how to configure and run these workflows, see:
- The relevant section of the documentation, which is a comprehensive guide on using Kenning Zephyr Runtime for model evaluation.
- Example of generating a comparison report, comparing two ML execution frameworks (microTVM and TFLite).
- Example of using AutoML to create an anomaly detection model and test it on the MAX32690 Evaluation Kit.
- Example of evaluating a model on a physical board.
There are several CMake functions, defined in the cmake directory.
These functions are used by demo_app and can be used by any application using kenning_inference_lib.
CMake function kenning_add_board_repl_target will add a CMake target board-repl.
This target will use the dts2repl tool, to generate a .repl file (this file format is used by the Renode emulator to describe simulated devices).
This function is used in the demo_app CMake file.
After adding the target to a Zephyr application, you will be able to build a .repl file for the board, for which the last build was ran:
west build -t board-replThe .repl file will be saved to build/<board name>.repl.
For example build/stm32f746g_disco.repl for the stm32f746g_disco board.
Function kenning_increase_board_memory will add a target increase-memory.
This target creates an .overlay file for the board, with increased memory size.
Thus Zephyr will allow a build requiring more memory, which can be then ran in a simulation (this will not work on hardware).
Adding it to a Zephyr application will allow to increase memory size of a simulated board, in a way that was described in this section of the README.
This function is used in both the demo_app and app CMake files.


