|
| 1 | +# Examples |
| 2 | + |
| 3 | +This dir contains scripts and other helper utilities to illustrate an end-to-end workflow to run a torch.nn.module on the Executorch runtime. |
| 4 | +It also includes a list of modules, from a simple `Add` to a full model like `MobileNetv2` and `MobileNetv3`, with more to come. |
| 5 | + |
| 6 | + |
| 7 | +## Directory structure |
| 8 | +```bash |
| 9 | +examples |
| 10 | +├── executor_runner # This is an example C++ wrapper around the ET runtime |
| 11 | +├── export # Python helper scripts to illustrate export workflow |
| 12 | +├── models # Contains a set of simple to PyTorch models |
| 13 | +└── README.md # This file |
| 14 | +``` |
| 15 | + |
| 16 | +## Using the examples |
| 17 | + |
| 18 | +We will walk through an example model to generate a binary file from a python torch.nn.module |
| 19 | +from the `models` dir using scripts from the `export` dir. Then we will run on these binary |
| 20 | +model files on the Executorch (ET) runtime. For that we will use `executor_runner`. It is a simple |
| 21 | +wrapper for the Executorch runtime to serve as an example. Although simple, it is capable of loading |
| 22 | +and executing previously exported binary file(s). |
| 23 | + |
| 24 | + |
| 25 | +1. Following the setup guide in [Setting up ExecuTorch from GitHub](/docs/website/docs/tutorials/00_setting_up_executorch.md) |
| 26 | +you should be able to get the basic development environment for Executorch working. |
| 27 | + |
| 28 | +2. Using the script `export/export_example.py` generate a model binary file by selecting a |
| 29 | +model name from the list of available models in the `models` dir. |
| 30 | + |
| 31 | + |
| 32 | +```bash |
| 33 | +cd executorch # To the top level dir |
| 34 | + |
| 35 | +bash examples/install_requirements.sh |
| 36 | + |
| 37 | +python3 -m examples.export.export_example --model_name="mv2" # for MobileNetv2 |
| 38 | + |
| 39 | +# This should generate ./mv2.ff file, if successful. |
| 40 | +``` |
| 41 | + |
| 42 | +3. Once we have the model binary (ff) file, then let's run it with Executorch runtime using the `executor_runner`. |
| 43 | + |
| 44 | +```bash |
| 45 | +buck2 run examples/executor_runner:executor_runner -- --model_path mv2.ff |
| 46 | +``` |
| 47 | + |
| 48 | +For MobileNetv3, change the model name and the corrosponding binary filename from "mv2" to "mv3". |
| 49 | + |
1 | 50 | ## Dependencies
|
2 | 51 |
|
3 | 52 | Various models listed in this directory have dependencies on some other packages, e.g. torchvision, torchaudio.
|
4 | 53 | In order to make sure model's listed in examples are importable, e.g. via
|
5 |
| -``` |
| 54 | + |
| 55 | +```python |
6 | 56 | from executorch.examples.models.mobilenet_v3d import MV3Model
|
7 | 57 | m = MV3Model.get_model()
|
8 | 58 | ```
|
9 |
| -we need to have appropriate packages installed. You should install these deps via install_requirements.sh |
| 59 | +we need to have appropriate packages installed. You should install these deps via install_requirements.sh. |
0 commit comments