Skip to content

Commit 2cdeaf6

Browse files
committed
chore: add pytorch base image dockerfiles
1 parent 1bd5176 commit 2cdeaf6

File tree

7 files changed

+178
-0
lines changed

7 files changed

+178
-0
lines changed

deploy/bases/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Guide for building multi-arch docker images
2+
3+
The Dockerfiles contained in the subdirectories build small-ish (~1Gi)
4+
base images that helps with some common PyTorch scenarios.
5+
6+
- `lightning`: 827Mi
7+
- `pyarrow`: 1.01Gi (183Mi delta over `lightning`)
8+
- `transformers`: 1.09Gi (8Mi delta over `pyarrow`)
9+
10+
## Creating a `docker buildx` build config
11+
12+
To build for both amd64 and aarch4 (e.g. for running on Apple
13+
Silicon), you can use `docker buildx`.
14+
15+
First, you will need to create a buildx config, because the default
16+
one does not seem to work well for cross-platform builds. Here we name
17+
that config `multiarch`, but it can be named anything.
18+
19+
We have found that using the `kubernetes` driver works better than the
20+
default `docker-container` driver.
21+
22+
```shell
23+
docker buildx create --name multiarch --use --driver kubernetes --driver-opt=qemu.install=true
24+
```
25+
26+
The `--use` part tells buildx to set this as the default builder.
27+
28+
_Note_: We tell docker buildx to use qemu, so that the amd64 images
29+
can be built on an aarch64 host.
30+
31+
_Warning_: If your KUBECONFIG env var is colon-separated, this is
32+
something that `docker buildx` apparently does not support. You will
33+
need to run any `docker buildx` commands with
34+
e.g. `KUBECONFIG=~/.kube/config`, i.e. pointing it to a single
35+
filepath.
36+
37+
## Starting a build
38+
39+
Now you should be able to build and push:
40+
41+
```shell
42+
# whatever you need here, but note that the Dockerfiles
43+
# may need to change, as you update these image names and tags
44+
TAG=ghcr.io/project-codeflare/lightning:0.0.5
45+
46+
# build for aarch64 (arm64/v8) and amd64
47+
PLATFORMS=linux/arm64/v8,linux/amd64
48+
49+
# note here that we build and push in one step; for some reason,
50+
# buildx fails when only building
51+
docker buildx build --push --platforms $PLATFORMS --tag $TAG .
52+
```

deploy/bases/lightning/Dockerfile

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
FROM ubuntu:20.04
2+
3+
ARG PYTHON_VERSION=39
4+
ARG CONDA_VERSION=4.9.2
5+
ARG TARGETARCH
6+
7+
ENV \
8+
DEBIAN_FRONTEND="noninteractive" \
9+
CONDA_ENV="lightning" \
10+
PATH="/root/miniconda3/bin:$PATH" \
11+
LD_LIBRARY_PATH="/root/miniconda3/lib:$LD_LIBRARY_PATH"
12+
13+
COPY requirements.txt requirements.txt
14+
15+
RUN echo "TARGETARCH=$TARGETARCH" && \
16+
if [ "$TARGETARCH" = "arm64" ]; then TARGETARCH="aarch64"; else TARGETARCH="x86_64"; fi && \
17+
echo "TARGETARCH=$TARGETARCH" && \
18+
apt-get update -qq --fix-missing && \
19+
apt-get install -y --no-install-recommends \
20+
build-essential \
21+
ca-certificates \
22+
cmake \
23+
curl \
24+
git \
25+
jq \
26+
libopenmpi-dev \
27+
unzip \
28+
wget \
29+
&& \
30+
# Install conda and python.
31+
# NOTE new Conda does not forward the exit status... https://github.com/conda/conda/issues/8385
32+
curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-py${PYTHON_VERSION}_${CONDA_VERSION}-Linux-${TARGETARCH}.sh && \
33+
chmod +x ~/miniconda.sh && \
34+
~/miniconda.sh -b && \
35+
rm ~/miniconda.sh && \
36+
pip install -r requirements.txt && \
37+
# Cleaning
38+
apt-get remove -y \
39+
build-essential \
40+
ca-certificates \
41+
cmake \
42+
curl \
43+
git \
44+
jq \
45+
libopenmpi-dev \
46+
unzip \
47+
wget && \
48+
apt-get autoremove -y && \
49+
apt-get clean && \
50+
rm -rf /root/.cache && \
51+
rm -rf /var/lib/apt/lists/* && \
52+
chgrp -R 0 /root && \
53+
chmod -R g+rwX /root
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
numpy>=1.17.2
2+
torch>=1.11.0
3+
pytorch-lightning>=2.0.0
4+
future>=0.17.1
5+
PyYAML>=5.1
6+
tqdm>=4.57.0
7+
fsspec[http]>=2021.06.1
8+
9+
# Examples
10+
torchvision>=0.12.0

deploy/bases/pyarrow/Dockerfile

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM ghcr.io/project-codeflare/lightning:0.0.5
2+
3+
ENV \
4+
DEBIAN_FRONTEND="noninteractive" \
5+
CONDA_ENV="lightning" \
6+
PATH="/root/miniconda3/bin:$PATH" \
7+
LD_LIBRARY_PATH="/root/miniconda3/lib:$LD_LIBRARY_PATH"
8+
9+
COPY requirements.txt requirements.txt
10+
11+
RUN unset LD_LIBRARY_PATH && \
12+
apt-get update -qq --fix-missing && \
13+
apt-get install -y --no-install-recommends \
14+
build-essential \
15+
ca-certificates \
16+
cmake && \
17+
pip install -r requirements.txt && \
18+
# Cleaning
19+
apt-get remove -y \
20+
build-essential \
21+
ca-certificates \
22+
cmake && \
23+
apt-get autoremove -y && \
24+
apt-get clean && \
25+
rm -rf /root/.cache && \
26+
rm -rf /var/lib/apt/lists/* && \
27+
chgrp -R 0 /root && \
28+
chmod -R g+rwX /root
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pyarrow
2+
pandas
3+
ibm-cos-sdk
4+
5+
# helpful and small utilities
6+
psutil
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
FROM ghcr.io/project-codeflare/pyarrow:0.0.4
2+
3+
ENV \
4+
DEBIAN_FRONTEND="noninteractive" \
5+
CONDA_ENV="lightning" \
6+
PATH="/root/miniconda3/bin:$PATH" \
7+
LD_LIBRARY_PATH="/root/miniconda3/lib:$LD_LIBRARY_PATH"
8+
9+
COPY requirements.txt requirements.txt
10+
11+
RUN unset LD_LIBRARY_PATH && \
12+
apt-get update -qq --fix-missing && \
13+
apt-get install -y --no-install-recommends \
14+
build-essential \
15+
ca-certificates \
16+
cmake && \
17+
pip install -r requirements.txt && \
18+
# Cleaning
19+
apt-get remove -y \
20+
build-essential \
21+
ca-certificates \
22+
cmake && \
23+
apt-get autoremove -y && \
24+
apt-get clean && \
25+
rm -rf /root/.cache && \
26+
rm -rf /var/lib/apt/lists/* && \
27+
chgrp -R 0 /root && \
28+
chmod -R g+rwX /root
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
transformers

0 commit comments

Comments
 (0)