Skip to content

Instantly share code, notes, and snippets.

@Otteri
Created December 8, 2020 20:33
Show Gist options
  • Save Otteri/233a058a4ec5d31dc76bbcb50f7862dd to your computer and use it in GitHub Desktop.
Save Otteri/233a058a4ec5d31dc76bbcb50f7862dd to your computer and use it in GitHub Desktop.
Pytorch+cuda installation script for Ubuntu 20.04 LTS WSL
#!/bin/bash
# Installs Pytorch development environment
# on Ubuntu 20.04 LTS (WSL2) host machine
# First make sure that Windows GPU driver and WSL2 installations are ok,
# then launch WSL, create a new user and execute commands.
# Reference: https://docs.nvidia.com/cuda/wsl-user-guide/index.html
# 1) Install cuda stuff
sudo apt-key adv --fetch-keys http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/7fa2af80.pub
sudo sh -c 'echo "deb http://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" > /etc/apt/sources.list.d/cuda.list'
sudo apt-get update
sudo apt-get install -y cuda-toolkit-11-0
# 2) Verify that GPU can be found (optional step)
cd /usr/local/cuda/samples/1_Utilities/deviceQuery/
sudo make && ./deviceQuery && cd ~/
# 3) Install docker
curl https://get.docker.com | sh
sudo usermod -aG docker $USER
# 4) Install NVIDIA Container Toolkit
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add -
curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list
curl -s -L https://nvidia.github.io/libnvidia-container/experimental/$distribution/libnvidia-container-experimental.list | sudo tee /etc/apt/sources.list.d/libnvidia-container-experimental.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
# 5) Install Nvidia seasoned Pytorch docker container
sudo service docker start
sudo docker pull nvcr.io/nvidia/pytorch:20.11-py3
# 6) Launch the container
mkdir data
su - $USER # Reload docker group permissions, to be able to run docker
docker run --gpus all -it --rm -v /home/$USER/data:/workspace/data nvcr.io/nvidia/pytorch:20.11-py3
@Otteri
Copy link
Author

Otteri commented Mar 12, 2021

Additional optional steps:

If you plan to run GUI applications on WSL (e.g. matplotlib):
https://techcommunity.microsoft.com/t5/windows-dev-appconsult/running-wsl-gui-apps-on-windows-10/ba-p/1493242

Install jupyter with conda:
$ conda install jupyter
$ conda install -c miniconda ipykernel # this allows to use conda-env with notebook

Create env and then launch notebook with it:
$ python -m ipykernel install --user --name=yolo
Launch without browser: $ jupyter notebook --port=8889 --no-browser
(https://medium.com/@nrk25693/how-to-add-your-conda-environment-to-your-jupyter-notebook-in-just-4-steps-abeab8b8d084)

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