Skip to content

Commit

Permalink
commit #27: add install tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
BIGBALLON committed Apr 22, 2018
1 parent a82cfa9 commit 61a26e9
Show file tree
Hide file tree
Showing 5 changed files with 370 additions and 0 deletions.
132 changes: 132 additions & 0 deletions doc/OpenAI-gym-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
# OpenAI Gym Install & Setting

Assume we already installed all of deep learning packages we need(tf, pytorch etc.)


## Install openai-gym


In order to install openai-gym, we should setup the following packages:

```
sudo apt install cmake swig zlib1g-dev python3-tk -y
```

To save videos, we aslo need to install ffmpeg

```
sudo apt install ffmpeg
```

Then, we can setup openai-gym by the following commands:

```
git clone https://github.com/openai/gym
cd gym
pip3 install gym[all]
```

## Use fake screen to get videos


Because remote server has no display device, we can't see the training process and save videos.
So we will use the following method to get the remote screen.


- Change GPU fan setting

```
sudo nvidia-xconfig -a --cool-bits=4
```


- Download the file [dfp-edid.bin][1] & move it to ``/etc/``

- Open xorg.conf

```
sudo vim /etc/X11/xorg.conf
```

- Insert the following three lines in each Section "Screen":

![screen][2]

```
Option "UseDisplayDevice" "DFP-0"
Option "ConnectedMonitor" "DFP-0"
Option "CustomEDID" "DFP-0:/etc/dfp-edid.bin"
```

- Restart X server(ex. lightdm)

```
sudo service lightdm restart
```

- Auto login setting

bulid(or modify) file ``vim /etc/lightdm/lightdm.conf``
write the following lines:

```
[Seat:*]
autologin-guest=false
autologin-user=username
autologin-user-timeout=0
```
then restart X server again.

- Install anydesk
- Download & upload to your server(via sftp, scp or using wget etc.)
- Install deb: ``sudo dpkg -i anydesk.XXX.deb``
- Set password: ``anydesk --set-password``
- Get ID: ``anydesk --get-id``
- run anydesk ``anydesk``
- (optinal) if it still doesn't work, try to use cmd ``export DISPLAY=:0``


## Use AnyDesk


- Download AnyDesk from [official website][3], windowsx64 version in this tutorial.
- Double click to run the application(no need to install).
- Enter the ID we got from remote server.
- Enter the password.
- Then,you can see the remote desktop, enjoy it!

![anydesk][4]


## Run an simple code

```
import gym
env = gym.make('CartPole-v0')
env.reset()
for _ in range(1000):
env.render()
env.step(env.action_space.sample()) # take a random action
```

You can see the environment works fine!
Take it easy!


![run][5]

## Reference


- [OpenAI Documentation][6]
- [Command Line Interface][7]


[1]: https://1drv.ms/u/s!AiF_YAjgP2iqmUKHkH7t8lzlz9aO
[2]: ./img/screen.png
[3]: https://anydesk.com/platforms
[4]: ./img/anydesk.png
[5]: ./img/run.png
[6]: https://gym.openai.com/docs/
[7]: http://support.anydesk.com/knowledgebase/articles/441867-command-line-interface
238 changes: 238 additions & 0 deletions doc/PyTorch-install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# NVIDIA Driver & Pytorch installation

The simple setup tutorial for deep learning beginner.

## STEP 1: Install NVIDIA Driver


```
sudo apt-get update
sudo apt-get upgrade
```

- Disable Nouveau

```
sudo vi /etc/modprobe.d/disable-nouveau.conf
//insert the following lines
blacklist nouveau
options nouveau modeset=0
```

- Update kernel initramfs

```
sudo update-initramfs -u
sudo reboot
```

- Install NVIDIA driver

> hit **Ctrl+Alt+F1(tty1)** and login, stop lightdm service & install dirver
```
sudo service lightdm stop
sudo apt-get install nvidia-375
sudo reboot
```

(optional)To install latest drivers add PPA:

```
sudo apt-get purge nvidia-*
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt-get update
sudo apt-get install nvidia-3xx
```

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

## STEP 2: Install CUDA 8.0

- Download setup file from [official website][1]
- The latest release version is 9.0, but we use [CUDA 8.0][2] ``cuda_8.0.61_375.26_linux.run``


```
cd Downloads/
sudo chmod a+x cuda_8.0.61_375.26_linux.run
sudo ./cuda_8.0.61_375.26_linux.run
```

- Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
- (**Attention!**) Please input **no**

```
Do you accept the previously read EULA?
accept/decline/quit: accept
Install NVIDIA Accelerated Graphics Driver for Linux-x86_64 375.26?
(y)es/(n)o/(q)uit: no
Install the CUDA 8.0 Toolkit?
(y)es/(n)o/(q)uit: y
Enter Toolkit Location
[ default is /usr/local/cuda-8.0 ]:
Do you want to install a symbolic link at /usr/local/cuda?
(y)es/(n)o/(q)uit: y
Install the CUDA 8.0 Samples?
(y)es/(n)o/(q)uit: y
Enter CUDA Samples Location
[ default is /home/bg ]:
```

- Set up the environment

```
sudo vi ~/.bashrc
//insert the following lines
export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64
export CUDA_HOME=/usr/local/cuda-8.0
```

- Reload .bashrc

```
source ~/.bashrc
```

- (optional)You can also test CUDA Samples

```
cd /usr/local/cuda-8.0/samples/1_Utilities/deviceQuery
sudo make
sudo ./deviceQuery
```

## STEP 3: Install Cudnn


- Download cuDNN files from [official website][3] (need to login, ``cuDNN v6.0 for CUDA 8.0`` in this tutorial)

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

## STEP 4-1: Install [PyTorch][4] via virtualenv

----------

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

- 1) Install pip and virtualenv(python3)

```
sudo apt-get install python3-pip python3-dev python-virtualenv
```

- 2) Create a virtualenv environment:
```
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.

- 3) Activate the virtualenv environment:

```
source ~/deeplearning/bin/activate
```

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

```
(deeplearning) bg@bg-cgi:~$
```

- 4) Ensure pip ≥8.1 is installed:

```
(deeplearning) bg@bg-cgi:~$ easy_install -U pip
```

- 5) Run this command to install Pytorch(python3.5):

```
pip3 install http://download.pytorch.org/whl/cu80/torch-0.2.0.post3-cp35-cp35m-manylinux1_x86_64.whl
pip3 install torchvision
```

Then, just test the Warm Up demo:

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

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

```
Train Epoch: 20 [58496/60000 (97%)] Loss: 0.012621
Train Epoch: 20 [58624/60000 (98%)] Loss: 0.011611
Train Epoch: 20 [58752/60000 (98%)] Loss: 0.010518
Train Epoch: 20 [58880/60000 (98%)] Loss: 0.008049
Train Epoch: 20 [59008/60000 (98%)] Loss: 0.042140
Train Epoch: 20 [59136/60000 (99%)] Loss: 0.002592
Train Epoch: 20 [59264/60000 (99%)] Loss: 0.003716
Train Epoch: 20 [59392/60000 (99%)] Loss: 0.006034
Train Epoch: 20 [59520/60000 (99%)] Loss: 0.015948
Train Epoch: 20 [59648/60000 (99%)] Loss: 0.005287
Train Epoch: 20 [59776/60000 (100%)] Loss: 0.039094
Train Epoch: 20 [44928/60000 (100%)] Loss: 0.005245
Test set: Average loss: 0.0271, Accuracy: 9908/10000 (99%)
```

## STEP 4-2: Install [TensorFlow][6] via virtualenv


- 1 - 4: same as PyTorch

- 5) Issue one of the following commands to install TensorFlow(GPU) in the active virtualenv environment:

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

- 6) When you are done using Pytorch(TensorFlow), you may deactivate the environment by invoking the deactivate function as follows:

```
(deeplearning) bg@bg-cgi:~$ deactivate
```


- 7) Uninstalling Pytorch(TensorFlow)

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

```
rm -r ~/deeplearning
```

## Reference

- [pytorch.org][7]
- [tensorflow install][8]


[1]: https://developer.nvidia.com/cuda-downloads
[2]: https://developer.nvidia.com/cuda-toolkit-archive
[3]: https://developer.nvidia.com/rdp/cudnn-download
[4]: http://pytorch.org/
[5]: https://github.com/pypa/virtualenv
[6]: https://www.tensorflow.org/install/
[7]: http://pytorch.org/
[8]: https://www.tensorflow.org/install/install_linux
Binary file added doc/img/anydesk.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/run.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/img/screen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 61a26e9

Please sign in to comment.