-
Notifications
You must be signed in to change notification settings - Fork 0
Environment setup for MXNet
There are many tutorials about how to install the Ubuntu system available, here are some simple steps to install Ubuntu through a USB boot drive.
Download Ubuntu 20.04 LTS image file here: https://releases.ubuntu.com/focal/
Use a USB boot drive creation tool such as Rufus to flash the downloaded images file to a USB drive to make an installation media of Ubuntu.
Boot from the USB and follow the prompts to install Ubuntu, it is recommended to select the option "Install third-party software for graphics and Wi-Fi hardware and additional media formats" during installation, this will automatically install the GPU driver.
Verify You Have a CUDA-Capable GPU
lspci | grep -i nvidia
Check if the Nvidia driver has been installed by running:
nvidia-smi
Or you can check and change the driver version under the "Additional driver" tab in the update manager (Type "additional driver" in the Ubuntu search bar to open). If nvidia-smi is not found, or no additional driver is found, you can install the Proprietary GPU Drivers from Nvidia through the terminal.
Adding the PPA repository:
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
Install the driver, you can change the driver version if needed, the latest PPA driver version can be found here: https://launchpad.net/~graphics-drivers/+archive/ubuntu/ppa
sudo apt install nvidia-driver-520
Install CUDA11.2
First, gcc is required for installing CUDA, run this command to install gcc
sudo apt install gcc
Then, download the CUDA 11.2 runfile installer. The reason for using the runfile installer is that we can deselect the graphics card driver, so the existing driver will not be overwritten.
wget https://developer.download.nvidia.com/compute/cuda/11.2.0/local_installers/cuda_11.2.0_460.27.04_linux.run
Install CUDA, and remember to deselect the graphic card driver to avoid overwriting the graphics card driver. It is a large file so it can take a while before the installation prompt shows up.
sudo sh cuda_11.2.0_460.27.04_linux.run
Add CUDA to the path
echo 'export PATH=/usr/local/cuda-11.2/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-11.2/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc
sudo ldconfig
Verify the CUDA version by running:
nvcc --version
Important: The version for CUDNN and NCCL needs to match the version of CUDA
Install CUDNN(v8.5.0) for CUDA11.2
You can find CUDNN for different CUDA versions here: https://developer.nvidia.com/rdp/cudnn-archive
Download the CUDNN tar file
wget https://developer.nvidia.com/compute/cudnn/secure/8.5.0/local_installers/11.7/cudnn-linux-x86_64-8.5.0.96_cuda11-archive.tar.xz
Extract the downloaded tar file to the home directory and rename it as cuda, then run the following commands to install CUDNN, this might take some time to complete.
sudo cp cuda/include/cudnn*.h /usr/local/cuda-11.2/include
sudo cp cuda/lib64/libcudnn* /usr/local/cuda-11.2/lib64/
sudo chmod a+r /usr/local/cuda-11.2/lib64/libcudnn*
You can check if CUDNN has been installed properly using this command
cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
Install NCCL(2.8.4) for CUDA11.2
You can find NCCL for different CUDA versions here: https://developer.nvidia.com/nccl/nccl-legacy-downloads
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/ /"
sudo apt-get update
Then run the following command to installer NCCL, you need to change the NCCL and CUDA version number if you are installing for a different version.
sudo apt install libnccl2=2.8.4-1+cuda11.2 libnccl-dev=2.8.4-1
System preparation for MXNet is now completed.
It is recommended to create a new environment for MXNet to avoid conflict with other deep learning backends. Anaconda is used here as an example, or you can use your preferred environment management software.
Download Anaconda from here: https://www.anaconda.com/download/#linux
Install Anaconda, and change the file name and location if required. Follow the prompts to complete the installation.
bash ~/Downloads/Anaconda3-2020.05-Linux-x86_64.sh
After installing Anaconda, open a new terminal, there should be a prefix "(base)" in the command line, indicating the Anaconda base environment is activated. If the prefix is not found, run this command and reopen the terminal.
conda config --set auto_activate_base True
Now run this command and follow the prompts to create a new environment for MXNet:
conda create -name mx python=3.9.12
Activate the new environment, then install MXNet and GluonCV:
conda activate mx
pip install --upgrade mxnet-cu112 gluoncv
Check the installed pip packaged:
pip list
You can validate MXNet installation by running the commands below, it might take a while to run depending on the performance of your PC.
python
import mxnet as mx
a = mx.nd.ones((2, 3),mx.gpu())
b = a * 2 + 1
b.asnumpy()
If no error occurs, you have successfully installed MXNet in the new environment.