Installing Torch 7 deep learning on Ubuntu 16.04

Make sure you have followed caffe setup if not atleast install Prerequisite packages from that post.

Step 1: install general dependencies

sudo apt-get install --no-install-recommends git software-properties-common

Step 2: gedit ~/.bashrc (append following lines) and restart terminal (source ~/.bashrc)

export TORCH_ROOT=~/torch

Step 3: Download Torch repo in that root location

git clone https://github.com/torch/distro.git $TORCH_ROOT --recursive

Step 4: Change directory to Torch folder

cd $TORCH_ROOT

Step 5: Install torch dependencies

./install-deps

Step 6: Now, lets install torch

./install.sh -b

Step 7: Install some extra dependencies after restarting terminal (source ~/.bashrc)

sudo apt-get install --no-install-recommends libhdf5-serial-dev liblmdb-dev

luarocks install tds
luarocks install "https://raw.github.com/deepmind/torch-hdf5/master/hdf5-0-0.rockspec"
luarocks install "https://raw.github.com/Neopallium/lua-pb/master/lua-pb-scm-0.rockspec"
luarocks install lightningmdb 0.9.18.1-1 LMDB_INCDIR=/usr/include LMDB_LIBDIR=/usr/lib/x86_64-linux-gnu

# If you have installed NCCL
luarocks install "https://raw.githubusercontent.com/ngimel/nccl.torch/master/nccl-scm-1.rockspec"

luarocks install nngraph 
luarocks install optim
luarocks install nn

If you’d like to train on an NVIDIA GPU using CUDA (this can be to about 15x faster), you’ll of course need the GPU, and you will have to install the CUDA Toolkit. Then get the cutorch and cunn packages:

luarocks install cutorch
luarocks install cunn

Aditionally to load caffe models in torch

luarocks install loadcaffe

Step 8: Install torch/demos from github by command:

git clone https://github.com/torch/demos

Go into the demos folder, then just run one of the demos:

th demos/train-on-cifar/train-on-cifar.lua

Training screenshot

torchtestupload

If you are using CUDA 10 and cuDNN 7 and having some issue. Please refer to my new post here.

19 thoughts on “Installing Torch 7 deep learning on Ubuntu 16.04

Add yours

  1. Great tancks for your post, it’s a great help to Install Torch on Ubuntu 16.04 !!!
    I’an in France and write in English it’s no ver easy for me.. but i’m a Deep Learning Enthusiast to !
    Best regards.
    Michel

  2. Hey,
    I am trying to install torch as per your direction on ubuntu 16.04. I tried on 17.04 as well and got the same error.

    In file included from ../include/lapacke_utils.h:37:0,
    from lapacke_cgelq2_work.c:34:
    ../include/lapacke.h:15893:21: internal compiler error: Segmentation fault
    lapack_int* lwork, lapack_int *info );
    ^
    And it is telling me to submit a full bug report.

    Any suggestion?

    Thanks,
    Suhas

    1. Try installing this packages for linear algebra.
      “sudo apt-get -y install libblas-dev libopenblas-dev libatlas-base-dev liblapack-dev gfortran”
      Its helpful to install packages as recommended for building caffe “https://dwijaybane.wordpress.com/2017/07/19/installing-caffe-on-ubuntu-16-04-with-cudnn-and-ffmpeg-nvenc-sdk/”

  3. Thanks for sharing!
    Worked perfectly on non-GPU system, but on the one with CUDA 8.0 I’m getting:
    ./install.sh -b
    Found CUDA on your machine. Installing CUDA packages
    Warning: unmatched variable LUALIB

    jopts=$(getconf _NPROCESSORS_CONF)

    echo “Building on $jopts cores”
    cmake -E make_directory build && cd build && cmake .. -DLUALIB= -DLUA_INCDIR=/home/luser/torch/install/include -DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS} -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=”/home/luser/torch/install/bin/..” -DCMAKE_INSTALL_PREFIX=”/home/luser/torch/install/lib/luarocks/rocks/cutorch/scm-1″ && make -j$jopts install

    Building on 8 cores
    — The C compiler identification is GNU 5.4.0
    — The CXX compiler identification is GNU 5.4.0
    — Check for working C compiler: /usr/bin/cc
    — Check for working C compiler: /usr/bin/cc — works
    — Detecting C compiler ABI info
    — Detecting C compiler ABI info – done
    — Detecting C compile features
    — Detecting C compile features – done
    — Check for working CXX compiler: /usr/bin/c++
    — Check for working CXX compiler: /usr/bin/c++ — works
    — Detecting CXX compiler ABI info
    — Detecting CXX compiler ABI info – done
    — Detecting CXX compile features
    — Detecting CXX compile features – done
    — Found Torch7 in /home/luser/torch/install
    CMake Error at /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
    Could NOT find CUDA (missing: CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (found
    suitable version “8.0”, minimum required is “6.5”)
    Call Stack (most recent call first):
    /usr/share/cmake-3.5/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
    /home/luser/torch/install/share/cmake/torch/FindCUDA.cmake:1009 (find_package_handle_standard_args)
    CMakeLists.txt:7 (FIND_PACKAGE)

    — Configuring incomplete, errors occurred!
    See also “/home/luser/torch/extra/cutorch/build/CMakeFiles/CMakeOutput.log”.

    Error: Build error: Failed building.

  4. And one more detail:
    nvcc –version
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2016 NVIDIA Corporation
    Built on Tue_Jan_10_13:22:03_CST_2017
    Cuda compilation tools, release 8.0, V8.0.61

    and:
    set |grep CUDA
    CUDA_CUDART_LIBRARY=/usr/local/cuda-8.0/targets/x86_64-linux/lib/libcudart.so
    CUDA_INCLUDE_DIRS=/usr/local/cuda-8.0/include
    CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda-8.0

    1. Make sure your ~/.bashrc file should include these following CUDA path variables:
      ———————————————————————————————————————-
      #CUDA home path
      export CUDA_HOME=/usr/local/cuda

      # CUDA Bin Path
      export PATH=/usr/local/cuda-8.0/bin:$PATH

      # CUDA Library Path
      export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH
      ———————————————————————————————————————-

      Then restart your machine and try again !!!

  5. Les paquets suivants contiennent des dépendances non satisfaites :
    libfftw3-dev : Dépend: libfftw3-double3 (= 3.3.4-2ubuntu1) mais 3.3.7-1 devra être installé
    Dépend: libfftw3-single3 (= 3.3.4-2ubuntu1) mais 3.3.7-1 devra être installé
    libgraphicsmagick1-dev : Dépend: libjpeg-dev
    Dépend: liblcms2-dev mais ne sera pas installé
    Dépend: libwmf-dev mais ne sera pas installé
    Dépend: libx11-dev mais ne sera pas installé
    Dépend: libsm-dev mais ne sera pas installé
    Dépend: libice-dev mais ne sera pas installé
    Dépend: libxext-dev mais ne sera pas installé
    Dépend: libxml2-dev mais ne sera pas installé
    Dépend: libfreetype6-dev mais ne sera pas installé
    Dépend: libtiff-dev
    Dépend: libjbig-dev mais ne sera pas installé
    Dépend: zlib1g-dev mais ne sera pas installé ou
    libz-dev
    Dépend: libpng-dev
    Dépend: libexif-dev mais ne sera pas installé
    Dépend: libbz2-dev mais ne sera pas installé
    Dépend: libltdl-dev mais ne sera pas installé
    E: Impossible de corriger les problèmes, des paquets défectueux sont en mode « garder en l’état ».

    I have this error (I’m French) when I use .\install-deps, can you help me please ?

  6. The following packages have unmet dependencies:
    libfftw3-dev : Depends: libfftw3-double3 (= 3.3.4-2ubuntu1) but 3.3.7-1 is to be installed
    Depends: libfftw3-single3 (= 3.3.4-2ubuntu1) but 3.3.7-1 is to be installed
    libgraphicsmagick1-dev : Depends: libjpeg-dev
    Depends: liblcms2-dev but it is not going to be installed
    Depends: libwmf-dev but it is not going to be installed
    Depends: libx11-dev but it is not going to be installed
    Depends: libsm-dev but it is not going to be installed
    Depends: libice-dev but it is not going to be installed
    Depends: libxext-dev but it is not going to be installed
    Depends: libxml2-dev but it is not going to be installed
    Depends: libfreetype6-dev but it is not going to be installed
    Depends: libtiff-dev
    Depends: libjbig-dev but it is not going to be installed
    Depends: zlib1g-dev but it is not going to be installed or
    libz-dev
    Depends: libpng-dev
    Depends: libexif-dev but it is not going to be installed
    Depends: libbz2-dev but it is not going to be installed
    Depends: libltdl-dev but it is not going to be installed
    E: Unable to correct problems, you have held broken packages.

    (in english)

    1. Whenever you have any dependencies … make sure to install them …
      libfftw3-dev : Depends: libfftw3-double3 (= 3.3.4-2ubuntu1) but 3.3.7-1 is to be installed
      Depends: libfftw3-single3 (= 3.3.4-2ubuntu1) but 3.3.7-1 is to be installed
      libgraphicsmagick1-dev : Depends: libjpeg-dev

      So try installing these dependencies and try again…

  7. CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
    Please set them or make sure they are set and tested correctly in the CMake files:
    CUDA_cublas_device_LIBRARY (ADVANCED)
    linked by target “THC” in directory /home/azra/torch/extra/cutorch/lib/THC

    — Configuring incomplete, errors occurred!
    See also “/home/azra/torch/extra/cutorch/build/CMakeFiles/CMakeOutput.log”.
    See also “/home/azra/torch/extra/cutorch/build/CMakeFiles/CMakeError.log”.

    Error: Build error: Failed building.

Leave a reply to Anthony Cancel reply

Blog at WordPress.com.

Up ↑