[PYTHON] Make your own PC for deep learning

I will leave a memorandum of my own PC.

Finally, I will describe how to install Ubuntu and create a deep learning environment with docker.

table of contents

  1. Find out how to make your own PC
  2. Assemble the PC
  3. Environment construction

1. Find out how to make your own PC

――I referred to the following sites. -Summary by self-made PC budget -How to make a PC for deep learning

It seems that it is better to decide the specifications according to the application.

--Because preprocessing is executed frequently, the number of CPU cores is large. --Keep a large power supply and case in case you want to add more GPUs

As a result of the examination, we made the following configuration.

What I made

** CPU ** [Core i7-9700K](https://www.amazon.co.jp/%E3%82%A4%E3%83%B3%E3%83%86%E3%83%AB-Core i7 -9700K-INTEL 300% E3% 82% B7% E3% 83% AA% E3% 83% BC% E3% 82% BA-Chipset% E3% 83% 9E% E3% 82% B6% E3% 83% BC% E3 % 83% 9C% E3% 83% BC% E3% 83% 89% E5% AF% BE% E5% BF% 9C-BX80684I79700K% E3% 80% 90BOX% E3% 80% 91 / dp / B07HHN6KBZ) 45,000 yen ** GPU ** GeForce RTX2080Ti 11GB GamingPro OC 89,000 yen (used) ** Motherboard ** [ASUS PRIME Z390-A](https://www.amazon.co.jp/Intel-LGA1151-%E3%83%9E%E3%82%B6%E3%83%BC%E3% 83% 9C% E3% 83% BC% E3% 83% 89-PRIME-Z390 / dp / B07HCY7K9L) 22,000 yen ** Memory ** Kingston FURY RGB (DDR4 2666MHz 16GBx2) 20,000 yen ** Case ** [O11 DYNAMIC WHITE](https://www.amazon.co.jp/DYNAMIC%E3%82%B7%E3%83%AA%E3%83%BC%E3%82%BA-ATX % E5% AF% BE% E5% BF% 9CPC% E3% 82% B1% E3% 83% BC% E3% 82% B9-% E5% BC% B7% E5% 8C% 96% E3% 82% AC% E3% 83% A9% E3% 82% B9% E3% 83% 91% E3% 83% 8D% E3% 83% AB-DYNAMIC-% E6% 97% A5% E6% 9C% AC% E6% AD% A3 % E8% A6% 8F% E4% BB% A3% E7% 90% 86% E5% BA% 97% E5% 93% 81 / dp / B07C88K4KP / ref = sr_1_8? __ mk_ja_JP =% E3% 82% AB% E3% 82% BF% E3% 82% AB% E3% 83% 8A & crid = 126X9EAEQS38A & keywords = pc% E3% 82% B1% E3% 83% BC% E3% 82% B9% 2Be-atx & qid = 1572082964 & s = computers & sprefix = PC% E3% 82% B1% E3% 83% BC% E3% 82% B9% 2Be% 2Ccomputers% 2C234 & sr = 1-8 & th = 1) 14,000 yen ** Power ** [Corsair HX1000i](https://www.amazon.co.jp/Corsair-HX1000i-80PLUS-PLATINUM-CP-9020074-JP/dp/B00NV3NN1G/ref=sr_1_1?__mk_ja_JP=%E3%82 % AB% E3% 82% BF% E3% 82% AB% E3% 83% 8A & keywords = Corsair + HX1000i & linkCode = sl2 & linkId = 7e74aeede033623f3854a6a093ea43d9 & qid = 1572077086 & sr = 8-1) ** SSD ** [Intel SSD 660P](https://www.amazon.co.jp/dp/B07GCL6BR4/ref=as_li_ss_tl?ie=UTF8&linkCode=ll1&tag=jisakuhibi0b-22&linkId=fd963ff0cd812b7122e38e558af646c5&language=ja_JP ** HDD ** SEAGATE ST6000DM003 11,000 yen ** Simple water cooling fan ** [Novonest CC240RGB] (https://www.amazon.co.jp/gp/product/B07JFVV9VB/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1) 7,000 yen ** Wireless LAN card ** Ziyituod ZYT-WIE9260 4,000 yen ** Case fan ** Ubanner RB001 4,500 yen

** Total ** 254,500 yen

I bought it at "No!" Without doing much preliminary research, but I should have investigated more ** as described later **.

Other things I bought

** RGB fan controller ** Fractal Design Adjust R1 3,000 yen

I bought a motherboard that does not support the addressable RGB standard, but I bought a simple water-cooled fan for addressable RGB, so I ended up buying it. (Be careful not to make the same mistake ...)

** Thermal Grizzly ** Thermal Grizzly 750 yen

Consideration / Reflections

--Looking at the number of cores, Xeon and Threadripper There seems to be .aspx? Pdf_Spec101 = 73), but I couldn't afford it.

-[Intel 9900k](https://www.amazon.co.jp/INTEL-%E3%82%A4%E3%83%B3%E3%83%86%E3%83%AB-Corei9-9900K-INTEL300 % E3% 82% B7% E3% 83% AA% E3% 83% BC% E3% 82% BAChipset% E3% 83% 9E% E3% 82% B6% E3% 83% BC% E3% 83% 9C% E3 % 83% BC% E3% 83% 89% E5% AF% BE% E5% BF% 9C-BX80684I99900K% E3% 80% 90BOX% E3% 80% 91 / dp / B005404P9I) and [Ryzen 3900K](https: / /www.amazon.co.jp/AMD-Ryzen-3900X-105W%E3%80%90%E5%9B%BD%E5%86%85%E6%AD%A3%E8%A6%8F%E4%BB % A3% E7% 90% 86% E5% BA% 97% E5% 93% 81% E3% 80% 91-100-100000023BOX / dp / B07SXMZLP9 / ref = as_li_ss_tl? __mk_ja_JP =% E3% 82% AB% E3% 82% BF% E3% 82% AB% E3% 83% 8A & keywords = 3900x & qid = 1562932114 & s = gateway & sr = 8-1 & linkCode = sl1 & tag = artjuku-22 & linkId = 302a03c426c499b28724f235b7624370 & language = ja_JP), but price and cooling are also considered It seemed likely, so I chose Core i7, which seems to be fun.

-** It is not recommended to buy a GPU second hand **, so I should have bought a new one ... While accepting some risks, I will continue to use it as if it were a pillar.

--GPU is Titan RTX, Tesla V100, but it's expensive and I don't feel like it's used up.

――Honestly, if you just turn deep learning, you should be able to make it cheaper **. --Stop simple water cooling [air cooling](https://www.amazon.co.jp/%E3%82%B5%E3%82%A4%E3%82%BA-%E3%82%AA%E3%83 % AA% E3% 82% B8% E3% 83% 8A% E3% 83% ABCCPU% E3% 82% AF% E3% 83% BC% E3% 83% A9% E3% 83% BC-% E8% 99% 8E% E5% BE% B9-Mark-II / dp / B072PWL5YF) --Memory [normal (non-shining)](https://www.amazon.co.jp/2666Mhz-PC4-21300-8GBx2%E6%9E%9A%EF%BC%8816GBkit%EF%BC%89 % E3% 83% 87% E3% 82% B9% E3% 82% AF% E3% 83% 88% E3% 83% 83% E3% 83% 97% E7% 94% A8-% E6% 97% A5% E6% 9C% AC% E5% 9B% BD% E5% 86% 85% E7% 84% A1% E6% 9C% 9F% E9% 99% 90% E4% BF% 9D% E8% A8% BC-% E6 % B0% B8% E4% B9% 85% E4% BF% 9D% E8% A8% BC% EF% BC% 89% E6% AD% A3% E8% A6% 8F% E5% 93% 81 / dp / B07HK1HWJK / ref = as_li_ss_tl? _encoding = UTF8 & refRID = KVWRMB527B7G73Z9PMSZ & linkCode = sl1 & tag = artjuku-22 & linkId = 4a3b17eeb2d258052d4b015fc5764f39 & language = ja_JP & th = 1) --Make CPU and GPU good cost performance --Assuming one GPU, make the power supply and case smaller --Reduce SSD capacity

And so on, it seems that various wastes can be saved.

2. Assemble the PC

While carefully reading the instruction manual of the motherboard, I assembled it with reference to here.

  1. Install the CPU on the motherboard
  2. Attach the CPU cooler (this time simple water cooling) to the motherboard
  3. Memory installation
  4. SSD installation
  5. Connect the power supply and check the operation
  6. Attach the motherboard to the case
  7. Attach the water cooling fan to the case
  8. Installing the power supply
  9. HDD installation
  10. GPU installation
  11. Installing the wireless LAN card
  12. Installing the case fan
  13. Wiring
  14. Turn on the power and check the operation (check that the CPU temperature and fan speed are within the normal values)
  15. ** Satisfied with the beautiful LED, drink beer and sleep **
pc_image

3. Environment construction

3.1 Install Ubuntu 18.04.4 LTS

-I installed it referring to here.

--First, when I connected the monitor to the terminal of Gravo and started Ubuntu, [The screen freezes](https://qiita.com/k_ikasumipowder/items/5e88ec45f958c35e05ed#deep-learning-%E7%92 % B0% E5% A2% 83% E3% 81% AE% E6% A7% 8B% E7% AF% 89).

――So, first connect it to the terminal of the motherboard or [Disable nouveau](https://qiita.com/k_ikasumipowder/items/5e88ec45f958c35e05ed#nouveau%E3%81%AE%E7%84%A1%E5 % 8A% B9% E5% 8C% 96).

3.2 Installing the graphics driver

If you installed Ubuntu in Japanese, change the Japanese such as documents to English.

terminal


LANG=C xdg-user-dirs-gtk-update

Update package

terminal


sudo apt-get update
sudo apt-get upgrade

Select and download the corresponding driver from NVIDIA Driver Download

Install what you need to run the downloaded file


sudo apt-get install build-essential

The graphics driver may crash during driver installation, so just in case, switch to CUI with Ctrl + Alt + F1. (It seems that it may be switched by Ctrl + Alt + F2 etc. If it still does not work, try changing the function key to 3 ~ 12) At this time, specify **--no-opengl-files **, **--no-libglx-indirect **, **--dkms ** If you don't specify --no yeah, you will get stuck in the login loop, and if you don't have enough --dkms, the nvidia driver will be disabled every time you restart.

Run the downloaded file


chmod +x ./NVIDIA-Linux-x86_64-440.31.run
sudo ./NVIDIA-Linux-x86_64-440.31.run --no-opengl-files --no-libglx-indirect --dkms

Reboot


reboot

(If the monitor is connected to the motherboard, connect it to the terminal of Gravo.)

Driver operation check


nvidia-smi

Complete when GPU information is displayed

3.3 docker installation

Install according to Official. As of November 4, 2019, the following command was executed.

sudo apt-get update
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

Settings to execute docker command without sudo Also.

sudo groupadd docker
sudo gpasswd -a $USER docker
sudo service docker restart
reboot

3.4 nvidia-docker installation

Install according to NVIDIA Container Toolkit.

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

If you can see the GPU information with the following command, it is successful.

docker run --gpus all --rm nvidia/cuda nvidia-smi

3.5 Confirmed operation with docker image

Let's move tensorflow official docker image.

docker pull tensorflow/tensorflow:1.14.0-gpu-py3-jupyter
docker run --gpus all -it --rm -v $(realpath ~/notebooks):/tf/notebooks -p 8888:8888 tensorflow/tensorflow:1.14.0-gpu-py3-jupyter

When jupyter starts, connect to localhost: 8888 with a browser

Check if you can see the GPU from tensorflow

from tensorflow.python.client import device_lib
print(device_lib.list_local_devices()) 

If you can see the GPU as shown below, you are successful.

output


[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 14740279898702566726
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 10721268506091676345
physical_device_desc: "device: XLA_GPU device"
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 16980550380766421160
physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 10512030106
locality {
  bus_id: 1
  links {
  }
}
incarnation: 10531017116676756003
physical_device_desc: "device: 0, name: GeForce RTX 2080 Ti, pci bus id: 0000:01:00.0, compute capability: 7.5"
]

3.6 MNIST

You can finally turn the deep!

Let's turn MNIST with a simple CNN.

!pip install keras

import keras
from keras.datasets import mnist
from keras.models import Sequential
from keras.layers import Dense, Dropout, Flatten, MaxPooling2D, Conv2D
from keras.callbacks import TensorBoard

(X_train,y_train), (X_test, y_test) = mnist.load_data()

X_train = X_train.reshape(60000,28,28,1).astype('float32')
X_test = X_test.reshape(10000,28,28,1).astype('float32')

X_train /= 255
X_test /= 255

n_classes = 10
y_train = keras.utils.to_categorical(y_train, n_classes)
y_test = keras.utils.to_categorical(y_test, n_classes)

model = Sequential()
model.add(Conv2D(32, kernel_size=(3,3), activation='relu', input_shape=(28,28,1)) )
model.add(Conv2D(64, kernel_size=(3,3), activation='relu'))
model.add(MaxPooling2D(pool_size=(2,2)))
model.add(Dropout(0.5))
model.add(Flatten())          
model.add(Dense(128, activation='relu'))
model.add(Dropout(0.5))
model.add(Dense(n_classes, activation='softmax'))

model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])

import time
start = time.time()

model.fit(X_train, y_train, batch_size=128, epochs=15, verbose=1,
          validation_data=(X_test,y_test))

elapsed_time = time.time() - start
print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

output


elapsed_time:65.47733306884766[sec]

The GPU of Google Colaboratory is randomly assigned, but when I subtracted P100, it took 62 seconds.

It's sad that a PC that has used more than 200,000 loses to the free Colaboratory, but there is no time limit, the response is quick, and it seems to be a big advantage to be able to expand as you like.

Recommended Posts

Make your own PC for deep learning
Extend and inflate your own Deep Learning dataset
Deep learning for compound formation?
[Python] Make your own LINE bot
Make your own manual. [Linux] [man]
Make ASCII art with deep learning
Make people smile with Deep Learning
[AI] Deep Learning for Image Denoising
Introduction to Deep Learning (2) --Try your own nonlinear regression with Chainer-
Deep Learning
[Deep learning] Nogizaka face detection ~ For beginners ~
About data expansion processing for deep learning
Put your own image data in Deep Learning and play with it
Recommended study order for machine learning / deep learning beginners
Deep Learning Memorandum
Start Deep learning
Read & implement Deep Residual Learning for Image Recognition
Make your own module quickly with setuptools (python)
Python Deep Learning
Deep learning × Python
Implementation of Deep Learning model for image recognition
Make for VB6.
python: Use your own class for numpy ndarray
I installed Chainer, a framework for deep learning
Make your own music player with Bottle0.13 + jPlayer2.5!
Create your own Big Data in Python for validation
Make your python CUI application an app for mac
Techniques for understanding the basis of deep learning decisions
Try to put LED in your own PC (slightly)
Deep Learning Experienced in Python Chapter 2 (Materials for Journals)
Make Jupyter Notebook your own: Change background and icons
A scene where GPU is useful for deep learning?
Create your own exception
First Deep Learning ~ Struggle ~
Python: Deep Learning Practices
Deep learning / activation functions
Deep Learning from scratch
Deep learning 1 Practice of deep learning
Reinforcement learning for tic-tac-toe
Deep learning / cross entropy
First Deep Learning ~ Preparation ~
First Deep Learning ~ Solution ~
[AI] Deep Metric Learning
I tried deep learning
Python: Deep Learning Tuning
Deep learning large-scale technology
Try to make a blackjack strategy by reinforcement learning (③ Reinforcement learning in your own OpenAI Gym environment)
Summary for learning RAPIDS
[For recording] Keras image system Part 2: Make judgment by CNN using your own data set
Deep learning / softmax function
Tips for handling variable length inputs in deep learning frameworks
Japanese translation of public teaching materials for Deep learning nanodegree
Create an environment for "Deep Learning from scratch" with Docker
Recognize your boss and hide the screen with Deep Learning
Set up AWS (Ubuntu 14.04) for Deep Learning (install CUDA, cuDNN)
Let's make a number guessing game in your own language!
A story about a 40-year-old engineer manager passing "Deep Learning for ENGINEER"
Reinforcement learning 23 Create and use your own module with Colaboratory