[关闭]
@BIGBALLON 2017-10-12T09:01:28.000000Z 字数 4400 阅读 3967

NVIDIA Driver & Pytorch installation

The simple setup tutorial for deep learning beginner.

STEP 1: Install NVIDIA Driver

  1. sudo apt-get update
  2. sudo apt-get upgrade
  1. sudo vi /etc/modprobe.d/disable-nouveau.conf
  2. //insert the following lines
  3. blacklist nouveau
  4. options nouveau modeset=0
  1. sudo update-initramfs -u
  2. sudo reboot

hit Ctrl+Alt+F1(tty1) and login, stop lightdm service & install dirver

  1. sudo service lightdm stop
  2. sudo apt-get install nvidia-375
  3. sudo reboot

(optional)To install latest drivers add PPA:

  1. sudo apt-get purge nvidia-*
  2. sudo add-apt-repository ppa:graphics-drivers/ppa
  3. sudo apt-get update
  4. sudo apt-get install nvidia-3xx

Then, you can use nvidia-smi to get the GPU info.

STEP 2: Install CUDA 8.0

  1. cd Downloads/
  2. sudo chmod a+x cuda_8.0.61_375.26_linux.run
  3. sudo ./cuda_8.0.61_375.26_linux.run
  1. Do you accept the previously read EULA?
  2. accept/decline/quit: accept
  3. Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
  4. (y)es/(n)o/(q)uit: no
  5. Install the CUDA 8.0 Toolkit?
  6. (y)es/(n)o/(q)uit: y
  7. Enter Toolkit Location
  8. [ default is /usr/local/cuda-8.0 ]:
  9. Do you want to install a symbolic link at /usr/local/cuda?
  10. (y)es/(n)o/(q)uit: y
  11. Install the CUDA 8.0 Samples?
  12. (y)es/(n)o/(q)uit: y
  13. Enter CUDA Samples Location
  14. [ default is /home/bg ]:
  1. sudo vi ~/.bashrc
  2. //insert the following lines
  3. export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
  4. export CUDA_HOME=/usr/local/cuda-8.0
  1. source ~/.bashrc
  1. cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
  2. sudo make
  3. sudo ./deviceQuery

STEP 3: Install Cudnn

  1. cd Downloads/
  2. tar -zxvf cudnn-8.0-linux-x64-v6.0.tgz
  3. sudo cp cuda/include/cudnn.h /usr/local/cuda-8.0/include
  4. sudo cp cuda/lib64/libcudnn* /usr/local/cuda-8.0/lib64
  5. sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda-8.0/lib64/libcudnn*

STEP 4-1: Install PyTorch via virtualenv


virtualenv is a tool to create isolated Python environments.
We recommend you to use it instead of "native" pip.

  1. sudo apt-get install python3-pip python3-dev python-virtualenv
  1. virtualenv --system-site-packages -p python3 targetDirectory

where targetDirectory specifies the top of the virtualenv tree, our instructions assume that targetDirectory is ~/deeplearning, but you may choose any directory.

  1. source ~/deeplearning/bin/activate

The preceding source command should change your prompt to the following:

  1. (deeplearning) bg@bg-cgi:~$
  1. (deeplearning) bg@bg-cgi:~$ easy_install -U pip
  1. pip3 install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl
  2. pip3 install torchvision

Then, just test the Warm Up demo:

  1. (deeplearning) bg@bg-cgi:~$ git clone https://github.com/2017-fall-DL-training-program/PyTorchWarmUp.git
  2. (deeplearning) bg@bg-cgi:~$ cd PyTorchWarmUp/
  3. (deeplearning) bg@bg-cgi:~/PyTorchWarmUp$ python3 CNN_MNIST_pytorch.py

After training(a few mins), you can see the following result:

  1. Train Epoch: 20 [58496/60000 (97%)] Loss: 0.012621
  2. Train Epoch: 20 [58624/60000 (98%)] Loss: 0.011611
  3. Train Epoch: 20 [58752/60000 (98%)] Loss: 0.010518
  4. Train Epoch: 20 [58880/60000 (98%)] Loss: 0.008049
  5. Train Epoch: 20 [59008/60000 (98%)] Loss: 0.042140
  6. Train Epoch: 20 [59136/60000 (99%)] Loss: 0.002592
  7. Train Epoch: 20 [59264/60000 (99%)] Loss: 0.003716
  8. Train Epoch: 20 [59392/60000 (99%)] Loss: 0.006034
  9. Train Epoch: 20 [59520/60000 (99%)] Loss: 0.015948
  10. Train Epoch: 20 [59648/60000 (99%)] Loss: 0.005287
  11. Train Epoch: 20 [59776/60000 (100%)] Loss: 0.039094
  12. Train Epoch: 20 [44928/60000 (100%)] Loss: 0.005245
  13. Test set: Average loss: 0.0271, Accuracy: 9908/10000 (99%)

STEP 4-2: Install TensorFlow via virtualenv

  1. (deeplearning) bg@bg-cgi:~$ pip install --upgrade tensorflow # for Python 2.7
  2. (deeplearning) bg@bg-cgi:~$ pip3 install --upgrade tensorflow # for Python 3.n
  3. (deeplearning) bg@bg-cgi:~$ pip install --upgrade tensorflow-gpu # for Python 2.7 and GPU
  4. (deeplearning) bg@bg-cgi:~$ pip3 install --upgrade tensorflow-gpu # for Python 3.n and GPU
  1. (deeplearning) bg@bg-cgi:~$ deactivate

To uninstall Pytorch(TensorFlow), simply remove the tree you created. For example:

  1. rm -r ~/deeplearning

Reference

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注