Skip to content

Commit d7198a4

Browse files
Merge pull request #1575 from annietllnd/tinyml-review
Update TinyML LP
2 parents 30cabba + 89645ca commit d7198a4

File tree

4 files changed

+70
-75
lines changed

4 files changed

+70
-75
lines changed

content/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/_index.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ learning_objectives:
1313
- Identify how TinyML is different from other AI domains.
1414
- Understand the benefits of deploying AI models on Arm-based edge devices.
1515
- Select Arm-based devices for TinyML.
16-
- Install and configure a TinyML development environment.
17-
- Apply best practices for ensuring optimal performance on constrained edge devices.
18-
16+
- Install and configure a TinyML development environment using ExecuTorch and the Corstone-320 FVP.
1917

2018
prerequisites:
2119
- Basic knowledge of machine learning concepts.

content/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/build-model-8.md

Lines changed: 51 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ weight: 7 # 1 is first, 2 is second, etc.
88
layout: "learningpathall"
99
---
1010

11+
## Define a small neural network using Python
12+
1113
With the development environment ready, you can create a simple PyTorch model to test the setup.
1214

1315
This example defines a small feedforward neural network for a classification task. The model consists of 2 linear layers with ReLU activation in between.
@@ -41,100 +43,85 @@ output_size = 2 # number of output classes
4143
model = SimpleNN(input_size, hidden_size, output_size)
4244

4345
# Example input tensor (batch size 1, input size 10)
44-
x = torch.randn(1, input_size)
45-
46-
# torch.export: Defines the program with the ATen operator set for SimpleNN.
47-
aten_dialect = export(model, (x,))
48-
49-
# to_edge: Make optimizations for edge devices. This ensures the model runs efficiently on constrained hardware.
50-
edge_program = to_edge(aten_dialect)
51-
52-
# to_executorch: Convert the graph to an ExecuTorch program
53-
executorch_program = edge_program.to_executorch()
46+
x = (torch.randn(1, input_size),)
5447

55-
# Save the compiled .pte program
56-
with open("simple_nn.pte", "wb") as file:
57-
file.write(executorch_program.buffer)
48+
# Add arguments to be parsed by the Ahead-of-Time (AoT) Arm compiler
49+
ModelUnderTest = model
50+
ModelInputs = x
5851

5952
print("Model successfully exported to simple_nn.pte")
6053
```
6154

62-
Run the model from the Linux command line:
55+
## Running the model on the Corstone-320 FVP
56+
57+
The final step is to take the Python-defined model and run it on the Corstone-320 FVP. This was done upon running the `run.sh` script in a previous section. To wrap up the Learning Path, you will perform these steps separately to better understand what happened under the hood. Start by setting some environment variables that are used by ExecuTorch.
6358

6459
```bash
65-
python3 simple_nn.py
60+
export ET_HOME=$HOME/executorch
61+
export executorch_DIR=$ET_HOME/build
6662
```
6763

68-
The output is:
64+
Then, generate a model file on the `.pte` format using the Arm examples. The Ahead-of-Time (AoT) Arm compiler will enable optimizations for devices like the Grove Vision AI Module V2 and the Corstone-320 FVP. Run it from the ExecuTorch root directory.
6965

70-
```output
71-
Model successfully exported to simple_nn.pte
66+
```bash
67+
cd $ET_HOME
68+
python -m examples.arm.aot_arm_compiler --model_name=examples/arm/simple_nn.py \
69+
--delegate --quantize --target=ethos-u85-256 \
70+
--so_library=cmake-out-aot-lib/kernels/quantized/libquantized_ops_aot_lib.so \
71+
--system_config=Ethos_U85_SYS_DRAM_Mid --memory_mode=Sram_Only
7272
```
7373

74-
The model is saved as a .pte file, which is the format used by ExecuTorch for deploying models to the edge.
75-
76-
Run the ExecuTorch version, first build the executable:
74+
From the Arm Examples directory, you build an embedded Arm runner with the `.pte` included. This allows you to get the most performance out of your model, and ensures compatibility with the CPU kernels on the FVP. Finally, generate the executable `arm_executor_runner`.
7775

7876
```bash
79-
# Clean and configure the build system
80-
(rm -rf cmake-out && mkdir cmake-out && cd cmake-out && cmake ..)
81-
82-
# Build the executor_runner target
83-
cmake --build cmake-out --target executor_runner -j$(nproc)
84-
```
77+
cd $HOME/executorch/examples/arm/executor_runner
8578

86-
You will see the build output and it ends with:
8779

88-
```output
89-
[100%] Linking CXX executable executor_runner
90-
[100%] Built target executor_runner
91-
```
80+
cmake -DCMAKE_BUILD_TYPE=Release \
81+
-DCMAKE_TOOLCHAIN_FILE=$ET_HOME/examples/arm/ethos-u-setup/arm-none-eabi-gcc.cmake \
82+
-DTARGET_CPU=cortex-m85 \
83+
-DET_DIR_PATH:PATH=$ET_HOME/ \
84+
-DET_BUILD_DIR_PATH:PATH=$ET_HOME/cmake-out \
85+
-DET_PTE_FILE_PATH:PATH=$ET_HOME/simple_nn_arm_delegate_ethos-u85-256.pte \
86+
-DETHOS_SDK_PATH:PATH=$ET_HOME/examples/arm/ethos-u-scratch/ethos-u \
87+
-DETHOSU_TARGET_NPU_CONFIG=ethos-u85-256 \
88+
-DPYTHON_EXECUTABLE=$HOME/executorch-venv/bin/python3 \
89+
-DSYSTEM_CONFIG=Ethos_U85_SYS_DRAM_Mid \
90+
-B $ET_HOME/examples/arm/executor_runner/cmake-out
9291

93-
When the build is complete, run the executor_runner with the model as an argument:
92+
cmake --build $ET_HOME/examples/arm/executor_runner/cmake-out --parallel -- arm_executor_runner
9493

95-
```bash
96-
./cmake-out/executor_runner --model_path simple_nn.pte
9794
```
9895

99-
Since the model is a simple feedforward model, you see a tensor of shape [1, 2]
96+
Now run the model on the Corstone-320 with the following command.
10097

101-
```output
102-
I 00:00:00.006598 executorch:executor_runner.cpp:73] Model file simple_nn.pte is loaded.
103-
I 00:00:00.006628 executorch:executor_runner.cpp:82] Using method forward
104-
I 00:00:00.006635 executorch:executor_runner.cpp:129] Setting up planned buffer 0, size 320.
105-
I 00:00:00.007225 executorch:executor_runner.cpp:152] Method loaded.
106-
I 00:00:00.007237 executorch:executor_runner.cpp:162] Inputs prepared.
107-
I 00:00:00.012885 executorch:executor_runner.cpp:171] Model executed successfully.
108-
I 00:00:00.012896 executorch:executor_runner.cpp:175] 1 outputs:
109-
Output 0: tensor(sizes=[1, 2], [-0.105369, -0.178723])
98+
```bash
99+
FVP_Corstone_SSE-320 \
100+
-C mps4_board.subsystem.ethosu.num_macs=256 \
101+
-C mps4_board.visualisation.disable-visualisation=1 \
102+
-C vis_hdlcd.disable_visualisation=1 \
103+
-C mps4_board.telnetterminal0.start_telnet=0 \
104+
-C mps4_board.uart0.out_file='-' \
105+
-C mps4_board.uart0.shutdown_on_eot=1 \
106+
-a "$ET_HOME/examples/arm/executor_runner/cmake-out/arm_executor_runner"
110107
```
111108

112-
When the model execution completes successfully, you’ll see confirmation messages similar to those above, indicating successful loading, inference, and output tensor shapes.
113-
114-
115-
116-
TODO: Debug issues when running the model on the FVP, kindly ignore anything below this
117-
## Running the model on the Corstone-300 FVP
118-
119109

120-
Run the model using:
121-
122-
```bash
123-
FVP_Corstone_SSE-300_Ethos-U55 -a simple_nn.pte -C mps3_board.visualisation.disable-visualisation=1
124-
```
125110

126111
{{% notice Note %}}
127112

128-
-C mps3_board.visualisation.disable-visualisation=1 disables the FVP GUI. This can speed up launch time for the FVP.
113+
The argument `mps4_board.visualisation.disable-visualisation=1` disables the FVP GUI. This can speed up launch time for the FVP.
129114

130-
The FVP can be terminated with Ctrl+C.
131115
{{% /notice %}}
132116

133-
134-
117+
Observe that the FVP loads the model file.
135118
```output
136-
119+
telnetterminal0: Listening for serial connection on port 5000
120+
telnetterminal1: Listening for serial connection on port 5001
121+
telnetterminal2: Listening for serial connection on port 5002
122+
telnetterminal5: Listening for serial connection on port 5003
123+
I [executorch:arm_executor_runner.cpp:412] Model in 0x70000000 $
124+
I [executorch:arm_executor_runner.cpp:414] Model PTE file loaded. Size: 3360 bytes.
137125
```
138126

139-
140-
You've now set up your environment for TinyML development, and tested a PyTorch and ExecuTorch Neural Network.
127+
You've now set up your environment for TinyML development on Arm, and tested a small PyTorch and ExecuTorch Neural Network.

content/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/env-setup-5.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Run the commands below to set up the ExecuTorch internal dependencies.
4646
git submodule sync
4747
git submodule update --init
4848
./install_requirements.sh
49+
./install_executorch.sh
4950
```
5051

5152
{{% notice Note %}}
@@ -57,6 +58,16 @@ pkill -f buck
5758
```
5859
{{% /notice %}}
5960

61+
After running the commands, `executorch` should be listed upon running `pip list`:
62+
63+
```bash
64+
pip list | grep executorch
65+
```
66+
67+
```output
68+
executorch 0.6.0a0+3eea1f1
69+
```
70+
6071
## Next Steps
6172

6273
Your next steps depends on the hardware you have.

content/learning-paths/embedded-and-microcontrollers/introduction-to-tinyml-on-arm/env-setup-6-FVP.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,32 @@
11
---
22
# User change
3-
title: "Set up the Corstone-300 FVP"
3+
title: "Set up the Corstone-320 FVP"
44

55
weight: 5 # 1 is first, 2 is second, etc.
66

77
# Do not modify these elements
88
layout: "learningpathall"
99
---
1010

11-
## Corstone-300 FVP Setup for ExecuTorch
11+
## Corstone-320 FVP Setup for ExecuTorch
1212

13-
Navigate to the Arm examples directory in the ExecuTorch repository and configure the Fixed Virtual Platform (FVP).
13+
Navigate to the Arm examples directory in the ExecuTorch repository.
1414

1515
```bash
1616
cd $HOME/executorch/examples/arm
1717
./setup.sh --i-agree-to-the-contained-eula
1818
```
1919

20-
Set the environment variables for the FVP.
20+
After the script has finished running, it prints a command to run to finalize the installation. This will add the FVP executable's to your path.
2121

2222
```bash
23-
export FVP_PATH=${pwd}/ethos-u-scratch/FVP-corstone300/models/Linux64_GCC-9.3
24-
export PATH=$FVP_PATH:$PATH
23+
source $HOME/executorch/examples/arm/ethos-u-scratch/setup_path.sh
2524
```
2625

27-
Confirm the installation was successful by running the `run.sh` script.
26+
Test that the setup was successful by running the `run.sh` script for Ethos-U85, which is the target device for Corstone-320.
2827

2928
```bash
30-
./run.sh
29+
./examples/arm/run.sh --target=ethos-u85-256
3130
```
3231

3332
You will see a number of examples run on the FVP.

0 commit comments

Comments
 (0)