Skip to content

Commit c2cc019

Browse files
authored
[microTVM] Update tutorials (#13845)
This PR updates microTVM tutorials to use updated APIs. It also adds an ordering to the tutorials that are useful for first time users. RVM tutorial is also removed as it is not supported anymore.
1 parent 95fa223 commit c2cc019

File tree

13 files changed

+105
-272
lines changed

13 files changed

+105
-272
lines changed

docs/conf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -511,15 +511,15 @@ def jupyter_notebook(script_blocks, gallery_conf, target_dir, real_func):
511511
"use_pass_instrument.py",
512512
"bring_your_own_datatypes.py",
513513
],
514-
"micro": [
515-
"micro_train.py",
516-
"micro_autotune.py",
517-
"micro_reference_vm.py",
518-
"micro_tflite.py",
519-
"micro_ethosu.py",
514+
"work_with_microtvm": [
520515
"micro_tvmc.py",
516+
"micro_tflite.py",
521517
"micro_aot.py",
522518
"micro_pytorch.py",
519+
"micro_train.py",
520+
"micro_autotune.py",
521+
"micro_ethosu.py",
522+
"micro_mlperftiny.py",
523523
],
524524
}
525525

docs/topic/microtvm/index.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ Getting Started with microTVM
5050
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5151

5252
Before working with microTVM, we recommend you have a supported development board. Then, follow these
53-
tutorials to get started with microTVM:
53+
tutorials to get started with microTVM. Tutorials are in the order that could help developers to learn
54+
more as they follow through them. Here is a list of tutorials that you can start with:
5455

55-
1. :ref:`Start the microTVM Reference VM <tutorial-micro-reference-vm>`. The microTVM tutorials
56-
depend on Zephyr and on a compiler toolchain for your hardware. The reference VM is a convenient
57-
way to install those dependencies.
58-
2. Try the :ref:`microTVM with TFLite Tutorial <microTVM-with-TFLite>`.
59-
3. Try running a more complex `CIFAR10-CNN model <https://github.com/areusch/microtvm-blogpost-eval>`_.
56+
1. Try :ref:`microTVM CLI Tool <tutorial-micro-cli-tool>`.
57+
2. Try the :ref:`microTVM TFLite Tutorial <tutorial_micro_tflite>`.
58+
3. Try running a more complex tutorial: :ref:`Creating Your MLPerfTiny Submission with microTVM <tutorial-micro-mlperftiny>`.
6059

6160

6261
How microTVM Works

gallery/how_to/work_with_microtvm/micro_aot.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""
18-
.. _tutorial-micro-AoT:
18+
.. _tutorial-micro-aot:
1919
20-
microTVM Host-Driven AoT
21-
===========================
20+
3. microTVM Ahead-of-Time (AOT) Compilation
21+
===========================================
2222
**Authors**:
2323
`Mehrdad Hessar <https://github.com/mehrdadh>`_,
2424
`Alan MacDonald <https://github.com/alanmacd>`_
@@ -59,6 +59,7 @@
5959

6060
import tvm
6161
from tvm import relay
62+
import tvm.micro.testing
6263
from tvm.relay.backend import Executor, Runtime
6364
from tvm.contrib.download import download_testdata
6465

@@ -102,27 +103,23 @@
102103
# using AOT host driven executor. We use the host micro target which is for running a model
103104
# on x86 CPU using CRT runtime or running a model with Zephyr platform on qemu_x86 simulator
104105
# board. In the case of a physical microcontroller, we get the target model for the physical
105-
# board (E.g. nucleo_l4r5zi) and pass it to `tvm.target.target.micro` to create a full
106-
# micro target.
106+
# board (E.g. nucleo_l4r5zi) and change `BOARD` to supported Zephyr board.
107107
#
108108

109109
# Use the C runtime (crt) and enable static linking by setting system-lib to True
110110
RUNTIME = Runtime("crt", {"system-lib": True})
111111

112112
# Simulate a microcontroller on the host machine. Uses the main() from `src/runtime/crt/host/main.cc`.
113113
# To use physical hardware, replace "host" with something matching your hardware.
114-
TARGET = tvm.target.target.micro("host")
114+
TARGET = tvm.micro.testing.get_target("crt")
115115

116116
# Use the AOT executor rather than graph or vm executors. Don't use unpacked API or C calling style.
117117
EXECUTOR = Executor("aot")
118118

119119
if use_physical_hw:
120-
boards_file = pathlib.Path(tvm.micro.get_microtvm_template_projects("zephyr")) / "boards.json"
121-
with open(boards_file) as f:
122-
boards = json.load(f)
123120
BOARD = os.getenv("TVM_MICRO_BOARD", default="nucleo_l4r5zi")
124121
SERIAL = os.getenv("TVM_MICRO_SERIAL", default=None)
125-
TARGET = tvm.target.target.micro(boards[BOARD]["model"])
122+
TARGET = tvm.micro.testing.get_target("zephyr", BOARD)
126123

127124
######################################################################
128125
# Compile the model

gallery/how_to/work_with_microtvm/micro_autotune.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"""
1919
.. _tutorial-micro-autotune:
2020
21-
Autotuning with microTVM
22-
=========================
21+
6. Model Tuning with microTVM
22+
=============================
2323
**Authors**:
2424
`Andrew Reusch <https://github.com/areusch>`_,
2525
`Mehrdad Hessar <https://github.com/mehrdadh>`_
@@ -55,6 +55,7 @@
5555

5656
import tvm
5757
from tvm.relay.backend import Runtime
58+
import tvm.micro.testing
5859

5960
####################
6061
# Defining the model
@@ -102,20 +103,16 @@
102103
#
103104

104105
RUNTIME = Runtime("crt", {"system-lib": True})
105-
TARGET = tvm.target.target.micro("host")
106+
TARGET = tvm.micro.testing.get_target("crt")
106107

107108
# Compiling for physical hardware
108109
# --------------------------------------------------------------------------
109110
# When running on physical hardware, choose a TARGET and a BOARD that describe the hardware. The
110111
# STM32L4R5ZI Nucleo target and board is chosen in the example below.
111112
if use_physical_hw:
112-
boards_file = pathlib.Path(tvm.micro.get_microtvm_template_projects("zephyr")) / "boards.json"
113-
with open(boards_file) as f:
114-
boards = json.load(f)
115-
116113
BOARD = os.getenv("TVM_MICRO_BOARD", default="nucleo_l4r5zi")
117114
SERIAL = os.getenv("TVM_MICRO_SERIAL", default=None)
118-
TARGET = tvm.target.target.micro(boards[BOARD]["model"])
115+
TARGET = tvm.micro.testing.get_target("zephyr", BOARD)
119116

120117

121118
#########################

gallery/how_to/work_with_microtvm/micro_ethosu.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""
18-
Running TVM on bare metal Arm(R) Cortex(R)-M55 CPU and Ethos(TM)-U55 NPU with CMSIS-NN
19-
======================================================================================
18+
.. _tutorial-micro-ethosu:
19+
20+
7. Running TVM on bare metal Arm(R) Cortex(R)-M55 CPU and Ethos(TM)-U55 NPU with CMSIS-NN
21+
=========================================================================================
2022
**Author**:
2123
`Grant Watson <https://github.com/grant-arm>`_
2224

gallery/how_to/work_with_microtvm/micro_mlperftiny.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""
18-
.. _tutorial-micro-MLPerfTiny:
18+
.. _tutorial-micro-mlperftiny:
1919
20-
Creating Your MLPerfTiny Submission with microTVM
21-
=================================================
20+
8. Creating Your MLPerfTiny Submission with microTVM
21+
====================================================
2222
**Authors**:
2323
`Mehrdad Hessar <https://github.com/mehrdadh>`_
2424
@@ -69,6 +69,7 @@
6969
from tvm.contrib.download import download_testdata
7070
from tvm.micro import export_model_library_format
7171
from tvm.micro.model_library_format import generate_c_interface_header
72+
import tvm.micro.testing
7273
from tvm.micro.testing.utils import (
7374
create_header_file,
7475
mlf_extract_workspace_size_bytes,

gallery/how_to/work_with_microtvm/micro_pytorch.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717
"""
18-
.. _tutorial-micro-Pytorch:
18+
.. _tutorial-micro-pytorch:
1919
20-
microTVM PyTorch Tutorial
21-
===========================
20+
4. microTVM PyTorch Tutorial
21+
============================
2222
**Authors**:
2323
`Mehrdad Hessar <https://github.com/mehrdadh>`_
2424
@@ -46,6 +46,7 @@
4646
from tvm import relay
4747
from tvm.contrib.download import download_testdata
4848
from tvm.relay.backend import Executor
49+
import tvm.micro.testing
4950

5051
##################################
5152
# Load a pre-trained PyTorch model
@@ -91,13 +92,14 @@
9192
# and we use `host` micro target. Using this setup, TVM compiles the model
9293
# for C runtime which can run on a x86 CPU machine with the same flow that
9394
# would run on a physical microcontroller.
95+
# CRT Uses the main() from `src/runtime/crt/host/main.cc`
96+
# To use physical hardware, replace `board` with another physical micro target, e.g. `nrf5340dk_nrf5340_cpuapp`
97+
# or `mps2_an521` and change the platform type to Zephyr.
98+
# See more target examples in :ref:`Training Vision Models for microTVM on Arduino <tutorial-micro-train-arduino>`
99+
# and :ref:`microTVM TFLite Tutorial<tutorial_micro_tflite>`.
94100
#
95101

96-
97-
# Simulate a microcontroller on the host machine. Uses the main() from `src/runtime/crt/host/main.cc`
98-
# To use physical hardware, replace "host" with another physical micro target, e.g. `nrf52840`
99-
# or `mps2_an521`. See more more target examples in micro_train.py and micro_tflite.py tutorials.
100-
target = tvm.target.target.micro("host")
102+
target = tvm.micro.testing.get_target(platform="crt", board=None)
101103

102104
# Use the C runtime (crt) and enable static linking by setting system-lib to True
103105
runtime = tvm.relay.backend.Runtime("crt", {"system-lib": True})

gallery/how_to/work_with_microtvm/micro_reference_vm.py

Lines changed: 0 additions & 159 deletions
This file was deleted.

0 commit comments

Comments
 (0)