ã©ããå¤å·ã§ãã
ä»åã¯nvidia-dockerã«ã¤ãã¦æ¸ãã¦ã¿ãããã¨æãã¾ãã
nvidia-dockerã¨ã¯ï¼
CUDAããã³cuDNNãªã©ã梱å ãããdockerã³ã³ããã¤ã¡ã¼ã¸ã使ããããã«ããããã®ãã¼ã«ã§ãã
å³ã®ããã«ãã¹ããã·ã³ã®Driverãç¨æããã¦ããã°ãCUDAãcuDNNãã¤ãã£ãã¢ããªãã³ã³ãããã¨ã«ç®¡çã§ãã¾ãï¼
2016å¹´7ææç¹ã§ã¯rcçã§ããã家ã®ãã·ã³ã§è©¦ããã¨ããå®å®ãã¦ä½¿ãããã ã£ãã®ã§ãä»åãæã«ç´¹ä»ãã¾ãï¼
çµå±nvidia-dockerã¯ä½ãããããã®ï¼
Deep Learningã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ã容æã«ãªã
ãã¹ããã·ã³ã«Deep Learningã©ã¤ãã©ãªãããå ´åãæ³å®ãã¦ãã ããã
Deep Learningã©ã¤ãã©ãªããã¼ã¸ã§ã³ã¢ãããããã¨ããèµ·ãã¾ããããã®å ´åã次ã®ä½æ¥ãå¿ è¦ã«ãªããã¨ãããã¾ãã
- CUDAã®ãã¼ã¸ã§ã³ã¢ãã
- cuDNNã®ãã¼ã¸ã§ã³ã¢ãã
ãã®ä½æ¥å¤§å¤ã§ãããï¼ï¼ã¨ãã«CUDAã¯GBåä½ããã®ã§ãã¤ã³ã¹ãã¼ã«ã¨ãé常ã«æéããããã¾ãï¼ã
ã¾ãããã¼ã¸ã§ã³ã¢ããå¾ä½ãããä¸å ·åããã£ãããåãæ»ãã®ã大å¤ã§ãããï¼ãããè¤æ°å°ããå¿ è¦ãããã®ãªãã»ã»ã»
ããã§ããã®ãã¼ã«ã§Deep Learningã©ã¤ãã©ãªã®ãã¼ã¸ã§ã³ãã¨ã«ã³ã³ããã管çãã¦ãããã¨ã§ããã¼ã¸ã§ã³ã®å¤æ´ã¯ã³ã³ãããåãæ¿ãã®ã¿ã§å¯¾å¿ã§ããã®ã§ãé常ã«ç°¡åã«ãªãã¾ãããã
ãããã£ãã¨ããã«ããªãã¡ãªããã¯ãããã¨æãã¾ãã
ãã ãããã©ã¤ãã¯ãã¹ãå´ã®ã使ç¨ããã®ã§ããã©ã¤ãã®ã¢ãããã¼ãã¯åé¿ã§ãã¾ããã®ã§ã注æãã ããï¼
å°å ¥
å°å ¥ç°å¢
- CPU: Core i7 6700K
- ã¡ã¢ãªï¼32GB
GPU: GTX980TI
OS: ubuntu 16.04 LTS
- GPUãã©ã¤ãï¼NVIDIA Driver ãã©ã¤ãï¼ãã¼ã¸ã§ã³360å°ï¼
docker engineã®ã¤ã³ã¹ãã¼ã«
nvidia-dockerã使ãå ´åãdocker-engineãå¿ è¦ã¨ã®ãã¨ãªã®ã§ãã¤ã³ã¹ãã¼ã«ãã¦ããã¾ã
# éµè¿½å sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D # ãªãã¸ããªè¿½å sudo vim /etc/apt/sources.list.d/docker.list # å 容ã¯æ¬¡ã®ããã«ããï¼ubuntuã®ãã¼ã¸ã§ã³ã«ãã£ã¦å 容ãå¤ããï¼ deb https://apt.dockerproject.org/repo ubuntu-xenial main # apt-getã®ã¢ãããã¼ã sudo apt-get update # docker-engineã®ã¤ã³ã¹ãã¼ã« apt-cache policy docker-engine sudo apt-get install docker-engine sudo service docker start
nvidia-dockerã®ã¤ã³ã¹ãã¼ã«
nvidia-dockerãã½ã¼ã¹ãããã«ããã¾ãã ãã«ãã«æåããã°ã/usr/bin/ãã£ã¬ã¯ããªã«ãnvidia-dockerã¨nvidia-docker-pluginãä½æããã¾ãã
git clone https://github.com/NVIDIA/nvidia-docker.git cd nvidia-docker/ sudo make install sudo nvidia-docker volume setup
使ãæ¹
tensorflow v0.9ã®ã³ã³ãããä½ãã使ã£ã¦ã¿ã
é©å½ãªå ´æã«ã¤ãã®Dockerfileãä½ãã¾ãã
FROM nvidia/cuda:7.5-cudnn4-runtime RUN apt-get update RUN apt-get install -y --no-install-recommends python-pip python-dev build-essential git RUN pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.9.0-cp27-none-linux_x86_64.whl # ã³ã³ãã容éç¯ç´ã®ãã RUN rm -rf /var/lib/apt/lists/* ENV LD_LIBRARY_PATH /usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH # cuDNNã®å ±æã©ã¤ãã©ãªãå¿ è¦ãªä½ç½®ã«ãªããããã·ã³ããªãã¯ãªã³ã¯ãè²¼ã£ã¦ãã RUN ln -s /usr/lib/x86_64-linux-gnu/libcudnn.so.4.0.7 /usr/lib/x86_64-linux-gnu/libcudnn.so ENTRYPOINT ["/bin/bash"]
ããã§ãã¤ã³ãã¨ãªãã®ã¯ãnvidia/cuda:7.5-cudnn4-runtime
ã³ã³ãããæå®ãã¦ããã¨ãããã¨ã§ãã
ãããæå®ãããã¨ã§ãCUDA7.5, cuDNN v4ãå
¥ã£ãã³ã³ããããã¼ã¹ã«ä½ã£ã¦ãã¾ãã
ã¤ã¾ããCUDAããã³cuDNNã®ãã¼ã¸ã§ã³ã®ã³ã³ããã¯ããã§æ±ºããã°ããã¨ãããã¨ã§ãï¼
ã¤ãã®ãã¨ã«ãããã£ã¦ãã®ã³ã³ããã決ãã¦ãã¾ãã
- tensorflowã®ãã«ãæ¸ã¿ã®pipããã±ã¼ã¸ãå©ç¨ããã«ã¯ãCUDA 7.5 cuDNN v4ã«ããå¿
è¦ãããããã§ãã
- ãã以å¤ã¯ã½ã¼ã¹ãããã«ãããªããã°ããã¾ããã
- pythonçã®tensorflowã®ã¿ä½¿ãã¨ãããã¨ã§ãnvccã¯ä¸è¦ã§ããã¨ãããã¨ã§runtimeã®æ¹ã使ç¨ãã¦ãã¾ãã
- ãã ããnvccãå¿
è¦ãªå ´åã¯
FROM nvidia/cuda:7.5-cudnn4-devel
- ãã ããnvccãå¿
è¦ãªå ´åã¯
ãã®Dockerfileãç¨ãã¦ã¤ã¡ã¼ã¸ããã«ããã¾ããã¤ã¡ã¼ã¸åã¯tensorflow:v0.9
ã¨ãã¾ãã
sudo nvidia-docker build -t tensorflow:v0.9 .
ãã«ãæåããããã³ã³ãããåããã¦ã¿ã¾ããããã®ã¾ãã«ã³ã³ããã¨ã®å
±æãã£ã¬ã¯ããª~/docker/share
ãä½æããtensorflowãµã³ãã«ã³ã¼ãããã¹ããã·ã³ã®æ¬¡ã®å ´æã«ããã¦ããã¾ãããããããã¨ãã¦ããã®ã¯ãã³ã³ããä¸ã§å®è¡ããçµæï¼ã¢ãã«ã¨ãï¼ã¯ã³ã³ããä¸ã§ã¯ãªãããã¹ããã·ã³ä¸ã«æ ¼ç´ãããããã§ãã
mkdir -P ~/docker/share cd ~/docker/share git clone --depth=1 -b v0.8.0 https://github.com/tensorflow/tensorflow.git
ãã®ã¤ã¡ã¼ã¸ã使ãããå ´åã¯ã次ã®ã³ãã³ããæã¡ã¾ããã¾ã-vãªãã·ã§ã³ãå
¥ãããã¨ã§ãã¹ããã·ã³ã®~/docker/share
ã/share
ã«ãããã³ã°ãã¦ãã¾ããã¾ããrw
ãæå®ãããã¨ã§ã³ã³ãããããã¹ããã·ã³ã¸ã®æ¸ãè¾¼ã¿ãå¯è½ã«ãã¦ã¾ãã
sudo nvidia-docker run -it -v ~/docker/share:/share:rw tensorflow:v0.9
注æ: ééã£ã¦ãã·ã¹ãã ãã¡ã¤ã«ãå«ã¾ããå ´æï¼ä¾ãã°, / ãªã©ï¼ããããã³ã°ãã¦ã¯ããã¾ããï¼ãããããã¨ã³ã³ããçµç±ã§ãã¹ããã·ã³èªä½ã®ãã¼ã¿ã«ã¢ã¯ã»ã¹ã§ãã¦ãã¾ãã¾ãï¼
ã§ã¯å®éã«ã³ã³ããä¸ãããµã³ãã«ã³ã¼ããåããã¦ã¿ã¾ãã
cd /share time python tensorflow/examples/tutorials/mnist/fully_connected_feed.py
ããã§ç¡äºã«åããããtensorflowã®ã³ã³ããã¯å®æã§ãã
ãã¨ã¯å¿ è¦ã«å¿ãã¦ã³ã³ããããç«ã¡ä¸ããã°ä½¿ããããã«ãªãã¾ãï¼
chainer v1.10ã®ã³ã³ãããä½ãã使ã£ã¦ã¿ã
ã¤ãã¯chainerã®ã³ã³ãããä½ã£ã¦ã¿ã¾ãï¼
é©å½ãªå ´æã«ã¤ãã®Dockerfileãä½ãã¾ããtensorflowã¨éãå ´æã§ä½ã£ã¦ãã ããï¼
FROM nvidia/cuda:7.5-cudnn4-devel RUN apt-get update RUN apt-get install -y --no-install-recommends python-pip python-dev build-essential git libhdf5-dev zlib1g-dev RUN pip install numpy==1.11 RUN pip install h5py ENV CUDA_PATH /usr/local/cuda RUN pip install chainer==1.10 # ã³ã³ãã容éç¯ç´ã®ãã RUN rm -rf /var/lib/apt/lists/* ENV LD_LIBRARY_PATH /usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH ENTRYPOINT ["/bin/bash"]
chainerã§GPUçã使ç¨ãããå ´åã¯nvccãå¿
è¦ã«ãªã£ã¦ããã®ã§ããã¼ã¹ã¨ãªãã³ã³ããã¯nvidia/cuda:7.5-cudnn4-devel
ã«ãã¾ãããnvidia/cuda:7.5-cudnn4-runtime
ã ã¨GPUã使ãã¾ããã§ããã
ãã®Dockerfileããããããããç¨ãã¦ã¤ã¡ã¼ã¸ããã«ããã¾ããã¤ã¡ã¼ã¸åã¯chainer:v1.10
ã¨ãã¾ããè¨å®å
容ã¯tensorflowã¨åæ§ã§ãã
sudo nvidia-docker build -t chainer:v1.10 .
tensorflowã®ã¨ãã¨åãããã«ãã³ã³ããã¨ã®å
±æãã£ã¬ã¯ããª~/docker/share
ã«chainerã®ãµã³ãã«ã³ã¼ããå
¥ãã¨ãã¾ãããï¼
cd ~/docker/share wget https://github.com/pfnet/chainer/archive/v1.10.0.tar.gz tar xzf v1.10.0.tar.gz rm v1.10.0.tar.gz
ã§ã¯ãã³ã³ãããèµ·åããã¾ãããï¼
sudo nvidia-docker run -it -v ~/docker/share:/share:rw chainer:v1.10
ã³ã³ããä¸ã«å ¥ããã次ã®ã³ãã³ãã§mnistãµã³ãã«ãåããã¦ã¿ã¾ãããï¼
cd /share python chainer-1.10.0/examples/mnist/train_mnist.py --gpu=0
ã¨ã©ã¼ããªãåãã°ãGPUçchainerã使ãã³ã³ããã¯å®æã§ãã
ã¾ã¨ãã»ææ
tensorflowã¨chainerãé¡æã«nvidia-dockerã§ã³ã³ããã®ä½ãæ¹ãç´¹ä»ãã¾ããï¼
æ£ç´CUDAã¨cuDNNãå ¥ããã®å¤§å¤ã§ãããããã¼ã¸ã§ã³å¤ããã ãã§ãè²ã 大å¤ã ã£ãã®ã§ããã®ãã¼ã«ãããã®ã¯ãããå©ããã¾ããï¼
ãã£ã¼ãã©ã¼ãã³ã°ç³»ã®ã©ã¤ãã©ãªã¯ã¾ã æ¯ãã¦ããªãæè¡ã§ãããé »ç¹ã«æ´æ°ãããã¨æãã¾ãï¼
ãããã£ãã©ã¤ãã©ãªã¨ãã¾ãä»ãåãããã®ä¸ã¤ã®æ段ã¨ãã¦å©ç¨ããã¨ããã¨æãã¾ãï¼