Skip to content

Commit a486a92

Browse files
shoumikhinfacebook-github-bot
authored andcommitted
Update the Setting Up tutorial. (#728)
Summary: Pull Request resolved: #728 Swap repo checkout and dev env setup, provide vanilla Python venvs as an alternative to Conda, etc. to make the steps friendlier on macOS. Differential Revision: https://internalfb.com/D50090516 fbshipit-source-id: 33c444aae2ee7c93746848fcd191ae1d283bcc6b
1 parent 81a302a commit a486a92

File tree

2 files changed

+105
-37
lines changed

2 files changed

+105
-37
lines changed

docs/source/getting-started-setup.md

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,23 @@ the required dependencies.
5555

5656
Follow these steps:
5757

58-
1. If you do not have it already, install conda on your machine by following
59-
the steps in the [conda installation guide](https://conda.io/projects/conda/en/latest/user-guide/install/index.html).
58+
1. If you do not have it already, install conda on your machine by following the
59+
steps in the
60+
[conda installation guide](https://conda.io/projects/conda/en/latest/user-guide/install/index.html).
61+
62+
1. Clone the `executorch` repository:
63+
64+
```bash
65+
git clone [email protected]:pytorch/executorch.git
66+
```
67+
68+
1. Update the submodules:
69+
70+
```bash
71+
cd executorch
72+
git submodule sync
73+
git submodule update --init
74+
```
6075

6176
1. Create and activate your conda environment:
6277

@@ -65,26 +80,39 @@ the steps in the [conda installation guide](https://conda.io/projects/conda/en/l
6580
conda activate executorch
6681
```
6782

68-
1. Clone the `executorch` repository:
83+
Or alternatively use a Python virtual environment:
6984

7085
```bash
71-
git clone [email protected]:pytorch/executorch.git
86+
python3 -m venv .executorch
87+
source .executorch/bin/activate
7288
```
7389

74-
1. Update the submodules:
90+
1. Install [Cmake](https://cmake.org/download)
7591

7692
```bash
77-
cd executorch
78-
git submodule sync
79-
git submodule update --init
93+
conda install cmake
94+
```
95+
96+
Alternatively:
97+
98+
```bash
99+
pip install cmake
80100
```
81101

82102
1. Install ExecuTorch and dependencies:
83103

84104
```bash
85-
bash ./install_requirements.sh
105+
./install_requirements.sh
86106
```
87107

108+
1. Expose FlatBuffers compiler:
109+
110+
ExecuTorch uses `flatc` to export models and builds it from sources at
111+
`third-party/flatbuffers`. Make it's available by referring in `$PATH`,
112+
as prompted by the previous step, or exporting as `$FLATC_EXECUTABLE`
113+
enironment variable.
114+
Run `./build/install_flatc.sh` to make sure `flatc` is installed correctly.
115+
88116
You have successfully set up your environment to work with ExecuTorch. The next
89117
step is to generate a sample ExecuTorch program.
90118

@@ -178,18 +206,25 @@ Complete the following steps:
178206
git submodule update --init
179207
```
180208

181-
2. Configure Buck2 by decompressing with the following command (filename depends
209+
1. Install ExecuTorch and dependencies:
210+
211+
```bash
212+
./install_requirements.sh
213+
```
214+
215+
1. Configure Buck2 by decompressing with the following command (filename depends
182216
on your system):
183217

184218
```bash
185-
# For example, buck2-x86_64-unknown-linux-musl.zst
219+
# For example, buck2-x86_64-unknown-linux-musl.zst or buck2-aarch64-apple-darwin.zst
186220
zstd -cdq buck2-DOWNLOADED_FILENAME.zst > /tmp/buck2 && chmod +x /tmp/buck2
187221
```
188222

189223
You may want to copy the `buck2` binary into your `$PATH` so you can run it
190224
as `buck2`.
191225

192-
3. Build a binary:
226+
1. Build a binary:
227+
193228
```bash
194229
/tmp/buck2 build //examples/portable/executor_runner:executor_runner --show-output
195230
```

docs/website/docs/tutorials/00_setting_up_executorch.md

Lines changed: 58 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,89 @@
22

33
# Setting up ExecuTorch
44

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.
67

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)
89

910
This will install an `executorch` pip package to your conda environment and
1011
allow you to export your PyTorch model to a flatbuffer file using ExecuTorch.
1112

12-
### Step 1: Set up a dev environment
13+
### Step 1: Clone the ExecuTorch repo
1314

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:
1636

1737
```bash
1838
conda create -yn executorch python=3.10.0
1939
conda activate executorch
40+
```
2041

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
2347
```
2448

25-
### Step 2: Clone the `executorch` repo
49+
### Step 3: Install [Cmake](https://cmake.org/download)
2650

2751
```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
3153
```
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:
3456

3557
```bash
36-
cd executorch
37-
git submodule sync
38-
git submodule update --init
58+
pip install cmake
3959
```
4060

41-
### Step 3: Install `executorch` pip package and dependencies
61+
### Step 4: Install `executorch` pip package and dependencies
4262

4363
Install all required python dependencies and PyTorch dependencies.
64+
4465
```bash
45-
cd executorch
4666
# Note: if you are behind a firewall an appropriate proxy server must be setup
4767
# for all subsequent steps.
48-
bash ./install_requirements.sh
68+
./install_requirements.sh
4969
```
5070

5171
When getting a new version of the executorch repo (via clone, fetch, or pull),
5272
you may need to re-install a new version the PyTorch nightly pip package. The
5373
`TORCH_VERSION` value in this document will be the correct version for the
5474
corresponsing version of the repo.
5575

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:
5787

58-
Via python script:
5988
```bash
6089
# Creates the file `add.pte`
6190
python3 -m examples.portable.scripts.export --model_name="add"
@@ -64,7 +93,8 @@ python3 -m examples.portable.scripts.export --model_name="add"
6493
python3 -m examples.portable.scripts.export_and_delegate --option "composite"
6594
```
6695

67-
Or via python interpreter:
96+
Or via Python interpreter:
97+
6898
```python
6999
$ python3
70100
>>> import executorch.exir as exir
@@ -74,11 +104,14 @@ $ python3
74104
>>> open("mul.pte", "wb").write(exir.capture(m, m.get_random_inputs()).to_edge().to_executorch().buffer)
75105
```
76106

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.
78109

79110
## Runtime Setup
80111

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.
82115

83116
### Step 1: Install buck2
84117

@@ -87,7 +120,7 @@ Follow [AOT Setup: Step 2](./00_setting_up_executorch.md#step-2-clone-the-execut
87120
- Decompress with the following command (filename depends on your system)
88121

89122
```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
91124
zstd -cdq buck2-DOWNLOADED_FILENAME.zst > /tmp/buck2 && chmod +x /tmp/buck2
92125
```
93126

0 commit comments

Comments
 (0)