2020-10-02 09:26:21 +00:00
# Copyright The PyTorch Lightning team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2020-08-15 19:39:44 +00:00
FROM google/cloud-sdk:slim
2020-10-02 09:26:21 +00:00
# CALL: docker image build -t pytorch-lightning:XLA-extras-py3.6 -f dockers/base-xla/Dockerfile . --build-arg PYTHON_VERSION=3.6
2020-08-15 19:39:44 +00:00
# This Dockerfile installs pytorch/xla 3.7 wheels. There are also 3.6 wheels available; see below.
ARG PYTHON_VERSION = 3 .7
2020-10-02 09:26:21 +00:00
ARG XLA_VERSION = 1 .6
2020-08-15 19:39:44 +00:00
SHELL [ "/bin/bash" , "-c" ]
# for skipping configurations
ENV DEBIAN_FRONTEND = noninteractive
2020-10-02 09:26:21 +00:00
ENV CONDA_ENV = lightning
2020-08-15 19:39:44 +00:00
# show system inforation
RUN lsb_release -a && cat /etc/*-release
RUN apt-get update && \
apt-get install -y --no-install-recommends \
build-essential \
cmake \
wget \
curl \
unzip \
ca-certificates \
libomp5 \
&& \
# Install conda and python.
# NOTE new Conda does not forward the exit status... https://github.com/conda/conda/issues/8385
curl -o ~/miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-4.7.12-Linux-x86_64.sh && \
chmod +x ~/miniconda.sh && \
~/miniconda.sh -b && \
rm ~/miniconda.sh && \
# Cleaning
apt-get autoremove -y && \
apt-get clean && \
2020-09-30 12:33:22 +00:00
rm -rf /root/.cache && \
rm -rf /var/lib/apt/lists/*
2020-08-15 19:39:44 +00:00
ENV PATH = " /root/miniconda3/bin: $PATH "
ENV LD_LIBRARY_PATH = " /root/miniconda3/lib: $LD_LIBRARY_PATH "
2020-10-02 09:26:21 +00:00
COPY environment.yml environment.yml
2020-08-15 19:39:44 +00:00
2020-10-02 09:26:21 +00:00
RUN conda create -y --name $CONDA_ENV && \
2020-08-15 19:39:44 +00:00
conda init bash && \
2020-10-02 09:26:21 +00:00
# replace channel to nigtly if neede, fix PT version and remove Horovod as it will be installe later
python -c " import re ; fname = 'environment.yml' ; req = re.sub(r'python>=[\d\.]+', 'python= ${ PYTHON_VERSION } ', open(fname).read()) ; open(fname, 'w').write(req) " && \
python -c "fname = 'environment.yml' ; req = open(fname).readlines() ; open(fname, 'w').writelines([ln for ln in req if not any(n in ln for n in ['pytorch>', 'horovod'])])" && \
cat environment.yml && \
conda env update --file environment.yml && \
conda clean -ya && \
rm environment.yml
ENV PATH /root/miniconda3/envs/${ CONDA_ENV } /bin:$PATH
ENV LD_LIBRARY_PATH = " /root/miniconda3/envs/ ${ CONDA_ENV } /lib: $LD_LIBRARY_PATH "
# if you want this environment to be the default one, uncomment the following line:
ENV CONDA_DEFAULT_ENV = ${ CONDA_ENV }
2020-08-15 19:39:44 +00:00
# Disable cache
2020-10-02 09:26:21 +00:00
RUN pip --version && \
2020-08-15 19:39:44 +00:00
pip config set global.cache-dir false && \
2020-10-02 09:26:21 +00:00
conda remove pytorch torchvision && \
2020-08-15 19:39:44 +00:00
# Install Pytorch XLA
py_version = ${ PYTHON_VERSION /./ } && \
# Python 3.7 wheels are available. Replace cp36-cp36m with cp37-cp37m
gsutil cp " gs://tpu-pytorch/wheels/torch- ${ XLA_VERSION } -cp ${ py_version } -cp ${ py_version } m-linux_x86_64.whl " . && \
gsutil cp " gs://tpu-pytorch/wheels/torch_xla- ${ XLA_VERSION } -cp ${ py_version } -cp ${ py_version } m-linux_x86_64.whl " . && \
gsutil cp " gs://tpu-pytorch/wheels/torchvision- ${ XLA_VERSION } -cp ${ py_version } -cp ${ py_version } m-linux_x86_64.whl " . && \
pip install *.whl && \
rm *.whl
# Get package
2020-09-10 22:38:29 +00:00
COPY ./ ./pytorch-lightning/
2020-08-15 19:39:44 +00:00
2020-09-10 22:38:29 +00:00
# Install pytorch-lightning dependencies.
RUN \
2020-10-02 09:26:21 +00:00
python --version && \
2020-08-15 19:39:44 +00:00
# Install PL dependencies
2020-09-10 22:38:29 +00:00
cd pytorch-lightning && \
2020-09-30 12:36:02 +00:00
# drop Torch as it was installed with XLA
2020-10-18 18:40:18 +00:00
python -c "fname = 'requirements.txt' ; lines = [line for line in open(fname).readlines() if not line.startswith('torch')] ; open(fname, 'w').writelines(lines)" && \
2020-09-30 12:36:02 +00:00
# drop Horovod as it is not needed
2020-10-02 09:26:21 +00:00
python -c "fname = 'requirements/extra.txt' ; lines = [line for line in open(fname).readlines() if not line.startswith('horovod')] ; open(fname, 'w').writelines(lines)" && \
2020-09-30 12:36:02 +00:00
# drop TorchVision as it was installed with XLA
2020-10-02 09:26:21 +00:00
python -c "fname = 'requirements/examples.txt' ; lines = [line for line in open(fname).readlines() if not line.startswith('torchvision')] ; open(fname, 'w').writelines(lines)" && \
2020-09-30 12:36:02 +00:00
pip install --requirement ./requirements/devel.txt --upgrade-strategy only-if-needed && \
2020-08-15 19:39:44 +00:00
cd .. && \
2020-09-10 22:38:29 +00:00
rm -rf pytorch-lightning && \
2020-08-15 19:39:44 +00:00
rm -rf /root/.cache
2020-10-02 09:26:21 +00:00
RUN \
# Show what we have
pip --version && \
conda info && \
pip list && \
python -c " import sys; assert sys.version[:3] == ' $PYTHON_VERSION ', sys.version " && \
python -c " import torch; ver = ' $XLA_VERSION ' ; ver = dict(nightly='1.7').get(ver, ver) ; assert torch.__version__[:3] == ver, torch.__version__ "