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
Copy file name to clipboardExpand all lines: README.md
+82-27Lines changed: 82 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -36,57 +36,100 @@ Checklist for creating the repository:
36
36
37
37
## Working with the template:
38
38
39
-
The template assumes working within a Docker container. Non-container use is possible but not recommended.
39
+
The template assumes working within containers. Non-container development is possible but not recommended.
40
40
41
41
### Option 1: Codespaces
42
42
43
43
Repositories generated from the template are development-ready with [GitHub Codespaces](https://docs.github.com/en/codespaces/overview).
44
44
45
-
Codespaces builds a container according to `.devcontainer/devcontainer.json` and attaches to it in `vsc` mode (see 'Running the container' below).
45
+
Codespaces builds a container according to settings in `.devcontainer/devcontainer.json` and attaches to it in `vsc` mode (see 'Running the container' below).
46
46
47
47
Just launch your repository in a Codespace and start working.
48
48
49
49
### Option 2: Local
50
50
51
-
Clone the repository, and run the container (see 'Running the container' below).
52
51
53
-
## Running the container
52
+
Begin by selecting your tools. Here are two examples for local development: Podman + JupyterLab (recommended), and Docker + VSC (*Visual Studio Code*).
54
53
55
-
The template container has three modes: two for development `vsc` (default) and `jupyterlab`, and `api` for running the API. The mode is given to Docker as an environment variable `MODE`.
54
+
The template container has three modes: two for development `vsc` (default) and `jupyterlab`, and `api` for running the API. The mode is given an environment variable `MODE` when running the container.
56
55
57
-
### Visual Studio Code (VSC):
56
+
*Podman + JupyterLab*
58
57
59
-
Install VSC and Dev Containers Extension. When you open your repository in VSC, it automatically detects `.devcontainer/devcontianer.json` and suggests opening the repository in a container. Alternatively, press `cmd/ctrl shift P`, type `Remote-Container: Rebuild and Reopen in Container` and press enter. VSC builds the container and attaches to it.
58
+
Podman is an open source container runtime tool, that can also operate Docker containers, and shares most of the syntax with Docker. While it is possible to configure VSC Dev Container or VSC Remote Container to use Podman or other open source container framework (see instructions with [minikube](https://benmatselby.dev/post/vscode-dev-containers-minikube/) or [Podman desktop](https://developers.redhat.com/articles/2023/02/14/remote-container-development-vs-code-and-podman#)), this requires some effort compared to Docker with Docker Desktop. In addition, third party Docker extensions may not work. Therefore, it is recommended to develop locally with Jupyterlab, which comes installed within the template container.
60
59
61
-
### JupyterLab:
60
+
```bash
61
+
# On MacOS
62
62
63
-
The template installs JupyterLab within the container. To work in JupyterLab, run the container with `MODE=jupyterlab docker-compose up`. The container starts JupyterLab. To access jupyterlab, copy the address from the terminal to your browser.
63
+
# Install podman, docker and hyperkit
64
+
# These are the only requirements for your system -
65
+
# everything else, including python and it's packages
66
+
# are installed within the container!
64
67
65
-
### Working offline with JupyterLab:
68
+
$ brew install hyperkit
69
+
$ brew install docker docker-compose
70
+
$ brew install podman podman-compose
71
+
$ brew install podman-desktop
72
+
73
+
# Init podman machine and allocate resources
74
+
# NOTE: edit the allocation according to your needs.
75
+
# You may well run out of memory with this default setup.
76
+
$ podman machine init --cpus=2 --memory=4096
66
77
67
-
The repository allows developing and running ML models completely offline.
78
+
# Start podman machine
79
+
$ podman machine start
68
80
69
-
Steps to offline install:
81
+
# Build container
82
+
$ cd your_repo
83
+
$ podman-compose build
70
84
71
-
0. Clone your repo on a network connected device or use codespaces.
72
-
1. Add required python packages to `requirements/requirements.in`. Try to include all packages you might require, because adding them later without internet access is rather difficult.
73
-
2. Build the image, and within the `requirements` folder run the script `./update_requirements.sh`.
74
-
3. Rebuild the image.
75
-
4. Pull the image and transfer it to the offline device. The offline device must have Docker installed.
76
-
5. Start container in the `jupyterlab` mode (see above).
85
+
# Start dev container with JupyterLab
86
+
$ MODE=jupyterlab podman-compose up
77
87
78
-
The API works offline, too, but requires network access for external clients.
88
+
# To stop the dev container
89
+
# (in another terminal window or tab)
90
+
$ cd your_repo
91
+
$ podman-compose down
92
+
93
+
# To stop podman
94
+
$ podman machine stop
95
+
```
96
+
97
+
Check out [Podman docs](https://docs.podman.io/en/latest/index.html) for more information and instructions.
98
+
99
+
*Docker Desktop + Visual Studio Code*
100
+
101
+
[Docker Desktop](https://www.docker.com/) is an open core tool for managing Docker containers. Please note that most non-personal use of Docker Desktop now requires paid license subscription.
102
+
103
+
To use the template with docker desktop, install and start docker desktop according to the instructions. VSC Extensions work with Docker Desctop with default settings.
104
+
105
+
Visual Studio Code is an IDE that supports container development. Install VSC and Dev Containers Extension. When you open your repository in VSC, it automatically detects `.devcontainer/devcontianer.json` and suggests opening the repository in a container. Alternatively, press `cmd/ctrl shift P`, type `Remote-Container: Rebuild and Reopen in Container` and press enter. VSC builds the container and attaches to it.
79
106
80
107
### Running the API:
81
108
82
-
To start the API as the container entrypoint, run `MODE=api docker-compose up`. This loads the latest trained model from model store, starts the API and leaves the container running. The API requires an existing model store and a stored model to function.
109
+
To start the API as the container entrypoint, run
110
+
`MODE=api podman-compose up` or `MODE=api docker-compose up` This loads the latest trained model from model store, starts the API and leaves the container running. The API requires an existing model store and a stored model to function.
83
111
84
112
> NOTE: To launch container in `api` mode, you must first train a model and save it to model store on a persistent volume or mapping, i.e. change the `local_data` volume type in compose and rebuild the container. To avoid accidentaly leaking sensitive data, model stores are by default saved to `tmpfs` storage that is removed every time the container is stopped. The `api` mode will not work without changing this setup.
85
113
86
114
To develop interactively with the API running, you may start the API from within your VSC / jupyterlab terminal by running `uvicorn main:app --reload --reload-include *.pickle --host 0.0.0.0` within the API folder of the container. This does not require changing the volume types.
87
115
88
116
To specify model store and model version to load, use environment variables as specified in `api/app_base.py`. The default option loads latest model from pickle store.
89
117
118
+
### Working offline:
119
+
120
+
The repository allows developing and running ML models completely offline.
121
+
122
+
Steps to offline install:
123
+
124
+
0. Clone your repo on a network connected device or use codespaces.
125
+
1. Add required python packages to `requirements/requirements.in`. Try to include all packages you might require, because adding them later without internet access is rather difficult.
126
+
2. Build the image, and within the `requirements` folder run the script `./update_requirements.sh`.
127
+
3. Rebuild the image.
128
+
4. Pull the image and transfer it to the offline device with Podman requirements installed.
129
+
5. Start container in the `jupyterlab` mode with your choice of container tools.
130
+
131
+
The API works offline, too, but requires network access for external clients.
132
+
90
133
## Examples
91
134
92
135
The `examples/` folder contains simplified single-notebook examples on how to create, train, evaluate and deploy a ML model to model store. There are two notebooks due to two alternatives for the model store. You can try out the API by:
@@ -97,6 +140,8 @@ The `examples/` folder contains simplified single-notebook examples on how to cr
97
140
3. Automatically generated online API documentation is available at: http://127.0.0.1:8000/docs
98
141
4. Real time metrics are available at: http://127.0.0.1:8000/metrics and at the built-in example Prometheus server at http://127.0.0.1:9090
99
142
143
+
> NOTE: if working in Codespaces, right-click the localhost links from README to access the port-forwarded endpoints!
144
+
100
145
The following API request calls for the example model to make a prediction on two new data points:
101
146
102
147
curl -X 'POST' \
@@ -131,7 +176,7 @@ To update `requirements.txt`, run script `./update_requirements.sh` INSIDE the `
131
176
Install new requirements with `pip install -r requirements/requirements.txt` or by rebuilding the container.
132
177
133
178
The template installs python 3.10 (Ubuntu default).
134
-
To specify another python version, edit the dockerfile to set up a virtual environment. The template is tested with python 3.10, but is expected to work with 3.8 and newer. However, other versions may require additional configuration.
179
+
To specify another python version, edit Dockerfile to set up a virtual environment. The template is tested with python 3.10, but is expected to work with 3.8 and newer. However, other versions may require additional configuration.
135
180
136
181
## ML Pipeline
137
182
@@ -238,18 +283,28 @@ The template comes with an 'ethical issue template' found in `.github/ISSUE_TEMP
238
283
239
284
The template was developed and tested with:
240
285
241
-
- GitHub Codespaces
286
+
GitHub Codespaces
287
+
288
+
and MacBook Pro M1 & macOS Ventura 13.2.1 with:
289
+
290
+
Docker desktop 4.15.0 (93002)
291
+
VSC 1.74.0
292
+
VSC Dev Containers Extension v0.245.2
242
293
243
-
and MacBook Pro M1 & macOS Ventura 13.0 with:
294
+
and MacBook Pro M1 & macOS Ventura 13.2.1 with:
244
295
245
-
- Docker desktop 4.15.0 (93002)
246
-
- VSC 1.74.0
247
-
- VSC Dev Containers Extension v0.245.2
296
+
podman-desktop 1.1.0
297
+
hyperkit 0.20210107
298
+
podman 4.5.1
299
+
podman-compose 1.0.6
300
+
docker 24.0.2
301
+
docker-compose 2.18.1
248
302
249
303
Additional configuration may be required for other systems.
250
304
251
305
## Known issues
252
306
253
307
- nbdev_clean git hook may remove 'parameters' tag from notebook cells, even though it should be an allowed key as it is listed in settings.ini. The tag may need to be re-added manually to allow notebook parameterization with papermill.
254
-
- nbdev documentation related functions may not work out-of-box with arm64 machines such as M1 macbooks because the container installs amd64 version of Quarto. You can bypass this by setting `platform` option for docker. However, this makes container build SUPER slow and is thus not a default setting.
308
+
- nbdev documentation related functions may not work out-of-box with arm64 machines such as M1 macbooks because the container installs amd64 version of Quarto. You can bypass this by setting `platform` option for Docker. However, this makes container build SUPER slow and is thus not a default setting.
255
309
- Source code (git) and model instance version may mismatch if code changes are not committed before updating a model to the model store.
310
+
- Is podman not responding? See [this discussion](https://github.com/containers/podman/issues/16054) for possible solutions.
0 commit comments