2
2
3
3
# Setting up ExecuTorch
4
4
5
- This is a tutorial for building and installing ExecuTorch from the GitHub repository.
5
+ This is a tutorial for building and installing ExecuTorch from the GitHub
6
+ repository.
6
7
7
- ## AOT Setup [ (Open on Google Colab)] ( https://colab.research.google.com/drive/1m8iU4y7CRVelnnolK3ThS2l2gBo7QnAP#scrollTo=1o2t3LlYJQY5 )
8
+ ## Ahead-of-Time Setup [ (Open on Google Colab)] ( https://colab.research.google.com/drive/1m8iU4y7CRVelnnolK3ThS2l2gBo7QnAP#scrollTo=1o2t3LlYJQY5 )
8
9
9
10
This will install an ` executorch ` pip package to your conda environment and
10
11
allow you to export your PyTorch model to a flatbuffer file using ExecuTorch.
11
12
12
- ### Step 1: Set up a dev environment
13
+ ### Step 1: Clone the ExecuTorch repo
13
14
14
- To install conda, you can look at the
15
- [ conda installation guide] ( https://conda.io/projects/conda/en/latest/user-guide/install/index.html ) .
15
+ ``` bash
16
+ # Do one of these, depending on how your auth is set up
17
+ git clone https://github.com/pytorch/executorch.git
18
+ git clone
[email protected] :pytorch/executorch.git
19
+ ```
20
+
21
+ Ensure that git has fetched and updated the submodules. This is necessary
22
+ anytime commit hash of any of the submodules changes. Thus it is safe and
23
+ necessary at times to apply this step after you pull changes from upstream.
24
+
25
+ ``` bash
26
+ cd executorch
27
+ git submodule sync
28
+ git submodule update --init
29
+ ```
30
+
31
+ ### Step 2: Set up a dev environment
32
+
33
+ Install
34
+ [ Conda] ( https://conda.io/projects/conda/en/latest/user-guide/install/index.html )
35
+ and activate a new virtual environment:
16
36
17
37
``` bash
18
38
conda create -yn executorch python=3.10.0
19
39
conda activate executorch
40
+ ```
20
41
21
- conda install cmake
22
- conda install -c conda-forge flatbuffers
42
+ Or alternatively, activate a new Python virtual environment:
43
+
44
+ ``` bash
45
+ python3 -m venv .executorch
46
+ source .executorch/bin/activate
23
47
```
24
48
25
- ### Step 2: Clone the ` executorch ` repo
49
+ ### Step 3: Install [ Cmake ] ( https://cmake.org/download )
26
50
27
51
``` bash
28
- # Do one of these, depending on how your auth is set up
29
- git clone https://github.com/pytorch/executorch.git
30
- git clone
[email protected] :pytorch/executorch.git
52
+ conda install cmake
31
53
```
32
- Ensure that git has fetched and updated the submodules. This is necessary anytime
33
- commit hash of any of the submodules changes. Thus it is safe and necessary at times to apply this step after you pull changes from upstream.
54
+
55
+ Alternatively:
34
56
35
57
``` bash
36
- cd executorch
37
- git submodule sync
38
- git submodule update --init
58
+ pip install cmake
39
59
```
40
60
41
- ### Step 3 : Install ` executorch ` pip package and dependencies
61
+ ### Step 4 : Install ` executorch ` pip package and dependencies
42
62
43
63
Install all required python dependencies and PyTorch dependencies.
64
+
44
65
``` bash
45
- cd executorch
46
66
# Note: if you are behind a firewall an appropriate proxy server must be setup
47
67
# for all subsequent steps.
48
- bash ./install_requirements.sh
68
+ ./install_requirements.sh
49
69
```
50
70
51
71
When getting a new version of the executorch repo (via clone, fetch, or pull),
52
72
you may need to re-install a new version the PyTorch nightly pip package. The
53
73
` TORCH_VERSION ` value in this document will be the correct version for the
54
74
corresponsing version of the repo.
55
75
56
- ### Step 4: Generate a program file from an ` nn.Module `
76
+ ### Step 5: Expose FlatBuffers compiler
77
+
78
+ ExecuTorch uses ` flatc ` to export models and builds it from sources at
79
+ ` third-party/flatbuffers ` . Make it's available by referring in ` $PATH ` ,
80
+ as prompted by the previous step, or exporting as ` $FLATC_EXECUTABLE `
81
+ enironment variable.
82
+ Run ` ./build/install_flatc.sh ` to make sure ` flatc ` is installed correctly.
83
+
84
+ ## Testing Model Export
85
+
86
+ Generate a test program file from an ` nn.Module ` via Python script:
57
87
58
- Via python script:
59
88
``` bash
60
89
# Creates the file `add.pte`
61
90
python3 -m examples.portable.scripts.export --model_name=" add"
@@ -64,7 +93,8 @@ python3 -m examples.portable.scripts.export --model_name="add"
64
93
python3 -m examples.portable.scripts.export_and_delegate --option " composite"
65
94
```
66
95
67
- Or via python interpreter:
96
+ Or via Python interpreter:
97
+
68
98
``` python
69
99
$ python3
70
100
>> > import executorch.exir as exir
@@ -74,11 +104,14 @@ $ python3
74
104
>> > open (" mul.pte" , " wb" ).write(exir.capture(m, m.get_random_inputs()).to_edge().to_executorch().buffer)
75
105
```
76
106
77
- Please refer to the [ More Examples] ( ./00_setting_up_executorch.md#more-examples ) section for running with more popular models.
107
+ Please refer to the [ More Examples] ( ./00_setting_up_executorch.md#more-examples )
108
+ section for running with more popular models.
78
109
79
110
## Runtime Setup
80
111
81
- Follow [ AOT Setup: Step 2] ( ./00_setting_up_executorch.md#step-2-clone-the-executorch-repo ) above to clone the ` executorch ` repo if you haven't already.
112
+ Follow
113
+ [ Ahead-of-Time Setup: Step 1] ( ./00_setting_up_executorch.md#step-1-clone-the-executorch-repo )
114
+ above to clone the ` executorch ` repo if you haven't already.
82
115
83
116
### Step 1: Install buck2
84
117
@@ -87,7 +120,7 @@ Follow [AOT Setup: Step 2](./00_setting_up_executorch.md#step-2-clone-the-execut
87
120
- Decompress with the following command (filename depends on your system)
88
121
89
122
``` bash
90
- # For example, buck2-x86_64-unknown-linux-musl.zst
123
+ # For example, buck2-x86_64-unknown-linux-musl.zst or buck2-aarch64-apple-darwin.zst
91
124
zstd -cdq buck2-DOWNLOADED_FILENAME.zst > /tmp/buck2 && chmod +x /tmp/buck2
92
125
```
93
126
0 commit comments