LoginSignup
4
1

More than 3 years have passed since last update.

PyTorch1.3.1をCUDA9.0環境でDocker Buildする

Posted at

PyTorch1.3.1はCUDA9.2や10.0のwheelが用意されているが、CUDA9.0環境が無い。
ので、自分でビルドしないといけない。そのときにちょっと苦戦したのでメモ。

PyTorch1.3.1のコードのコードをビルドしていく。
docker/pytorch/Dockerfileがあるのでまずこれをベースにする。

1行目をCUDA9.0のイメージにすれば良いと思ってたんだけど、どうやら28行目のTORCH_CUDA_ARCH_LISTも変えないといけないらしい。
TORCH_CUDA_ARCH_LISTで検索して、どうやらCUDA9.0のときはTORCH_CUDA_ARCH_LIST="3.7+PTX;5.0;6.0;7.0"を指定すればいいことに気づいたけど、何をヒントにそう思ったのかは忘れてしまった。

この2箇所を変えたDockerfileが↓のようになる。
github checkout v1.3.1したあとにdocker built .すればいいはず。

FROM nvidia/cuda:9.0-cudnn7-devel-ubuntu16.04
ARG PYTHON_VERSION=3.6
ARG WITH_TORCHVISION=1
RUN apt-get update && apt-get install -y --no-install-recommends \
         build-essential \
         cmake \
         git \
         curl \
         ca-certificates \
         libjpeg-dev \
         libpng-dev && \
     rm -rf /var/lib/apt/lists/*


RUN curl -o ~/miniconda.sh -O  https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh  && \
     chmod +x ~/miniconda.sh && \
     ~/miniconda.sh -b -p /opt/conda && \
     rm ~/miniconda.sh && \
     /opt/conda/bin/conda install -y python=$PYTHON_VERSION numpy pyyaml scipy ipython mkl mkl-include ninja cython typing && \
     /opt/conda/bin/conda install -y -c pytorch magma-cuda100 && \
     /opt/conda/bin/conda clean -ya
ENV PATH /opt/conda/bin:$PATH
# This must be done before pip so that requirements.txt is available
WORKDIR /opt/pytorch
COPY . .

RUN git submodule update --init --recursive
RUN TORCH_CUDA_ARCH_LIST="3.7+PTX;5.0;6.0;7.0" TORCH_NVCC_FLAGS="-Xfatbin -compress-all" \
    CMAKE_PREFIX_PATH="$(dirname $(which conda))/../" \
    pip install -v .

RUN if [ "$WITH_TORCHVISION" = "1" ] ; then git clone https://github.com/pytorch/vision.git && cd vision && pip install -v . ; else echo "building without torchvision" ; fi

WORKDIR /workspace
RUN chmod -R a+w .
4
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
1