2020-04-25 18:17:09 +00:00
|
|
|
ARG CUDA_VERSION=10.1
|
2020-09-10 22:38:29 +00:00
|
|
|
FROM nvidia/cuda:${CUDA_VERSION}-devel
|
2020-04-25 18:17:09 +00:00
|
|
|
|
|
|
|
# install versions
|
|
|
|
ARG PYTHON_VERSION=3.7
|
2020-09-22 23:41:35 +00:00
|
|
|
ARG PYTORCH_VERSION=1.6
|
2020-09-17 18:30:39 +00:00
|
|
|
ARG PYTORCH_CHANNEL=pytorch
|
2020-09-10 22:38:29 +00:00
|
|
|
ARG LIGHTNING_VERSION=""
|
2020-08-15 19:39:44 +00:00
|
|
|
# NOTE new Conda does not forward the exit status... https://github.com/conda/conda/issues/8385
|
|
|
|
ARG CONDA_VERSION=4.7.12
|
2020-04-25 18:17:09 +00:00
|
|
|
|
2020-08-15 19:39:44 +00:00
|
|
|
RUN apt-get update && \
|
|
|
|
apt-get install -y --no-install-recommends \
|
2020-04-25 18:17:09 +00:00
|
|
|
build-essential \
|
|
|
|
cmake \
|
|
|
|
git \
|
|
|
|
curl \
|
2020-08-15 19:39:44 +00:00
|
|
|
ca-certificates \
|
|
|
|
&& \
|
|
|
|
|
|
|
|
# Cleaning
|
|
|
|
apt-get autoremove -y && \
|
|
|
|
apt-get clean && \
|
|
|
|
rm -rf /root/.cache
|
2020-04-25 18:17:09 +00:00
|
|
|
|
|
|
|
# add non-root user
|
2020-09-10 22:38:29 +00:00
|
|
|
RUN useradd --create-home --shell /bin/bash flash
|
2020-08-15 19:39:44 +00:00
|
|
|
|
2020-09-10 22:38:29 +00:00
|
|
|
USER flash
|
2020-08-15 19:39:44 +00:00
|
|
|
ENV CONDA_ENV=lightning
|
2020-09-10 22:38:29 +00:00
|
|
|
ENV WORKDIR=/home/flash
|
|
|
|
WORKDIR $WORKDIR
|
2020-08-15 19:39:44 +00:00
|
|
|
|
2020-04-25 18:17:09 +00:00
|
|
|
# install conda and python
|
2020-08-15 19:39:44 +00:00
|
|
|
RUN curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-${CONDA_VERSION}-Linux-x86_64.sh && \
|
2020-04-25 18:17:09 +00:00
|
|
|
chmod +x ~/miniconda.sh && \
|
2020-09-10 22:38:29 +00:00
|
|
|
~/miniconda.sh -b -p ${WORKDIR}/miniconda && \
|
2020-08-15 19:39:44 +00:00
|
|
|
rm ~/miniconda.sh
|
|
|
|
|
2020-04-25 18:17:09 +00:00
|
|
|
# add conda to path
|
2020-09-10 22:38:29 +00:00
|
|
|
ENV PATH="${WORKDIR}/miniconda/bin:$PATH"
|
|
|
|
ENV LD_LIBRARY_PATH="${WORKDIR}/miniconda/lib:$LD_LIBRARY_PATH"
|
|
|
|
ENV CUDA_TOOLKIT_ROOT_DIR="/usr/local/cuda"
|
|
|
|
|
|
|
|
COPY --chown=flash environment.yml environment.yml
|
2020-08-15 19:39:44 +00:00
|
|
|
|
|
|
|
# conda init
|
2020-09-22 23:41:35 +00:00
|
|
|
RUN conda create -y --name $CONDA_ENV python=$PYTHON_VERSION pytorch=$PYTORCH_VERSION torchvision cudatoolkit=$CUDA_VERSION --channel=$PYTORCH_CHANNEL && \
|
2020-08-15 19:39:44 +00:00
|
|
|
conda init bash && \
|
2020-09-22 23:41:35 +00:00
|
|
|
# NOTE: this requires that the channel is presented in the yaml before packages
|
|
|
|
python -c "fname = 'environment.yml' ; req = open(fname).read().replace('pytorch', '${PYTORCH_CHANNEL}', 1) ; open(fname, 'w').write(req)" && \
|
2020-09-10 22:38:29 +00:00
|
|
|
conda env update --file environment.yml && \
|
2020-09-22 23:41:35 +00:00
|
|
|
conda clean -ya && \
|
|
|
|
rm environment.yml
|
2020-08-15 19:39:44 +00:00
|
|
|
|
2020-09-10 22:38:29 +00:00
|
|
|
ENV LD_LIBRARY_PATH="${WORKDIR}/miniconda/envs/${CONDA_ENV}/lib:$LD_LIBRARY_PATH"
|
2020-08-15 19:39:44 +00:00
|
|
|
# if you want this environment to be the default one, uncomment the following line:
|
|
|
|
ENV CONDA_DEFAULT_ENV=${CONDA_ENV}
|
2020-04-25 18:17:09 +00:00
|
|
|
|
2020-09-10 22:38:29 +00:00
|
|
|
# Get package
|
|
|
|
COPY --chown=flash ./ ./pytorch-lightning/
|
|
|
|
|
2020-04-25 18:17:09 +00:00
|
|
|
# install dependencies
|
2020-09-10 22:38:29 +00:00
|
|
|
RUN \
|
2020-09-22 23:41:35 +00:00
|
|
|
# Disable cache
|
|
|
|
#conda install "pip>20.1" && \
|
|
|
|
#pip config set global.cache-dir false && \
|
2020-09-10 22:38:29 +00:00
|
|
|
if [ -z $LIGHTNING_VERSION ] ; then \
|
|
|
|
pip install ./pytorch-lightning --upgrade-strategy only-if-needed ; \
|
|
|
|
rm -rf pytorch-lightning ; \
|
|
|
|
else \
|
|
|
|
rm -rf pytorch-lightning ; \
|
|
|
|
pip install git+https://github.com/PyTorchLightning/pytorch-lightning.git@${LIGHTNING_VERSION} --upgrade-strategy only-if-needed ; \
|
|
|
|
fi
|
2020-04-25 18:17:09 +00:00
|
|
|
|
2020-08-15 19:39:44 +00:00
|
|
|
RUN python --version && \
|
|
|
|
pip --version && \
|
2020-09-22 23:41:35 +00:00
|
|
|
pip list && \
|
2020-08-15 19:39:44 +00:00
|
|
|
python -c "import pytorch_lightning as pl; print(pl.__version__)"
|
2020-04-25 18:17:09 +00:00
|
|
|
|
|
|
|
CMD ["/bin/bash"]
|