BlueEye

How to configure Python, PyTorch and TensorFlow?

Python

Python 3 is default installed on Ubuntu.
Check version python3:
python3 -V
or
python -V
We should get the same response on Ubuntu 20.04:
Next, we need install Conda package manager for Python:
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
sudo reboot
Now we can prepare dedicated enviroment for Python applications:
conda create -n my-example-env
Activate enviroment:
conda activate my-example-env
Deactivate enviroment:
conda deactivate

PyTorch

Create enviroment:
conda create -n pytorch-env
Activate enviroment:
conda activate pytorch-env
Install PyTorch with suported GPUs:
conda install pytorch-gpu
Now, run Python console:
python
and list PyTorch GPU devices:
import torch
for i in range(0, torch.cuda.device_count()):
print(torch.cuda.get_device_name(i))
If we have any device on list then installaton is ok.

TensorFlow

Create and activate enviroment
conda create -n tf-env
conda activate tf-env
Install TensorFlow with suported GPUs:
conda install tensorflow-gpu
Now, run Python console:
python
and list TensorFlow GPU devices:
from tensorflow.python.client import device_lib
device_lib.list_local_devices()
In my example I have list:
(tf-env) seba@blueeye:~$ python
Python 3.8.5 (default, Sep  4 2020, 07:30:14)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from tensorflow.python.client import device_lib

>>> device_lib.list_local_devices()
2020-10-21 19:59:45.924648: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
2020-10-21 19:59:46.118002: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2898240000 Hz
2020-10-21 19:59:46.125829: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x563809dfa800 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-10-21 19:59:46.125880: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host, Default Version
2020-10-21 19:59:46.282857: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-10-21 19:59:46.782287: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:46.782801: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties:
pciBusID: 0000:01:00.0 name: Tesla K20Xm computeCapability: 3.5
coreClock: 0.732GHz coreCount: 14 deviceMemorySize: 5.57GiB deviceMemoryBandwidth: 232.46GiB/s
2020-10-21 19:59:46.782889: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:46.783334: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 1 with properties:
pciBusID: 0000:02:00.0 name: Tesla K20Xm computeCapability: 3.5
coreClock: 0.732GHz coreCount: 14 deviceMemorySize: 5.57GiB deviceMemoryBandwidth: 232.46GiB/s
2020-10-21 19:59:46.803993: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-10-21 19:59:47.369147: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-10-21 19:59:47.660352: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-10-21 19:59:47.736191: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-10-21 19:59:48.354785: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-10-21 19:59:48.414624: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-10-21 19:59:49.404472: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-10-21 19:59:49.404780: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.406518: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.408116: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.409708: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.411181: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0, 1
2020-10-21 19:59:49.426791: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-10-21 19:59:49.442604: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-10-21 19:59:49.442649: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 1
2020-10-21 19:59:49.442665: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N Y
2020-10-21 19:59:49.442682: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 1:   Y N
2020-10-21 19:59:49.442977: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.444203: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.445396: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.446587: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.447681: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/device:GPU:0 with 5299 MB memory) -> physical GPU (device: 0, name: Tesla K20Xm, pci bus id: 0000:01:00.0, compute capability: 3.5)
2020-10-21 19:59:49.472187: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.473023: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:981] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2020-10-21 19:59:49.473872: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/device:GPU:1 with 5299 MB memory) -> physical GPU (device: 1, name: Tesla K20Xm, pci bus id: 0000:02:00.0, compute capability: 3.5)
2020-10-21 19:59:49.497974: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x56380b82ff20 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-10-21 19:59:49.498024: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Tesla K20Xm, Compute Capability 3.5
2020-10-21 19:59:49.498040: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (1): Tesla K20Xm, Compute Capability 3.5
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 17359870790592050054
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 1924305867903798958
physical_device_desc: "device: XLA_CPU device"
, name: "/device:GPU:0"
device_type: "GPU"
memory_limit: 5557036000
locality {
  bus_id: 1
  links {
    link {
      device_id: 1
      type: "StreamExecutor"
      strength: 1
    }
  }
}
incarnation: 1717249119449247050
physical_device_desc: "device: 0, name: Tesla K20Xm, pci bus id: 0000:01:00.0, compute capability: 3.5"
, name: "/device:GPU:1"
device_type: "GPU"
memory_limit: 5557036000
locality {
  bus_id: 1
  links {
    link {
      type: "StreamExecutor"
      strength: 1
    }
  }
}
incarnation: 2947898550070061296
physical_device_desc: "device: 1, name: Tesla K20Xm, pci bus id: 0000:02:00.0, compute capability: 3.5"
, name: "/device:XLA_GPU:0"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 16850640239424483047
physical_device_desc: "device: XLA_GPU device"
, name: "/device:XLA_GPU:1"
device_type: "XLA_GPU"
memory_limit: 17179869184
locality {
}
incarnation: 5119050475016557833
physical_device_desc: "device: XLA_GPU device"
]
>>>
if we are device name /device:GPU:0 on list then installation is ok.

Links