mlonmcu.models package

Submodules

mlonmcu.models.convert_data module

Utility to convert various types of data into MLonMCU compatible raw binary files.

mlonmcu.models.convert_data.convert(mode, val)[source]

Actual convertion function.

Returns:
databytes

Raw converted output.

Raises:
AssertionError

If the choses mode does not exist or value has a wrong shape.

ValueError

If the conversion failed.

mlonmcu.models.convert_data.main()[source]

Main entry pint handling command line options.

mlonmcu.models.convert_data.write_file(dest, data)[source]

Utility to save the file to disk.

mlonmcu.models.frontend module

class mlonmcu.models.frontend.CoremarkFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.DhrystoneFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.EmbenchFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {'embench.src_dir'}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
get_platform_defs(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.ExampleFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.Frontend(name, input_formats=None, output_formats=None, features=None, config=None)[source]

Bases: ABC

DEFAULTS = {'use_inout_data': False}
FEATURES = {'validate'}
OPTIONAL = {}
REQUIRED = {}
add_platform_config(platform, config)[source]
add_platform_defs(platform, defs)[source]
export_artifacts(path)[source]
generate(model) Tuple[dict, dict][source]
generate_artifacts(model) List[Artifact][source]
get_platform_config(platform)[source]
get_platform_defs(platform)[source]
lookup_models(names, config=None, context=None)[source]
process_features(features)[source]
process_metadata(model, cfg=None)[source]
abstract produce_artifacts(model)[source]
supports_formats(ins=None, outs=None)[source]

Returs true if the frontend can handle at least one combination of input and output formats.

property use_inout_data
class mlonmcu.models.frontend.LayerGenFrontend(features=None, config=None)[source]

Bases: Frontend

DEFAULTS = {'fmt': 'tflite', 'use_inout_data': False}
FEATURES = {'validate'}
REQUIRED = {'layergen.exe'}
property fmt
generate(model) Tuple[dict, dict][source]
property layergen_exe
produce_artifacts(model)[source]
class mlonmcu.models.frontend.MathisFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.MibenchFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {'mibench.src_dir'}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
get_platform_defs(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.ONNXFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

class mlonmcu.models.frontend.PBFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

class mlonmcu.models.frontend.PackedFrontend(features=None, config=None)[source]

Bases: Frontend

DEFAULTS = {'check': False, 'fake_pack': False, 'ignore_existing': True, 'use_inout_data': False, 'use_packed': True}
FEATURES = {'packed', 'packing', 'validate'}
REQUIRED = {'packer.exe'}
property check
property fake_pack
property ignore_existing
produce_artifacts(model)[source]
property use_packed
class mlonmcu.models.frontend.PaddleFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

class mlonmcu.models.frontend.PolybenchFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {'polybench.src_dir'}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
get_platform_defs(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.RelayFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

DEFAULTS = {'relayviz_plotter': 'term', 'use_inout_data': False, 'visualize_graph': False}
FEATURES = {'relayviz', 'validate'}
REQUIRED = {'tvm.build_dir', 'tvm.pythonpath'}
produce_artifacts(model)[source]
property relayviz_plotter
property tvm_build_dir
property tvm_pythonpath
property visualize_graph
class mlonmcu.models.frontend.SimpleFrontend(name, fmt, features=None, config=None)[source]

Bases: Frontend

An abstract frontend with equivalent input and output formats.

produce_artifacts(model)[source]
class mlonmcu.models.frontend.TaclebenchFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

REQUIRED = {'taclebench.src_dir'}
generate(model) Tuple[dict, dict][source]
get_platform_config(platform)[source]
get_platform_defs(platform)[source]
lookup_models(names, config=None, context=None)[source]
property supported_names
class mlonmcu.models.frontend.TfLiteFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

DEFAULTS = {'analyze_enable': False, 'analyze_script': None, 'pack_script': None, 'split_layers': False, 'use_inout_data': False, 'visualize_enable': False, 'visualize_script': None}
FEATURES = {'split_layers', 'tflite_analyze', 'validate', 'visualize'}
OPTIONAL = {'tflite_analyze.script'}
REQUIRED = {}
property analyze_enable
property analyze_script
generate(model) Tuple[dict, dict][source]
property pack_script
produce_artifacts(model)[source]
property split_layers
property visualize_enable
property visualize_script

mlonmcu.models.group module

class mlonmcu.models.group.ModelGroup(name, models, description='')[source]

Bases: object

mlonmcu.models.lookup module

mlonmcu.models.lookup.apply_modelgroups(models, context=None)[source]
mlonmcu.models.lookup.find_metadata(directory, model_name=None)[source]
mlonmcu.models.lookup.get_model_directories(context)[source]
mlonmcu.models.lookup.list_modelgroups(directory)[source]
mlonmcu.models.lookup.list_models(directory, depth=1, formats=None, config=None)[source]
mlonmcu.models.lookup.lookup_models(names, frontends=None, config=None, context=None)[source]
mlonmcu.models.lookup.lookup_models_and_groups(directories, formats, config=None)[source]
mlonmcu.models.lookup.map_frontend_to_model(model, frontends, backend=None)[source]
mlonmcu.models.lookup.print_groups(groups, all_models=[], duplicates=[], detailed=False)[source]
mlonmcu.models.lookup.print_models(models, duplicates=[], detailed=False)[source]
mlonmcu.models.lookup.print_paths(directories)[source]
mlonmcu.models.lookup.print_summary(context, detailed=False)[source]

mlonmcu.models.metadata module

mlonmcu.models.metadata.parse_metadata(path)[source]

mlonmcu.models.model module

class mlonmcu.models.model.CoremarkProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.DhrystoneProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.EmbenchProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.ExampleProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.MathisProgram(name, config=None, alt=None)[source]

Bases: Program

DEFAULTS = {'size': 1024}
get_elem_size(name)[source]
get_nargs(name)[source]
get_platform_defs(platform)[source]
property size
class mlonmcu.models.model.MibenchProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.Model(name, paths, config=None, alt=None, formats=ModelFormats.TFLITE)[source]

Bases: Workload

DEFAULTS = {'input_shapes': None, 'input_types': None, 'inputs_path': 'input', 'metadata_path': 'definition.yml', 'output_shapes': None, 'output_types': None, 'outputs_path': 'output', 'support_path': 'support'}
property input_shapes
property input_types
property inputs_path
property metadata_path
property output_shapes
property output_types
property outputs_path
property skip_check
property support_path
class mlonmcu.models.model.ModelFormat(value, extensions)

Bases: tuple

extensions

Alias for field number 1

value

Alias for field number 0

class mlonmcu.models.model.ModelFormats(value)[source]

Bases: Enum

An enumeration.

IPYNB = (3, ['ipynb'])
NONE = (0, [])
ONNX = (4, ['onnx'])
PACKED = (2, ['tflm'])
PADDLE = (7, ['pdmodel'])
PB = (6, ['pb'])
RELAY = (5, ['relay'])
TEXT = (8, ['txt'])
TFLITE = (1, ['tflite'])
property extension
property extensions
classmethod from_extension(ext)[source]
class mlonmcu.models.model.PolybenchProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.Program(name, config=None, alt=None)[source]

Bases: Workload

class mlonmcu.models.model.TaclebenchProgram(name, config=None, alt=None)[source]

Bases: Program

get_platform_defs(platform)[source]
class mlonmcu.models.model.Workload(name, config=None, alt=None)[source]

Bases: object

DEFAULTS = {}
add_platform_config(platform, config)[source]
add_platform_defs(platform, defs)[source]
get_platform_config(platform)[source]
get_platform_defs(platform)[source]
mlonmcu.models.model.parse_metadata_from_path(path)[source]
mlonmcu.models.model.parse_shape_string(inputs_string)[source]

Parse an input shape dictionary string to a usable dictionary.

Taken from: https://github.com/apache/tvm/blob/main/python/tvm/driver/tvmc/shape_parser.py

Parameters:
inputs_string: str

A string of the form “input_name:[dim1,dim2,…,dimn] input_name2:[dim1,dim2]” that indicates the desired shape for specific model inputs. Colons, forward slashes and dots within input_names are supported. Spaces are supported inside of dimension arrays.

Returns
——-
shape_dict: dict

A dictionary mapping input names to their shape for use in relay frontend converters.

mlonmcu.models.model.parse_type_string(inputs_string)[source]

Parse an input type dictionary string to a usable dictionary.

Parameters:
inputs_string: str

A string of the form “input_name:ty input_name2:ty” that indicates the desired type for specific model inputs/outputs. Colons, forward slashes and dots within input_names are supported. Spaces are supported inside of dimension arrays.

Returns
——-
type_dict: dict

A dictionary mapping input names to their type.

mlonmcu.models.options module

class mlonmcu.models.options.BackendModelOptions(backend, supported=True, options={})[source]

Bases: object

class mlonmcu.models.options.TFLMIModelOptions(backend, supported=True, arena_size=None, builtin_ops=None, custom_ops=None)[source]

Bases: BackendModelOptions

class mlonmcu.models.options.TVMRTModelOptions(backend, supported=True, arena_size=None)[source]

Bases: BackendModelOptions

mlonmcu.models.options.parse_model_options_for_backend(backend, options)[source]

mlonmcu.models.utils module

mlonmcu.models.utils.fill_data_source(in_bufs, out_bufs)[source]
mlonmcu.models.utils.get_data_source(input_paths, output_paths)[source]
mlonmcu.models.utils.lookup_data_buffers(input_paths, output_paths)[source]
mlonmcu.models.utils.make_hex_array(filename, mode='bin')[source]

Module contents

class mlonmcu.models.LayerGenFrontend(features=None, config=None)[source]

Bases: Frontend

DEFAULTS = {'fmt': 'tflite', 'use_inout_data': False}
FEATURES = {'validate'}
REQUIRED = {'layergen.exe'}
property fmt
generate(model) Tuple[dict, dict][source]
property layergen_exe
produce_artifacts(model)[source]
class mlonmcu.models.ONNXFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

class mlonmcu.models.PBFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

class mlonmcu.models.PackedFrontend(features=None, config=None)[source]

Bases: Frontend

DEFAULTS = {'check': False, 'fake_pack': False, 'ignore_existing': True, 'use_inout_data': False, 'use_packed': True}
FEATURES = {'packed', 'packing', 'validate'}
REQUIRED = {'packer.exe'}
property check
property fake_pack
property ignore_existing
produce_artifacts(model)[source]
property use_packed
class mlonmcu.models.TfLiteFrontend(features=None, config=None)[source]

Bases: SimpleFrontend

DEFAULTS = {'analyze_enable': False, 'analyze_script': None, 'pack_script': None, 'split_layers': False, 'use_inout_data': False, 'visualize_enable': False, 'visualize_script': None}
FEATURES = {'split_layers', 'tflite_analyze', 'validate', 'visualize'}
OPTIONAL = {'tflite_analyze.script'}
REQUIRED = {}
property analyze_enable
property analyze_script
generate(model) Tuple[dict, dict][source]
property pack_script
produce_artifacts(model)[source]
property split_layers
property visualize_enable
property visualize_script
mlonmcu.models.print_summary(context, detailed=False)[source]