TensorFlow prepares the JupyterLab interactive notebook environment for writing code and taking notes as we go along.

Based on the environment

The following is the base environment for this article without going into detail about the installation process.

Ubuntu

  • Ubuntu 18.04.5 LTS (Bionic Beaver)

    • Ubuntu – 18.04.5 – desktop – amd64. Iso

CUDA

  • CUDA 11.2.2

    • Cuda_11. 2.2 _460. 32.03 _linux. Run
  • CuDNN 8.1.1

    • Libcudnn8_8. 1.1.33-1 + cuda11.2 _amd64. Deb
    • Libcudnn8 – dev_8. 1.1.33-1 + cuda11.2 _amd64. Deb
    • Libcudnn8 – samples_8. 1.1.33-1 + cuda11.2 _amd64. Deb

Anaconda

  • Anaconda Python 3.8

    • Anaconda3-2020.11 – Linux – x86_64. Sh
conda activate base

Install JupyterLab

Anaconda is available in the Anaconda environment. See the following version:

jupyter --version

Otherwise, install as follows:

conda install -c conda-forge jupyterlab

Install TensorFlow

Create virtual environment TF, then PIP to install TensorFlow:

# create virtual environment
conda create -n tf python=3.8 -y
conda activate tf

# install tensorflow
pip install --upgrade pip
pip install tensorflow

Testing:

$ python - <<EOF
import tensorflow as tf
print(tf.__version__, tf.test.is_built_with_gpu_support())
print(tf.config.list_physical_devices('GPU'))
EOF
The 2021-04-01 11:18:17. 719061: I tensorflow stream_executor/platform/default/dso_loader. Cc: 49] Successfully the opened the dynamic library libcudart. So. 11.0 Against 2.4.1 True 11:18:18 2021-04-01. 437590: I tensorflow/compiler/jit/xla_cpu_device.cc:41] Not creating XLA devices, TF_XLA_ENABLE_XLA_DEVICES NOT SET 2021-04-01 11:18:18.437998: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcuda.so.1 The 2021-04-01 11:18:18. 458471: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2021-04-01 11:18:18.458996: I TensorFlow/Core/Common_Runtime/GPU/GPU_DEVICE.cc :1720] Found devices0 with properties: PcibusID: 0000:01:00.0 Name: GeForce RTX 2060 ComputeCapability: 7.5CorecLock: 1.35GHz Corecount: 30 DEVICEMorySize: 5.79 Gib DeviceMoryBandwidth: 245.91 Gib /s 2021-04-01 11:18:18.459034: I tensorflow stream_executor/platform/default/dso_loader. Cc: 49] Successfully the opened the dynamic library libcudart. So. 11.0 The 2021-04-01 11:18:18. 461332: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublas.so.11 The 2021-04-01 11:18:18. 461362: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcublasLt.so.11 The 2021-04-01 11:18:18. 462072: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcufft.so.10 The 2021-04-01 11:18:18. 462200: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcurand.so.10 The 2021-04-01 11:18:18. 462745: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusolver.so.10 The 2021-04-01 11:18:18. 463241: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcusparse.so.11 The 2021-04-01 11:18:18. 463353: I tensorflow/stream_executor/platform/default/dso_loader.cc:49] Successfully opened dynamic library libcudnn.so.8 The 2021-04-01 11:18:18. 463415: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2021-04-01 11:18:18.463854: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:941] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero 2021-04-01 11:18:18.464170: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1862] Adding visible gpu devices: 0 [PhysicalDevice(name='/physical_device:GPU:0', device_type='GPU')]

Solution: Could not load dynamic library ‘libcusolver.so.10’

cd /usr/local/cuda/lib64
sudo ln -sf libcusolver.so.11 libcusolver.so.10

Install IPython kernel

In the virtual environment tf, install ipykernel to interact with Jupyter.

# install ipykernel (conda new environment)
conda activate tf
conda install ipykernel -y
python -m ipykernel install --user --name tf --display-name "Python TF"

# run JupyterLab (conda base environment with JupyterLab)
conda activate base
jupyter lab

Alternatively, you can use the nb_conda extension, which activates the Conda environment in the note:

# install ipykernel (conda new environment)
conda activate tf
conda install ipykernel -y

# install nb_conda (conda base environment with JupyterLab)
conda activate base
conda install nb_conda -y
# run JupyterLab
jupyter lab

Finally, visit http://localhost:8888/ :

reference

  • Install TensorFlow 2

    • Build from source
    • GPU support
  • Install TensorFlow – Anaconda

    • anaconda / packages / tensorflow
  • Installing the IPython kernel

Gocoding personal practice experience sharing, can pay attention to the public number!