forked from prabhuomkar/pytorch-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Build and run tutorials in Docker container on CPU (prabhuomkar#65)
* Add option to build and run tutorials on CPU using Docker * Remove parallel cmake building in Docker container and ipc=host setting for Windows compatibility * Change Dockerfile username
- Loading branch information
Showing
7 changed files
with
124 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/data | ||
/build | ||
/images | ||
/LICENSE | ||
/AUTHORS | ||
/notebooks | ||
/README.md | ||
/docker-compose.yml | ||
/Dockerfile | ||
/.github | ||
/.gitignore | ||
/.dockerignore | ||
/.travis.yml | ||
/.git |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Force bash scripts to always use LF line endings. | ||
*.sh text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Based on and inspired by Dockerfiles and resources at: | ||
# https://github.com/pytorch/pytorch/blob/master/Dockerfile | ||
# https://github.com/anibali/docker-pytorch | ||
# https://jtreminio.com/blog/running-docker-containers-as-current-host-user/ | ||
|
||
ARG BASE_IMAGE=ubuntu:18.04 | ||
ARG PYTHON_VERSION=3.8 | ||
|
||
FROM ${BASE_IMAGE} AS dev-base | ||
# Install basic packages. | ||
RUN apt-get update && \ | ||
apt-get install -y --no-install-recommends \ | ||
build-essential \ | ||
curl \ | ||
git \ | ||
ca-certificates && \ | ||
apt-get autoremove -y && \ | ||
rm -rf /var/lib/apt/lists/* | ||
ENV PATH /opt/conda/bin:$PATH | ||
|
||
FROM dev-base AS conda | ||
# Install conda. | ||
ARG PYTHON_VERSION | ||
ENV CONDA_AUTO_UPDATE_CONDA=false | ||
RUN curl --silent --show-error --location --output ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && \ | ||
chmod +x ~/miniconda.sh && \ | ||
~/miniconda.sh -b -p /opt/conda && \ | ||
rm ~/miniconda.sh && \ | ||
conda install -y python=${PYTHON_VERSION} && \ | ||
conda clean -ya | ||
|
||
FROM conda AS conda-installs | ||
# Install pytorch for CPU and torchvision. | ||
ARG PYTORCH_VERSION=1.6.0 | ||
ARG TORCHVISION_VERSION=0.7.0 | ||
ENV NO_CUDA=1 | ||
RUN conda install pytorch==${PYTORCH_VERSION} torchvision==${TORCHVISION_VERSION} cpuonly -y -c pytorch && conda clean -ya | ||
|
||
FROM conda AS build | ||
# Build tutorials. | ||
ARG PYTHON_VERSION | ||
ARG GROUP_ID=1000 | ||
ARG USER_ID=1000 | ||
ENV PYTHON_VERSION=${PYTHON_VERSION} | ||
WORKDIR /pytorch-cpp | ||
RUN pip install --upgrade --no-cache-dir cmake && \ | ||
groupadd --gid ${GROUP_ID} pytorch && \ | ||
useradd --uid ${USER_ID} --gid pytorch --create-home --no-log-init --shell /bin/bash pytorch && \ | ||
chown --changes --silent --no-dereference --recursive ${USER_ID}:${GROUP_ID} /home/pytorch | ||
USER pytorch | ||
ENV HOME=/home/pytorch | ||
COPY --from=conda-installs /opt/conda /opt/conda | ||
COPY --chown=pytorch:pytorch ./docker/docker-entrypoint.sh / | ||
RUN chmod +x /docker-entrypoint.sh | ||
ENTRYPOINT [ "/docker-entrypoint.sh" ] | ||
CMD [ "bash" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "3" | ||
|
||
services: | ||
pytorch-cpp: | ||
build: . | ||
volumes: | ||
- .:/pytorch-cpp | ||
image: pytorch-cpp | ||
container_name: pytorch-cpp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
set -Eeo pipefail | ||
|
||
cmake -B build -D CMAKE_BUILD_TYPE=Release \ | ||
-D CMAKE_PREFIX_PATH=/opt/conda/lib/python${PYTHON_VERSION}/site-packages/torch/share/cmake/Torch/ \ | ||
-D CREATE_SCRIPTMODULES=ON | ||
cmake --build build | ||
cd build/tutorials | ||
|
||
tutorial_path=$(find . -maxdepth 2 -mindepth 2 -type d -name $(echo $1 | tr - _)) | ||
|
||
if [ ! -z "$tutorial_path" ] | ||
then | ||
cd $tutorial_path | ||
./$(echo $(basename $tutorial_path) | tr _ -) ${@:2} | ||
else | ||
exec $@ | ||
fi |