[SOLVED] TVMC Python for MicroTVM

I am trying to use MicroTVM’s compile flow directly from my Python script (for automating purposes). Compiling the model through the tvmc CLI works fine, but I am failing to convert all parameters to the appropriate parameters in the Python TVMC interface.

The CLI input looks like this:

tvmc compile \
    --target=ethos-u,cmsis-nn,c \
    --target-ethos-u-accelerator_config=ethos-u55-128 \
    --target-c-mcpu=cortex-m55 \
    --runtime=crt \
    --executor=aot \
    --executor-aot-interface-api=c \
    --executor-aot-unpacked-api=1 \
    --pass-config tir.usmp.enable=1  \
    --pass-config tir.usmp.algorithm=hill_climb  \
    --pass-config tir.disable_storage_rewrite=1  \
    --pass-config tir.disable_vectorize=1 \
    --output-format=mlf \
    --verbose \
    test.tflite

I am especially confused about the executor-aot-interface/unpacked args as well as the target-ethos-u and target-c-mcpu arguments.

A minimal working example without Ethos-U seems to be working when using this:


target = "cmsis-nn,c"

# Set the pass configurations
pass_context_configs = {
    "tir.usmp.enable=1",
    "tir.usmp.algorithm=hill_climb",
    "tir.disable_storage_rewrite=1",
    "tir.disable_vectorize=1",
}

# Compile the model
output = tvmc.compile(
    tvmc_model=model,
    target=target,
    output_format="mlf",
    pass_context_configs=pass_context_configs,
    package_path="./module.tar"
)

but I am unsure, where to put the currently missing arguments.

Hi. do you have an error message to share?

I think, I solved it now, it wasn’t really an error, more an issue on finding information on how to translate the parameters from CLI to Python.

I am now executing:

mcpu:str="cortex-m55"
ethos_u : bool = True
runtime = tvm.relay.backend.Runtime(name=runtime, options={"system-lib": True})
executor = tvm.relay.backend.Executor(name=executor, options={"unpacked-api": True, "interface-api": "c", "workspace-byte-alignment": 8})

pass_context_configs = [
    "tir.disable_vectorize=1",
    ]

    if ethos_u:
      add_targets["ethos-u"] = {
        'accelerator_config': ethos_u_config
      }
      target = "ethos-u,"+target

      pass_context_configs.append("tir.usmp.enable=1")
      pass_context_configs.append("tir.usmp.algorithm=hill_climb")
      pass_context_configs.append("tir.disable_storage_rewrite=1")

    add_targets["c"] = {
      "mcpu" : mcpu,
    }

tvmc.compile(
      tvmc_model=model,
      target=target,
      additional_target_options=add_targets,
      runtime=runtime,
      executor=executor
      output_format="mlf",
      pass_context_configs=pass_context_configs,
      package_path=output_path,
    )

which seems to produce usable results.

1 Like

OK, thanks for confirming. Can you edit your title to say “[solved]” or something to that effect?