model-converter.py wraps the Arm Ethos-U Vela compiler. It reads target settings
and model information from a generated *.cbuild-mlops.yml file and converts one
or more quantized LiteRT (TensorFlow Lite) input model files.
For every input model, the converter generates:
- a Vela-optimized
.tflitemodel; - a C source file containing the optimized model as a byte array; and
- a Markdown file containing the Vela report.
- Python 3.13 or newer
- Arm Ethos-U Vela available as
velaonPATH - PyYAML
Install the Python dependency:
python -m pip install -r script/requirements.txtConfirm that Vela is available:
vela --versionpython script/model-converter.py <project.cbuild-mlops.yml>The path to the *.cbuild-mlops.yml file may be absolute or relative. Example:
python script/model-converter.py Test-Ethos-U55.cbuild-mlops.ymlThe example contains a .vscode.d/tasks.json drop-in for the CMSIS Solution
extension. After opening or updating the solution, run Tasks: Run Task from
the Command Palette and select Convert LiteRT models. Choose the generated
MLOps configuration for U55, U65, or U85 when prompted.
If the task is not visible yet, run Update Debug Tasks and Launch
Configurations from the Command Palette. The extension merges the drop-in
task into the generated workspace .vscode/tasks.json file.
Generate the selected *.cbuild-mlops.yml file by setting up or building the
corresponding solution before running the conversion task.
The generated *.cbuild-mlops.yml supplies the Vela configuration and model
selection:
cbuild-mlops:
vela:
ini: Model/vela.ini
options: >-
--accelerator-config ethos-u55-128
--system-config Ethos_U55_High_End_Embedded
--memory-mode Shared_Sram
misc: --verbose-all
model:
dir: Model
name: tiny_cnn/tiny_cnn_int8.tflitePaths are resolved relative to the directory containing the MLOps file.
The converter uses from the *.cbuild-mlops.yml file the following nodes:
vela.inias Vela's configuration file when present;vela.optionsfor generated Vela arguments;vela.miscfor optional additional Vela arguments;model.diras the model working directory; andmodel.nameto select one or more input models.
Use a string-valued model.name for a single model:
model:
dir: Model
name: tiny_cnn/tiny_cnn_int8.tfliteThe model path is relative to model.dir.
Use a sequence-valued model.name for multiple models:
model:
dir: Model
name:
- hello_world/hello_world_int8.tflite
- tiny_cnn/tiny_cnn_int8.tfliteModels are converted in declared order and must be located below model.dir.
Three optional arguments override settings from the *.cbuild-mlops.yml file:
--system <name> Vela system configuration
--memory <name> Vela memory mode
--misc <options> Complete miscellaneous option string
Change the system or memory configuration:
python script/model-converter.py Test-Ethos-U55.cbuild-mlops.yml --system Ethos_U55_High_End_Embedded
python script/model-converter.py Test-Ethos-U55.cbuild-mlops.yml --memory Shared_SramReplace all miscellaneous Vela options:
python script/model-converter.py Test-Ethos-U55.cbuild-mlops.yml --misc="--verbose-all --timing"An empty value removes them:
python script/model-converter.py Test-Ethos-U55.cbuild-mlops.yml --misc=""--misc replaces vela.misc; it does not append to it.
Given this input:
Model/tiny_cnn/tiny_cnn_int8.tflite
the converter produces:
Model/tiny_cnn/tiny_cnn_int8_vela.tflite
Model/tiny_cnn/tiny_cnn_model.c
Model/tiny_cnn/VELA_SUMMARY.md
The _int8 suffix is removed when naming the C source. For network.tflite,
the outputs are network_vela.tflite and network_model.c.
The C source exports:
const uint8_t tiny_cnn_int8_vela_tflite[];
const uint32_t tiny_cnn_int8_vela_tflite_len;The array is aligned to 16 bytes and placed in the ethos_model section.
VELA_SUMMARY.md records the effective accelerator, system, and memory
configuration followed by Vela's report. Command-line overrides are reflected
in this file.
Outputs are prepared in temporary storage and replace destination files only after Vela succeeds.
0: all models were converted.1: Vela or output generation failed.2: command-line or YAML configuration is invalid.
The converter validates configuration files, directories, and models before starting Vela. Common errors include:
- Vela is missing from
PATH; model.dir, a model, or the Vela INI file does not exist;model.nameis missing, empty, or malformed; and- a model path escapes
model.dir.
From the example directory:
python -m unittest discover -s script_test -p "test_*.py" -vThe suite includes a real Vela conversion when vela is installed.