Alguns problemas que você pode encontrar ao usar o Servidor
- 1. Como encontrar a relação entre o modelo da GPU e a versão do driver?
- 2. Como verificar a versão atual do kernel do servidor?
- 3. Comandos que podem ser usados ao usar Nvidia
- 4. Algumas configurações do Jupyter Notebook
- 5. Operações gerais do TensorFlow
- 6. Algumas operações usando PyTorch
- 7. Modifique a fonte de instalação para um endereço doméstico
1. Como encontrar a relação entre o modelo da GPU e a versão do driver?
Ao instalar um novo driver CUDA, você precisa encontrar a versão do driver correspondente à GPU atual, que pode ser https://www.nvidia.com/Download/Find.aspx?lang=en-us
obtida fazendo login. A interface de login é a seguinte:
insira o modelo de GPU correspondente para obter o driver correspondente.
2. Como verificar a versão atual do kernel do servidor?
1) Veja a lista de kernel:
$ sudo dpkg --get-selections | grep linux-image
linux-image-5.0.0-23-generic deinstall
linux-image-5.0.0-25-generic deinstall
linux-image-5.0.0-27-generic deinstall
linux-image-5.0.0-29-generic deinstall
linux-image-5.0.0-31-generic deinstall
linux-image-5.0.0-32-generic deinstall
2) Verifique a versão do kernel usada atualmente:
$ uname -r
5.4.0-146-generic
3) Exclua kernels não usados atualmente:
$ sudo apt-get remove linux-image-***-generic
3. Comandos que podem ser usados ao usar Nvidia
1) Verifique as informações básicas da placa gráfica
$ nvidia-smi
Tue Sep 5 23:43:55 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 470.182.03 Driver Version: 470.182.03 CUDA Version: 11.4 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA TITAN X ... Off | 00000000:02:00.0 Off | N/A |
| 26% 46C P8 11W / 250W | 0MiB / 12196MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 1 NVIDIA TITAN X ... Off | 00000000:03:00.0 Off | N/A |
| 30% 52C P8 12W / 250W | 0MiB / 12196MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 2 NVIDIA TITAN X ... Off | 00000000:82:00.0 Off | N/A |
| 34% 58C P8 15W / 250W | 0MiB / 12196MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
| 3 NVIDIA TITAN X ... Off | 00000000:83:00.0 Off | N/A |
| 32% 55C P8 13W / 250W | 0MiB / 12196MiB | 0% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
| No running processes found |
+-----------------------------------------------------------------------------+
2) A relação correspondente entre o driver Nvidia e a versão de tempo de execução CUDA
pode ser verificada no site oficial da Nvidia, o endereço é: https://docs.nvidia.com/cuda/cuda-toolkit-release-notes/index.html
. A correspondência entre o driver mais recente e a versão de tempo de execução do CUDA é a seguinte:
3) Use o conda para instalar o TensorFlow.
Ao usar o Conda para instalar o Tensorflow-GPU, ele baixará automaticamente as dependências, como o CUDA e o cuDNN mais importantes.
Encontre o pacote TensorFlow :
$ conda search tensorflow
Instale o TensorFlow-GPU 2.4.1
$ conda install tensorflow-gpu=2.4.1
4) Use pip para instalar o TensorFlow
e instalar o cudatookit:
$ pip install cudatoolkit==11.8.0
Instale o cudnn:
$ pip install cudnn
Instale o TensorFlow-GPU 2.4.1:
$ pip install tensorflow-gpu==2.4.1
A versão específica será adaptada de acordo com a situação real! ! !
4. Algumas configurações do Jupyter Notebook
Algumas configurações do Jupyter Notebook podem facilitar nosso trabalho de desenvolvimento de código.
1) Gere arquivo de configuração
$ jupyter notebook --generate-config
O arquivo será gerado no diretório do usuário atual: .jupyter/jupyter_notebook_config.py
2) Gere a senha de login do usuário atual.
Abra o ipython e crie uma senha de texto cifrado:
$ ipython
Python 3.8.16 (default, Mar 2 2023, 03:21:46)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.12.2 -- An enhanced Interactive Python. Type '?' for help.
In [1]:from notebook.auth import passwd
In [2]:passwd()
Enter password:
Verify password:
3) Modifique o arquivo de configuração.
Modifique o arquivo de configuração da seguinte forma:
$ vim ~/.jupyter/jupyter_notebook_config.py
c.NotebookApp.ip = '*' # 设置所有ip皆可访问
c.NotebookApp.password = u'argon2:$argon....' # 粘贴上一步生成的密文
c.NotebookApp.open_browser = False # 禁止自动打开浏览器
c.NotebookApp.port = 8899 # 指定端口
4) Inicie o notebook Jupyter.
É melhor iniciá-lo em segundo plano sem gravar logs:
$ nohup jupyter notebook >/dev/null 2>&1 &
Em seguida, você pode inserir http://YOUIP:port no navegador para entrar na interface do notebook jupyter:
5. Operações gerais do TensorFlow
1) Verifique se a instalação do TensorFlow foi bem-sucedida:
$ python
Python 3.8.16 (default, Mar 2 2023, 03:21:46)
[GCC 11.2.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2023-09-06 00:18:25.800736: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-09-06 00:18:28.733394: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
>>> print(tf.__version__)
2.12.0
>>> print(tf.test.is_gpu_available())
WARNING:tensorflow:From <stdin>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version.
Instructions for updating:
Use `tf.config.list_physical_devices('GPU')` instead.
2023-09-06 00:19:04.284931: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1956] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
False
>>> print(tf.config.list_physical_devices('GPU'))
2023-09-06 00:19:26.509357: W tensorflow/core/common_runtime/gpu/gpu_device.cc:1956] Cannot dlopen some GPU libraries. Please make sure the missing libraries mentioned above are installed properly if you would like to use GPU. Follow the guide at https://www.tensorflow.org/install/gpu for how to download and setup the required libraries for your platform.
Skipping registering GPU devices...
[]
Se a execução normal for bem-sucedida, o número da GPU atualmente disponível será retornado. Aparentemente há um problema aqui, faltam algumas bibliotecas.
Observação: é recomendado usar conda para instalar o TensorFlow.
6. Algumas operações usando PyTorch
1) Faça login no site oficial do PyTorch e selecione a configuração de instalação.
Você pode escolher a versão mais recente ou seguir o link abaixo para escolher a versão mais antiga.
2) Instalar usando CUDA.
Aqui escolhemos instalar a versão v1.13.0 da GPU PyTorch baseada na versão CUDA.
# CUDA 11.6
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.6 -c pytorch -c nvidia
Caso não possa ser executado ou o download seja muito lento, você pode removê -c pytorch
-lo porque -c
o parâmetro especifica o canal de download do PyTorch, que tem prioridade maior que os espelhos domésticos.
3) Instale usando pip
# CUDA 11.6
pip install torch==1.13.0+cu116 torchvision==0.14.0+cu116 torchaudio==0.13.0 --extra-index-url https://download.pytorch.org/whl/cu116
5) Verifique se a instalação foi bem-sucedida
>>> import torch
>>> print(torch.__version__)
2.0.1+cu117
>>> print(torch.cuda.is_available())
True
7. Modifique a fonte de instalação para um endereço doméstico
1) Modifique a fonte de instalação do conda para fonte Tsinghua
, crie um arquivo no diretório atual do usuário .condarc
e coloque o seguinte conteúdo no arquivo:
channels:
- defaults
show_channel_urls: true
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
msys2: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
bioconda: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
menpo: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch-lts: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
deepmodeling: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/
2) Modifique a fonte de instalação do pip
e selecione a fonte Tsinghua aqui.
Uso temporário: pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
Definir como padrão:
python -m pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple