Ubuntu에 TensorFlow+Docker+NVIDIA GPU로 기계 학습하기 위한 준비 노트

Ubuntu에서 tensorflow2계에서 GPU를 사용한 기계 학습 준비입니다.

Docker 설치



【참고】
htps : // / cs. 도 c r. 코 m / 게 t - c r /
htps : // / cs. 도 c r. 코 m/엔기네/인 s타르/우분/
#旧バージョンがインストールされていればUninstallする
#$ sudo apt-get remove docker docker-engine docker.io containerd runc
#リポジトリ使ってインストール
$ sudo apt-get update

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
#Docker's official GPG keyを追加
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo apt-key fingerprint 0EBFCD88
#Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.だそうです

#x86_64/amd64の場合はこれ、armとかは別のコマンドのようです
$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

#Dockerエンジンインストール
#今回は19.03以降でnvidia-container-toolkitを使うつもりなので最新版をインストールします(19.03.8が最新でした)
 $ sudo apt-get update
 $ sudo apt-get install docker-ce docker-ce-cli containerd.io


동작 확인


sudo docker run --rm hello-world 실행

↓이런 메시지가 나오면 OK인 것 같습니다.
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete 
Digest: sha256:8e3114318a995a1ee497790535e7b88365222a21771ae7e53687ad76563e8e76
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the![Screenshot from 2020-05-09 17-35-12.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/241416/0ea9d1e3-e1d5-568e-7c0b-b577bfbae162.png)

    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

NVIDIA GPU 드라이버 설치



gcc가 필요하기 때문에 미리 넣어 둡시다.sudo apt install build-essentiial 에 넣어 보았습니다

【참고】
htps : // m / 191128 / ms / 8, 46308, 6949f5b, 57
NVIDIA-Linux-x86_64-440.82.run 옵션





NVIDIA Docker 지원 설치



htps : // 기주 b. 코 m / 응 ぃ ぢ 아 / 응 ぃ ぢ 아- c r
QuickStart에 따라
# Add the package repositories
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

sudo apt-get update && sudo apt-get install -y nvidia-container-toolkit
sudo systemctl restart docker

Usage의
sudo docker run --gpus all nvidia/cuda:10.0-base nvidia-smi

실행하면 뭔가 움직이는 것 같습니다! !

tensorflow의 GPU 지원 이미지를 사용한 동작 확인



htps //w w. 천식 rfぉw. 오 rg / 인 s ta l / da c r? hl = 그럼
돌아가서 GPU 지원 동작 확인
sudo docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu \
       python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"

조금 시간이 걸렸지만 무사히 완료!
아무래도 준비가 된 모양입니다.

좋은 웹페이지 즐겨찾기