You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2022/01/22 00:02:04 UTC

[GitHub] [tvm] mehrdadh opened a new pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

mehrdadh opened a new pull request #10024:
URL: https://github.com/apache/tvm/pull/10024


   This PR adds a TVMC tutorial for Zephyr platforms using ```tvmc micro```.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r791107241



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr board, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not
+# actually perform any action since QEMU will be used, however you need this step for physical hardware.
+#
+# .. code-block:: bash
+#
+#     tvmc micro flash \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+
+############################################################
+# Run Tiny Model on Micro Target
+############################################################
+#
+# To run the flashed model on the device using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``

Review comment:
       @areusch added more details. Please let me know if I should mention anything else. thanks!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
areusch commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r791010990



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this

Review comment:
       ```suggestion
   # TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr board, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not
+# actually perform any action since QEMU will be used, however you need this step for physical hardware.
+#
+# .. code-block:: bash
+#
+#     tvmc micro flash \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+
+############################################################
+# Run Tiny Model on Micro Target
+############################################################
+#
+# To run the flashed model on the device using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``

Review comment:
       could you explain what exactly has happened now at this point, and what we mean by "run the flashed model on the device?"

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.

Review comment:
       ```suggestion
   # package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about

Review comment:
       could you explain host_driven here?

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a

Review comment:
       ```suggestion
   # For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as

Review comment:
       nit: tvm.driver.tvmc




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r791107411



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about

Review comment:
       Added some details, PTAL. thanks!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch merged pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
areusch merged pull request #10024:
URL: https://github.com/apache/tvm/pull/10024


   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r792816223



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -169,8 +172,11 @@
 # Run Tiny Model on Micro Target
 ############################################################
 #
-# To run the flashed model on the device using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``
-# to specify the device type.
+# After flashing the device, the compiled model and TVM host driven `Graph Executor` handler are programmed on the device.

Review comment:
       done.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#issuecomment-1020369483


   @gromero thanks for the review! I added your changes, PTAL.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
areusch commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r791010990



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this

Review comment:
       ```suggestion
   # TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr board, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not
+# actually perform any action since QEMU will be used, however you need this step for physical hardware.
+#
+# .. code-block:: bash
+#
+#     tvmc micro flash \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+
+############################################################
+# Run Tiny Model on Micro Target
+############################################################
+#
+# To run the flashed model on the device using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``

Review comment:
       could you explain what exactly has happened now at this point, and what we mean by "run the flashed model on the device?"

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.

Review comment:
       ```suggestion
   # package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about

Review comment:
       could you explain host_driven here?

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a

Review comment:
       ```suggestion
   # For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as

Review comment:
       nit: tvm.driver.tvmc




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#issuecomment-1018982558


   cc @areusch @gromero 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] areusch commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
areusch commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r792170149



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -169,8 +172,11 @@
 # Run Tiny Model on Micro Target
 ############################################################
 #
-# To run the flashed model on the device using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``
-# to specify the device type.
+# After flashing the device, the compiled model and TVM host driven `Graph Executor` handler are programmed on the device.

Review comment:
       ```suggestion
   # After flashing the device, the compiled model and TVM RPC server are programmed on the device.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r791107241



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr board, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not
+# actually perform any action since QEMU will be used, however you need this step for physical hardware.
+#
+# .. code-block:: bash
+#
+#     tvmc micro flash \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+
+############################################################
+# Run Tiny Model on Micro Target
+############################################################
+#
+# To run the flashed model on the device using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``

Review comment:
       @areusch added more details. Please let me know if I should mention anything else. thanks!

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about

Review comment:
       Added some details, PTAL. thanks!




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#issuecomment-1020369483


   @gromero thanks for the review! I added your changes, PTAL.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] hogepodge commented on pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
hogepodge commented on pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#issuecomment-1022375775


   Thanks for this, read through it and it looks good to me.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] mehrdadh commented on pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
mehrdadh commented on pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#issuecomment-1018993379


   cc @hogepodge 


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] gromero commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
gromero commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r790819451



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 

Review comment:
       There is a trailing space here that needs to get removed.

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 
+build a program on Zephyr platform to execute this model, flash the program 
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly. ◊◊◊

Review comment:
       There  seems to be one trailing space and two odd (diamonds?) chars here that need to get removed.

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 
+build a program on Zephyr platform to execute this model, flash the program 
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly. ◊◊◊
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Projecg Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr baord, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not
+# actually perform any action, however you need this step for physical hardware.

Review comment:
       I would add  "... actually perform any action **because QEMU will be used**, however..." just be super clear that `flash()` does nothing for that specific board.

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 
+build a program on Zephyr platform to execute this model, flash the program 

Review comment:
       There is a trailing space here that needs to get removed.

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 
+build a program on Zephyr platform to execute this model, flash the program 
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly. ◊◊◊
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Projecg Using Model Library Format

Review comment:
       `s/Projecg/Project`

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 
+build a program on Zephyr platform to execute this model, flash the program 
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly. ◊◊◊
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Projecg Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr baord, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not
+# actually perform any action, however you need this step for physical hardware.
+#
+# .. code-block:: bash
+#
+#     tvmc micro flash \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+
+############################################################
+# Run Tiny Model on Micro Target
+############################################################
+#
+# To run the model in microtvm using TVMC, we use ``tvmc run`` subcommand and we pass ``--device micro``

Review comment:
       Maybe s/To run the model in microtvm/ To run the flashed model on the device/ ? 

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,192 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device, 
+build a program on Zephyr platform to execute this model, flash the program 
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a python package which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. First option is to use ``tvmc`` command directly. ◊◊◊
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvm`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magin Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Projecg Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a Zephyr project for `qemu_x86` zephyr board. To get more information about
+# TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in host_driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr baord, change `zephyr_board` project option.

Review comment:
       `s/baord/board/`




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] driazati commented on a change in pull request #10024: [microTVM][tvmc] Add TVMC Micro tutorial for Zephyr

Posted by GitBox <gi...@apache.org>.
driazati commented on a change in pull request #10024:
URL: https://github.com/apache/tvm/pull/10024#discussion_r793116091



##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvmc`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:

Review comment:
       fun rst nits:
   ```suggestion
   # Here, we generate a MLF file for ``qemu_x86`` Zephyr board. To generate MLF output for the ``magic_wand`` tflite model:
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvmc`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a `Host-Driven` Zephyr project for `qemu_x86` Zephyr board. In Host-Driven template project,

Review comment:
       ```suggestion
   # This will generate a `Host-Driven` Zephyr project for ``qemu_x86`` Zephyr board. In Host-Driven template project,
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvmc`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a `Host-Driven` Zephyr project for `qemu_x86` Zephyr board. In Host-Driven template project,
+# the Graph Executor will run on host and perform the model execution on Zephyr device by issuing commands to the
+# device using an RPC mechanism. Read more about `Host-Driven Execution <https://tvm.apache.org/docs/arch/microtvm_design.html#host-driven-execution>`_.
+#
+# To get more information about TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in Host-Driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build

Review comment:
       ```suggestion
   # This will build the project in ``project`` directory and generates binary files under ``project/build``. To build
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvmc`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for

Review comment:
       ```suggestion
   # This will generate a ``model.tar`` file which contains TVM compiler output files. To run this command for
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvmc`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a `Host-Driven` Zephyr project for `qemu_x86` Zephyr board. In Host-Driven template project,
+# the Graph Executor will run on host and perform the model execution on Zephyr device by issuing commands to the
+# device using an RPC mechanism. Read more about `Host-Driven Execution <https://tvm.apache.org/docs/arch/microtvm_design.html#host-driven-execution>`_.
+#
+# To get more information about TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in Host-Driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr board, change `zephyr_board` project option.
+#
+# Next, we flash the Zephyr binary file to Zephyr device. For `qemu_x86` Zephyr board this step does not

Review comment:
       ```suggestion
   # Next, we flash the Zephyr binary file to Zephyr device. For ``qemu_x86`` Zephyr board this step does not
   ```

##########
File path: gallery/how_to/work_with_microtvm/micro_tvmc.py
##########
@@ -0,0 +1,197 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+.. _tutorial-micro-tvmc:
+
+Executing a Tiny Model with TVMC Micro
+=========================
+**Author**: `Mehrdad Hessar <https://github.com/mehrdadh>`_
+
+This tutorial explains how to compile a tiny model for a micro device,
+build a program on Zephyr platform to execute this model, flash the program
+and run the model all using `tvmc micro` command.
+"""
+
+######################################################################
+# .. note::
+#     This tutorial is explaining using TVMC Mirco on Zephyr platform. You need
+#     to install Zephyr dependencies before processing with this tutorial. Alternatively,
+#     you can run this tutorial in one of the following ways which has Zephyr depencencies already installed.
+#
+#     * Use `microTVM Reference Virtual Machines <https://tvm.apache.org/docs/how_to/work_with_microtvm/micro_reference_vm.html#sphx-glr-how-to-work-with-microtvm-micro-reference-vm-py>`_.
+#     * Use QEMU docker image provided by TVM. Following these you will download and login to the docker image:
+#     .. code-block:: bash
+#
+#         cd tvm
+#         ./docker/bash.sh tlcpack/ci-qemu
+#
+
+
+############################################################
+# Using TVMC Micro
+############################################################
+#
+# TVMC is a command-line tool which is installed as a part of TVM Python packages. Accessing this
+# package varies based on your machine setup. In many cases, you can use the ``tvmc`` command directly.
+# Alternatively, if you have TVM as a Python module on your ``$PYTHONPATH``, you can access this
+# driver with ``python -m tvm.driver.tvmc`` command. This tutorial will use TVMC command as
+# ``tvmc`` for simplicity.
+#
+# To check if you have TVMC command installed on your machine, you can run:
+#
+# .. code-block:: bash
+#
+#     tvmc --help
+#
+# To compile a model for microtvm we use ``tvmc compile`` subcommand. The output of this command
+# is used in next steps with ``tvmc micro`` subcommands. You can check the availability of TVMC Micro using:
+#
+# .. code-block:: bash
+#
+#     tvmc micro --help
+#
+# The main tasks that you can perform using ``tvmc micro`` are ``create``, ``build`` and ``flash``.
+# To read about specific options under a givern subcommand, use
+# ``tvmc micro <subcommand> --help``. We will use each subcommand in this tutorial.
+#
+
+############################################################
+# Obtain a Tiny Model
+############################################################
+#
+# For this tutorial, we will use Magic Wand model from tflite micro. Magic Wand is a
+# Depthwise Convolution Layer model which recognizes gestures with an accelerometer.
+#
+# For this tutorial we will be using the model in tflite format.
+#
+# .. code-block:: bash
+#
+#     wget https://github.com/tensorflow/tflite-micro/raw/main/tensorflow/lite/micro/examples/magic_wand/magic_wand.tflite
+#
+
+############################################################
+# Compiling a TFLite model to a Model Library Format
+############################################################
+#
+# Model Library Format (MLF) is an output format that TVM provides for micro targets. MLF is a tarball
+# containing a file for each piece of the TVM compiler output which can be used on micro targets outside
+# TVM environment. Read more about `Model Library Format <https://tvm.apache.org/docs//arch/model_library_format.html>`_.
+#
+# Here, we generate a MLF file for `qemu_x86` Zephyr board. To generate MLF output for the `magic_wand` tflite model:
+#
+# .. code-block:: bash
+#
+#     tvmc compile magic_wand.tflite \
+#       --target='c -keys=cpu -link-params=0 -model=host' \
+#       --runtime=crt \
+#       --runtime-crt-system-lib 1 \
+#       --executor='graph' \
+#       --executor-graph-link-params 0 \
+#       --output model.tar \
+#       --output-format mlf \
+#       --pass-config tir.disable_vectorize=1 \
+#       --disabled-pass=AlterOpLayout
+#
+# This will generate a `model.tar` file which contains TVM compiler output files. To run this command for
+# a different Zephyr device, you need to update `target`. For instance, for `nrf5340dk_nrf5340_cpuapp` board
+# the target is ``--target='c -keys=cpu -link-params=0 -model=nrf5340dk'``.
+#
+
+
+############################################################
+# Create a Zephyr Project Using Model Library Format
+############################################################
+#
+# To generate a Zephyr project we use TVM Micro subcommand ``create``. We pass the MLF format and the path
+# for the project to ``create`` subcommand along with project options. Project options for each
+# platform (Zephyr/Arduino) are defined in their Project API server file. To generate Zephyr project, run:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create \
+#       project \
+#       model.tar \
+#       zephyr \
+#       --project-option project_type=host_driven zephyr_board=qemu_x86
+#
+# This will generate a `Host-Driven` Zephyr project for `qemu_x86` Zephyr board. In Host-Driven template project,
+# the Graph Executor will run on host and perform the model execution on Zephyr device by issuing commands to the
+# device using an RPC mechanism. Read more about `Host-Driven Execution <https://tvm.apache.org/docs/arch/microtvm_design.html#host-driven-execution>`_.
+#
+# To get more information about TVMC Micro ``create`` subcommand:
+#
+# .. code-block:: bash
+#
+#     tvmc micro create --help
+#
+
+############################################################
+# Build and Flash Zephyr Project Using TVMC Micro
+############################################################
+#
+# Next step is to build the Zephyr project which includes TVM generated code for running the tiny model, Zephyr
+# template code to run a model in Host-Driven mode and TVM runtime source/header files. To build the project:
+#
+# .. code-block:: bash
+#
+#     tvmc micro build \
+#       project \
+#       zephyr \
+#       --project-option zephyr_board=qemu_x86
+#
+# This will build the project in `project` directory and generates binary files under `project/build`. To build
+# Zephyr project for a different Zephyr board, change `zephyr_board` project option.

Review comment:
       ```suggestion
   # Zephyr project for a different Zephyr board, change ``zephyr_board`` project option.
   ```




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org