Installing MXNet on Ubuntu¶
The following installation instructions are for installing MXNet on computers running Ubuntu 16.04. Support for later versions of Ubuntu is not yet available.
CUDA Dependencies¶
If you plan to build with GPU, you need to set up the environment for CUDA and cuDNN.
First, download and install CUDA toolkit. CUDA 9.2 is recommended.
Then download cuDNN 7.1.4.
Unzip the file and change to the cuDNN root directory. Move the header and libraries to your local CUDA Toolkit folder:
tar xvzf cudnn-9.2-linux-x64-v7.1
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*
sudo ldconfig
Quick Installation¶
Install MXNet for Python¶
Dependencies¶
The following scripts will install Ubuntu 16.04 dependencies for MXNet Python development.
wget https://raw.githubusercontent.com/apache/incubator-mxnet/master/ci/docker/install/ubuntu_core.sh
wget https://raw.githubusercontent.com/apache/incubator-mxnet/master/ci/docker/install/ubuntu_python.sh
sudo ./ubuntu_core.sh
sudo ./ubuntu_python.sh
Using the latest MXNet with CUDA 9.2 package is recommended for the fastest training speeds with MXNet.
Recommended for training:
pip install mxnet-cu92
Recommended for inference:
pip install mxnet-cu92mkl
Alternatively, you can use the table below to select the package that suits your purpose.
pip Package Availability¶
The following table presents the pip packages that are recommended for each version of MXNet.
To install an older version of MXNet with one of the packages in the previous table add ==
with the version you require. For example for version 1.1.0 of MXNet with CUDA 8, you would use pip install mxnet-cu80==1.1.0
.
Build MXNet from Source¶
You can build MXNet from source, and then you have the option of installing language-specific bindings, such as Scala, Julia, R or Perl. This is a two-step process:
- Build the shared library from the MXNet C++ source code.
- (optional) Install the supported language-specific packages for MXNet. Be sure to check that section first, as some scripts may be available to handle all of the dependencies, MXNet build, and language bindings for you. Here they are again for quick access:
Note: To change the compilation options for your build, edit the make/config.mk
file prior to building MXNet. More information on this is mentioned in the different language package instructions.
Installing Language Packages for MXNet¶
After you have installed the MXNet core library. You may install MXNet interface packages for the programming language of your choice:
Install the MXNet Package for Scala¶
To use the MXNet-Scala package, you can acquire the Maven package as a dependency.
Further information is in the MXNet-Scala Setup Instructions.
If you use IntelliJ or a similar IDE, you may want to follow the MXNet-Scala on IntelliJ tutorial instead.
Install the MXNet Package for R¶
Building MXNet from source is a 2 step process.
- Build the MXNet core shared library,
libmxnet.so
, from source. - Build the R bindings.
Quick MXNet-R Installation¶
You can quickly build MXNet-R with the following two scripts found in the /docs/install
folder:
git clone --recursive https://github.com/apache/incubator-mxnet.git mxnet
cd mxnet/docs/install
./install_mxnet_ubuntu_python.sh
./install_mxnet_ubuntu_r.sh
Or you can go through a manual process described next.
Manual MXNet-R Installation¶
Minimum Requirements
Build the MXNet core shared library
Step 1 Install build tools and git.
$ sudo apt-get update
$ sudo apt-get install -y build-essential git
Step 2 Install OpenBLAS.
MXNet uses BLAS and LAPACK libraries for accelerated numerical computations on CPU machine. There are several flavors of BLAS/LAPACK libraries - OpenBLAS, ATLAS and MKL. In this step we install OpenBLAS. You can choose to install ATLAS or MKL.
$ sudo apt-get install -y libopenblas-dev liblapack-dev
Step 3 Install OpenCV.
MXNet uses OpenCV for efficient image loading and augmentation operations.
$ sudo apt-get install -y libopencv-dev
Step 4 Download MXNet sources and build MXNet core shared library. You can clone the repository as described in the following code block, or you may try the download links for your desired MXNet version.
$ git clone --recursive https://github.com/apache/incubator-mxnet
$ cd incubator-mxnet
$ make -j $(nproc) USE_OPENCV=1 USE_BLAS=openblas
Note - USE_OPENCV and USE_BLAS are make file flags to set compilation options to use OpenCV and BLAS library. You can explore and use more compilation options in make/config.mk
.
Step 5 Make and install the MXNet-R bindings.
$ make rpkg
Verify MXNet-R Installation¶
You can verify your MXNet-R installation as follows:
sudo -i R
At the R prompt enter the following:
library(mxnet)
a <- mx.nd.ones(c(2,3), ctx = mx.cpu())
b <- a * 2 + 1
b
You should see the following output:
[,1] [,2] [,3]
[1,] 3 3 3
[2,] 3 3 3
> quit()
Install the MXNet Package for Julia¶
The MXNet package for Julia is hosted in a separate repository, MXNet.jl, which is available on GitHub. To use Julia binding it with an existing libmxnet installation, set the MXNET_HOME
environment variable by running the following command:
export MXNET_HOME=/<path to>/libmxnet
The path to the existing libmxnet installation should be the root directory of libmxnet. In other words, you should be able to find the libmxnet.so
file at $MXNET_HOME/lib
. For example, if the root directory of libmxnet is ~
, you would run the following command:
export MXNET_HOME=/~/libmxnet
You might want to add this command to your ~/.bashrc
file. If you do, you can install the Julia package in the Julia console using the following command:
Pkg.add("MXNet")
For more details about installing and using MXNet with Julia, see the MXNet Julia documentation.
Install the MXNet Package for Scala¶
To use the MXNet-Scala package, you can acquire the Maven package as a dependency.
Further information is in the MXNet-Scala Setup Instructions.
If you use IntelliJ or a similar IDE, you may want to follow the MXNet-Scala on IntelliJ tutorial instead.
Install the MXNet Package for Perl¶
Before you build MXNet for Perl from source code, you must complete building the shared library. After you build the shared library, run the following command from the MXNet source root directory to build the MXNet Perl package:
sudo apt-get install libmouse-perl pdl cpanminus swig libgraphviz-perl
cpanm -q -L "${HOME}/perl5" Function::Parameters Hash::Ordered PDL::CCS
MXNET_HOME=${PWD}
export LD_LIBRARY_PATH=${MXNET_HOME}/lib
export PERL5LIB=${HOME}/perl5/lib/perl5
cd ${MXNET_HOME}/perl-package/AI-MXNetCAPI/
perl Makefile.PL INSTALL_BASE=${HOME}/perl5
make install
cd ${MXNET_HOME}/perl-package/AI-NNVMCAPI/
perl Makefile.PL INSTALL_BASE=${HOME}/perl5
make install
cd ${MXNET_HOME}/perl-package/AI-MXNet/
perl Makefile.PL INSTALL_BASE=${HOME}/perl5
make install
Contributions¶
You are more than welcome to contribute easy installation scripts for other operating systems and programming languages. See the community contributions page for further information.