You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Download tutorial-dependent datasets at build-time. (#71)
* Fetch tutorial-dependent datasets at build-time.
* Update docker entrypoint to support target build-choice when running
container [ci skip]
* Update README with additional tutorial building instructions [ci skip]
|`-D CUDA_V=(9.2 [Linux only]\|10.1\|10.2\|none)`|`none`| Download LibTorch for a CUDA version (`none` = download CPU version). |
99
-
|`-D DOWNLOAD_DATASETS=(OFF\|ON)`|`ON`| Download all datasets used in the tutorials. |
99
+
|`-D DOWNLOAD_DATASETS=(OFF\|ON)`|`ON`| Download required datasets during build (only if they do not already exist in `pytorch-cpp/data`). |
100
+
|`-D CREATE_SCRIPTMODULES=(OFF\|ON)`|`OFF`| Create all required scriptmodule files for prelearned models / weights during build. Requires installed python3 with pytorch and torchvision. |
100
101
|`-D CMAKE_PREFIX_PATH=path/to/libtorch/share/cmake/Torch`|`<empty>`| Skip the downloading of LibTorch and use your own local version (see [Requirements](#requirements)) instead. |
101
102
|`-D CMAKE_BUILD_TYPE=(Release\|Debug)`|`<empty>` (`Release` when downloading LibTorch on Windows) | Set the build type (`Release` = compile with optimizations).|
102
-
|`-D CREATE_SCRIPTMODULES=(OFF\|ON)`|`OFF`| Create all needed scriptmodule files for prelearned models / weights. Requires installed python3 with pytorch and torchvision. |
103
103
104
104
<details>
105
105
<summary><b>Example Linux</b></summary>
@@ -133,21 +133,45 @@ cmake -B build \
133
133
</details>
134
134
135
135
#### Build
136
+
>**_Note for Windows (Visual Studio) users:_** <br>
137
+
>The CMake script downloads the *Release* version of LibTorch, so `--config Release` has to be appended to the build command.
136
138
139
+
**How dataset download and scriptmodule creation work:**
140
+
* If `DOWNLOAD_DATASETS` is `ON`, the datasets required by the tutorials you choose to build will be downloaded to `pytorch-cpp/data` (if they do not already exist there).
141
+
* If `CREATE_SCRIPTMODULES` is `ON`, the scriptmodule files for the prelearned models / weights required by the tutorials you choose to build will be created in the `model` folder of the respective tutorial's source folder (if they do not already exist).
142
+
#### All tutorials
143
+
To build all tutorials use
137
144
```bash
138
145
cmake --build build
139
146
```
140
-
>**_Note for Windows users:_** <br>
141
-
>The CMake script downloads the *Release* version of LibTorch, so `--config Release` has to be appended to the build command.
142
-
>
143
-
>**_General Note:_** <br>
144
-
>By default all tutorials will be built. If you only want to build one specific tutorial, specify the `target` parameter for the build command. For example to only build the language model tutorial, append `--target language-model` (target name = tutorial foldername with all underscores replaced with hyphens).
147
+
148
+
#### All tutorials in a category
149
+
You can choose to only build tutorials in one of the categories `basics`, `intermediate`, `advanced` or `popular`. For example, if you are only interested in the `basics` tutorials:
150
+
```bash
151
+
cmake --build build --target basics
152
+
# In general: cmake --build build --target {category}
153
+
```
154
+
155
+
#### Single tutorial
156
+
You can also choose to only build a single tutorial. For example to build the language model tutorial only:
157
+
```bash
158
+
cmake --build build --target language-model
159
+
# In general: cmake --build build --target {tutorial-name}
160
+
```
161
+
>**_Note_**:
162
+
> The target argument is the tutorial's foldername with all underscores replaced by hyphens.
163
+
164
+
>**_Tip for users of CMake version >= 3.15_**:
165
+
> You can specify several targets separated by spaces, for example:
1. (**IMPORTANT!**) First change into the tutorial's directory within `build/tutorials`. For example, assuming you are in the `pytorch-cpp` directory and want to change to the pytorch basics tutorial folder:
148
172
```bash
149
173
cd build/tutorials/basics/pytorch_basics
150
-
# In general: cd build/tutorials/{basics|intermediate|advanced}/{tutorial_name}
174
+
# In general: cd build/tutorials/{basics|intermediate|advanced|popular/blitz}/{tutorial_name}
151
175
```
152
176
2. Run the executable. Note that the executable's name is the tutorial's foldername with all underscores replaced with hyphens (e.g. for tutorial folder: `pytorch_basics` -> executable name: `pytorch-basics` (or `pytorch-basics.exe` on Windows)). For example, to run the pytorch basics tutorial:<br><br>
153
177
**Linux/Mac**
@@ -176,13 +200,19 @@ You can build and run the tutorials (on CPU) in a Docker container using the pro
176
200
```bash
177
201
docker-compose run --rm pytorch-cpp
178
202
```
179
-
This fetches all necessary dependencies and builds the tutorials. After the build is done, by default the container starts `bash`in interactive mode in the `build/tutorials` folder.
180
-
As an alternative, you can also directly run a tutorial by instead invoking the above command with the tutorial as additional argument, for example:
203
+
This fetches all necessary dependencies and builds all tutorials.
204
+
After the build is done, by default the container starts `bash` in interactive mode in the `build/tutorials` folder.
205
+
As with the local build, you can choose to only build tutorials of a category (`basics`, `intermediate`, `advanced`, `popular`):
206
+
```bash
207
+
docker-compose run --rm pytorch-cpp {category}
208
+
```
209
+
In this case the container is started in the chosen category's base build directory.
210
+
Alternatively, you can also directly run a tutorial by instead invoking the run command with a tutorial name as additional argument, for example:
181
211
```bash
182
212
docker-compose run --rm pytorch-cpp pytorch-basics
183
213
# In general: docker-compose run --rm pytorch-cpp {tutorial-name}
184
214
```
185
-
This will - if necessary - build all tutorials and then start the provided tutorialin a container.
215
+
This will - if necessary - build the pytorch-basics tutorial and then start the executablein a container.
186
216
187
217
## License
188
218
This repository is licensed under MIT as given in [LICENSE](LICENSE).
0 commit comments