Skip to content

Instantly share code, notes, and snippets.

@xiaoli
Last active May 14, 2024 14:40
Show Gist options
  • Save xiaoli/29271027ed9eab0b9bf80e02031b9f19 to your computer and use it in GitHub Desktop.
Save xiaoli/29271027ed9eab0b9bf80e02031b9f19 to your computer and use it in GitHub Desktop.
Ubuntu 22.04.1 LTS for Deep Learning

Ubuntu 22.04.1 LTS for Deep Learning

This gist contains steps to setup Ubuntu 22.04.1 LTS for deep learning.


Install Ubuntu 22.04.1 LTS

  • Computer name: Name-PC
  • Name: Name
  • User name: name
  • Password: ********

  • $ sudo dpkg -i google-chrome-stable_current_amd64.deb

Install Development Tools

  • $ sudo apt install git curl vim build-essential gcc-9 g++-9 python-is-python3 python3-virtualenv

Install Git

$ sudo apt install git
$ git config --global user.name "Name"
$ git config --global user.email "[email protected]"
$ git config --global core.editor "gedit -s"
  • Copy your own SSH keys to ~/.ssh/

Install NVIDIA Drivers for Deep Learning

Check Display Hardware:

  • $ sudo lshw -C display

Install NVIDIA GPU Driver:

  • Software & Updates > Additional Drivers > NVIDIA

Try $ sudo ubuntu-drivers autoinstall if NVIDIA drivers are disabled.

  • $ sudo apt install nvidia-cuda-toolkit

Install Miniconda

Install:

$ wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
$ chmod +x Miniconda3-latest-Linux-x86_64.sh

$ ./Miniconda3-latest-Linux-x86_64.sh

$ # Do you wish the installer to initialize Miniconda3
  # by running conda init?
  # yes

$ source ~/miniconda3/bin/activate 
$ conda config --set auto_activate_base false
$ conda deactivate

Activate and Deactivate:

$ conda activate
(base) $ conda deactivate

Managing conda:

(base) $ conda info
(base) $ conda update conda

Managing environments:

(base) $ conda info --envs

(base) $ conda create --name tfcpu python=3.6.5
(base) $ conda info --envs

(base) $ conda activate tfcpu

(tfcpu) $ python --version

(tfcpu) $ conda list

(tfcpu) $ conda deactivate

(base) $ conda remove --name tfcpu --all

(base) $ conda info --envs

Install requirements

conda install --file requirements.txt

Machine Learning Environment

$ conda create --name ml
$ conda activate ml
(ml) $ conda install numpy scipy matplotlib ipython jupyter pandas sympy nose
(ml) $ conda install scikit-learn scikit-image
(ml) $ conda deactivate

Deep Learning Environment (TensorFlow-CPU)

$ conda create --name tfcpu
$ conda activate tfcpu
(tfcpu) $ conda install tensorflow-cpu -c conda-forge
(tfcpu) $ conda deactivate

Verification:

$ conda activate tfcpu
(tfcpu) $ python
>>> import tensorflow as tf
>>> print(tf.reduce_sum(tf.random.normal([1000, 1000])))
>>> exit()
(tfcpu) $ conda deactivate

Deep Learning Environment (TensorFlow-GPU)

$ conda create --name tfgpu
$ conda activate tfgpu
(tfgpu) $ conda install tensorflow -c conda-forge
(tfgpu) $ conda install -c conda-forge cudatoolkit=11.7 cudnn=8.4.1
(tfgpu) $ conda deactivate

Verification:

$ conda activate tfgpu
(tfgpu) $ python
>>> from tensorflow.python.client import device_lib
>>> device_lib.list_local_devices()
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 3297645215030404954
xla_global_id: -1
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 23145480192
locality {
  bus_id: 1
  links {
  }
}
incarnation: 6369018557020505979
physical_device_desc: "device: 0, name: NVIDIA GeForce RTX 3090, pci bus id: 0000:41:00.0, compute capability: 8.6"
xla_global_id: 416903419
]
>>> exit()
(tfgpu) $ conda deactivate

Deep Learning Environment (PyTorch-CPU)

$ conda create --name torchcpu
$ conda activate torchcpu
(torchcpu) $ conda install pytorch torchvision torchaudio cpuonly -c pytorch
(torchcpu) $ conda deactivate

Deep Learning Environment (PyTorch-GPU)

$ conda create --name torchgpu
$ conda activate torchgpu
(torchgpu) $ conda install pytorch torchvision torchaudio cudatoolkit=11.6 -c pytorch -c conda-forge
(torchgpu) $ conda deactivate

Verification:

$ conda activate torchgpu
(torchgpu) $ python
>>> import torch
>>> torch.cuda.is_available()
True
>>> torch.cuda.device_count()
1
>>> torch.cuda.current_device()
0
>>> torch.cuda.device(0)
<torch.cuda.device object at 0x7e96e8a0bffd0>
>>> torch.cuda.get_device_name(0)
'NVIDIA GeForce RTX 3090'
>>> exit()
(torchgpu) $ conda deactivate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment