Hi there! Last month I finally completed my first Deep Learning, TensorFlow machine (an old pc pimped with Ubuntu, some ram and a fantastic GTX 1080 Ti). The installation is substantially easy, if you know what you are doing. However there are some steps that for a Mac user like me could be troublesome. So, here is how to do a completely clean install.
Some important notes
- This is not a guide, it is more like a set of tips I write here for future reference and to help. I do not know if this is the best way to install all this stuff. Some initial steps could differ if you are not a mac user.
- I am going to consider TensorFlow 1.2 which requires CuDNN version 5 (sadly!). Soon TensorFlow 1.3 will be released and that one will use CuDNN 6!
- 03-Ago-2017: created
- 06-Ago-2017: big changes. Version numbers are clearly stated, the steps order is changed and code is easier to read
- Ubuntu installation
- Fix the nomodeset
- Nvidia driver
- Cuda toolkit
- Let's fix the path
- A tip
- Let's try it
Let's begin! Ubuntu installation
- First of all, let's download Ubuntu. At the time of writing there are two versions available: 16.04LTS and 17.04. I suggest the 16.04LTS. LTS stands for Long Term Support, which in short means that you will not have to worry about updating your machine too soon, you will receive all the necessary security and bug-fixing updates. This version is the best if, like me, you are building an hard-working, pragmatic machine. So, go here and pick the LTS version
- Now let's create a bootable usb stick. Here the best thing to do is to follow this guide (there are also guides for Windows and for Ubuntu too)
- Connect the usb stick to the fully-mounted pc and turn it on, booting from the usb device you created before. Now, the first problem: if you try to start Ubuntu you will end up with a terrible "pink" screen. What the heck? This is due to Ubuntu that is trying to load video driver too early at kernel level. Sadly this does not work with our 1080Ti. Here is the work-around
- In the UNetbootin boot menu, press the TAB key
- Add nomodeset before quiet splash - - -, obtaining
nomodeset quiet splash - - -
- Now, complete the Ubuntu installation. The computer will reboot
- During the startup, press the SHIFT key, to enter in the GRUB menu
- Now press the "e" key to edit the launch configuration. In the text displayed, find again the "quiet splash" string and add nomodeset before it, obtaining
Then start Ubuntu. Everything should work fine
nomodeset quiet splash
Fix the nomodeset forever
- Open the grub configuration file:
sudo nano /etc/default/grub
- Add nomodeset to the GRUB_CMDLINE_LINUX_DEFAULT, obtaining:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash nomodeset"
- Save (CTRL + O) and exit (CTRL + X)
- Then run
- Restart the computer
- Done!!! Thanks to this answer
- Now the fun stuff. First thing, download the Nvidia driver for the 1080Ti (from here). It is a .run file.
- Make the downloaded file executable, with the command
chmod +x <filename>
- Now, stop the X serve (the GUI) using the command:
sudo service lightdm stop
- Wow, the screen is completely black. Now you have to open a shell. Try CTRL + ALT + [a key from F1 to F7]. A shell should appear. Do the login
- Now, using the shell locate the downloaded Nvidia file and run it (if you are in the same directory, do
- Choose to update the X configuration
- When finished, relaunch the X serve:
sudo service lightdm start
- Now, download Cuda version 8 from Nvidia: choose your system type and then Ubuntu. It should be a .run file
- Make again the file executable with the command
chmod +x <filename>
- Run it. Again, if you are in the same directory, do
- DO NOT INSTALL the drivers (we have installed them before). Install just the CUDA toolkit. Leave all the settings to their default. Add symlinks. Do not install examples
The Deep Learning library: CuDNN
- Download CuDNN from Nvidia. A registration is required.
- Attention: download the linux file (not the Ubuntu one!!!!!)
- Attention: download the 5.1 version
- Locate the downloaded file (should be a .tgz).
- Let's extract it:
tar -xvzf <filename>
- Now, let's copy the extracted files:
sudo cp -P cuda/include/cudnn.h /usr/local/cuda/include sudo cp -P cuda/lib64/libcudnn\* /usr/local/cuda/lib64 sudo chmod a+r /usr/local/cuda/include/cudnn.h /usr/local/cuda/lib64/libcudnn\*
- Download Anaconda for Linux (a .sh file) from here
- Execute it WITHOUT USING THE SUDO COMMAND:
- Done!!! Please note that Anaconda is not strictly required in order to do some Deep Learning stuff. However, I think< it is worth trying because it makes the life so easy by managing all the packages behind the scene./li>
To install tensorflow-gpu, simply follow the guide here. To summarize:
- First grab here the last Tensorflow GPU version (1.2 for this guide) url. At the moment of writing the url is this one
pip install --ignore-installed --upgrade <here the url>
- Note: there are so many good Deep Learning frameworks. Here I have considered only TensorFlow, but everything should work well even with other frameworks
Path and other
Now, the last edit.
- Go to the end of the file and locate the comment line "# added by Anaconda3 ..."
- Immediately after this line add this new line:
- After this new line, there is a single line like this:
- Edit this line to obtain (be careful with the various colons!!!!):
- After this line add another line:
- The final result should be:
export CUDA_HOME=/usr/local/cuda export PATH="/home/username/anaconda3/bin:$CUDA_HOME:$PATH" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$CUDA_HOME/lib64"
- Remember: you have to open a new Terminal window in order to see these edits
Sometimes numpy can give problems. A good thing to do before start playing with TensorFlow is to update it:
conda update numpy
Let's try it
Everything should work like a charm! To check if everything is working open a Terminal and start an Ipython session. Then type this:
import tensorflow as tf tf.Session().run(tf.constant(2))
Everything should work fine!
And that is it! Everything should work fine! Now you can do some Deep Learning stuff :) This post will be updated to improve its quality and to add everything useful I will discover in this long run. Have fun!