Skip to content

Instantly share code, notes, and snippets.

@pyaf
Created June 9, 2021 07:18
Show Gist options
  • Save pyaf/aeec1e489087abef105f9a0b3ea22da6 to your computer and use it in GitHub Desktop.
Save pyaf/aeec1e489087abef105f9a0b3ea22da6 to your computer and use it in GitHub Desktop.
TF 2.4 GPU Conda Setup
#!/bin/bash
# Initialize conda environment
echo 'Create Conda env? Type y or n and then press [ENTER]:'
read create_env
if [ $create_env = "y" ];
then
echo "Provide name for Conda virtualenv and then press [ENTER]:"
read env_name
conda create --name "$env_name" --yes python=3.8
echo "Activating the $env_name virtual environment"
conda init bash
conda activate "$env_name"
else
echo 'Installing tensorflow to default environment'
fi
echo 'Adding NVIDIA package repositories'
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
wget http://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt install ./nvidia-machine-learning-repo-ubuntu1804_1.0.0-1_amd64.deb
sudo apt-get update
echo 'Installing NVIDIA drivers'
sudo apt-get install --no-install-recommends nvidia-driver-450
# Reboot. Check that GPUs are visible using the command: nvidia-smi
wget https://developer.download.nvidia.com/compute/machine-learning/repos/ubuntu1804/x86_64/libnvinfer7_7.1.3-1+cuda11.0_amd64.deb
sudo apt install ./libnvinfer7_7.1.3-1+cuda11.0_amd64.deb
sudo apt-get update
echo 'Installing CUDA development and runtime libraries (~4GB)'
sudo apt-get install --no-install-recommends \
cuda-11-0 \
libcudnn8=8.0.4.30-1+cuda11.0 \
libcudnn8-dev=8.0.4.30-1+cuda11.0
echo 'Install TensorRT. Requires that libcudnn8 is installed above.'
sudo apt-get install -y --no-install-recommends libnvinfer7=7.1.3-1+cuda11.0 \
libnvinfer-dev=7.1.3-1+cuda11.0 \
libnvinfer-plugin7=7.1.3-1+cuda11.0
echo 'Upgrading Python pip installer and installing TensorFlow'
pip3 install --upgrade pip
pip3 install tensorflow==2.4
@pyaf
Copy link
Author

pyaf commented Jun 9, 2021

Reboot the system after running the script.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment