一、驱动安装
1、根据推荐选择NVIDIA驱动版本安装,安装后重启电脑
2、重启后检查NVIDIA驱动安装是否成功
-
查看关于“图形”,是否显示了NVIDIA
- 查看你的显卡驱动所使用的内核版本,命令:
cat /proc/driver/nvidia/version
cat /proc/driver/nvidia/version
NVRM version: NVIDIA UNIX x86_64 Kernel Module 455.45.01 Thu Nov 5 23:03:56 UTC 2020
GCC version: gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04)
- 查看本地驱动安装情况,命令:
cat /var/log/dpkg.log | grep nvidia
cat /var/log/dpkg.log | grep nvidia
2020-11-21 17:36:53 install libnvidia-cfg1-455:amd64 <无> 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 status half-installed libnvidia-cfg1-455:amd64 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 status unpacked libnvidia-cfg1-455:amd64 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 install libnvidia-common-455:all <无> 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 status half-installed libnvidia-common-455:all 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 status unpacked libnvidia-common-455:all 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 install libnvidia-compute-455:amd64 <无> 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:53 status half-installed libnvidia-compute-455:amd64 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:55 status unpacked libnvidia-compute-455:amd64 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:55 install libnvidia-compute-455:i386 <无> 455.38-0ubuntu0.20.04.1
2020-11-21 17:36:55 status half-installed libnvidia-compute-455:i386 455.38-0ubuntu0.20.04.1
***
或,命令:sudo dpkg --list | grep nvidia-*
sudo dpkg --list | grep nvidia-*
ii libnvidia-cfg1-455:amd64 455.45.01-0ubuntu1 amd64 NVIDIA binary OpenGL/GLX configuration library
ii libnvidia-common-455 455.45.01-0ubuntu1 all Shared files used by the NVIDIA libraries
ii libnvidia-compute-455:amd64 455.45.01-0ubuntu1 amd64 NVIDIA libcompute package
ii libnvidia-decode-455:amd64 455.45.01-0ubuntu1 amd64 NVIDIA Video Decoding runtime libraries
ii libnvidia-encode-455:amd64 455.45.01-0ubuntu1 amd64 NVENC Video Encoding runtime library
ii libnvidia-extra-455:amd64 455.45.01-0ubuntu1 amd64 Extra libraries for the NVIDIA driver
ii libnvidia-fbc1-455:amd64 455.45.01-0ubuntu1 amd64 NVIDIA OpenGL-based Framebuffer Capture runtime library
ii libnvidia-gl-455:amd64 455.45.01-0ubuntu1 amd64 NVIDIA OpenGL/GLX/EGL/GLES GLVND libraries and Vulkan ICD
ii libnvidia-ifr1-455:amd64 455.45.01-0ubuntu1 amd64 NVIDIA OpenGL-based Inband Frame Readback runtime library
ii nvidia-compute-utils-455 455.45.01-0ubuntu1 amd64 NVIDIA compute utilities
ii nvidia-dkms-455 455.45.01-0ubuntu1 amd64 NVIDIA DKMS package
ii nvidia-driver-455 455.45.01-0ubuntu1 amd64 NVIDIA driver metapackage
ii nvidia-kernel-common-455 455.45.01-0ubuntu1 amd64 Shared files used with the kernel module
ii nvidia-kernel-source-455 455.45.01-0ubuntu1 amd64 NVIDIA kernel source package
ii nvidia-modprobe 455.45.01-0ubuntu1 amd64 Load the NVIDIA kernel driver and create device files
ii nvidia-prime 0.8.14 all Tools to enable NVIDIA's Prime
ii nvidia-settings 455.45.01-0ubuntu1 amd64 Tool for configuring the NVIDIA graphics driver
ii nvidia-utils-455 455.45.01-0ubuntu1 amd64 NVIDIA driver support binaries
ii screen-resolution-extra 0.18build1 all Extension for the nvidia-settings control panel
ii xserver-xorg-video-nvidia-455 455.45.01-0ubuntu1 amd64 NVIDIA binary Xorg driver
二、CUDA安装,使用阿里镜像加速方式
wget https://mirrors.aliyun.com/nvidia-cuda/ubuntu2004/x86_64/cuda-ubuntu2004.pin
sudo mv cuda-ubuntu2004.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://mirrors.aliyun.com/nvidia-cuda/ubuntu2004/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://mirrors.aliyun.com/nvidia-cuda/ubuntu2004/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda
注意:使用sudo apt-get -y install cuda-11-1
方式安装时可能会导致错误:依赖: cuda-runtime-11-1 (>= 11.1.1) 但是它将不会被安装依赖: cuda-toolkit-11-1 (>= 11.1.1) 但是它将不会被安装依赖: cuda-demo-suite-11-1 (>= 11.1.74) 但是它将不会被安装
,使用aptitude
安装:
- 先安装aptitude
sudo apt-get install aptitude
- 再安装cuda
sudo aptitude install cuda
安装完成后,重启一下电脑
- 查看安装结果
ls -l /usr/local/
lrwxrwxrwx 1 root root 22 11月 22 11:09 cuda -> /etc/alternatives/cuda
lrwxrwxrwx 1 root root 25 11月 22 11:09 cuda-11 -> /etc/alternatives/cuda-11
- 配置环境变量,命令:
gedit ~/.bashrc
$ gedit ~/.bashrc
- 验证安装结果,命令:
nvcc --version
$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2020 NVIDIA Corporation
Built on Mon_Oct_12_20:09:46_PDT_2020
Cuda compilation tools, release 11.1, V11.1.105
Build cuda_11.1.TC455_06.29190527_0
三、Anaconda安装,默认Python3
- 下载地址页:https://www.anaconda.com/products/individual
- 点击下载
64-Bit (x86) Installer (529 MB) - 执行安装,命令:
bash Anaconda3-2020.11-Linux-x86_64.sh
按回车键,一直按住回车键,直到出现下图所示:
输入yes:
然后按回车键,出现下图的画面输入yes后自动添加环境变量
- 配置环境变量
gedit ~/.bashrc
底部添加,路径根据自己的实际情况进行修改
:
export PATH=/home/oem/anaconda3/bin{PATH}}`
刷新重新加载配置
source ~/.bashrc
查看版本
$ conda --version
conda 4.9.2
- 更换国内源,安装提速
可先执行conda config --set show_channel_urls yes
生成.condarc
文件之后再修改
conda config --set show_channel_urls yes
修改配置
gedit .condarc
替换内容:
channels:
- defaults
show_channel_urls: true
channel_alias: https://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
- 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
simpleitk: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
运行 conda clean -i 清除索引缓存,保证用的是镜像站提供的索引。
到这里已经完成安装。
# 创建 python38虚拟环境,python版本为3.8
conda create -n python38 python=3.8
# 激活环境
source activate
# 退出环境
source deactivate
# 切换环境
conda activate your-env-name
三、安装pytorch
- 版本地址选择:https://pytorch.org/get-started/locally/
- 安装
pytorch
conda install pytorch torchvision torchaudio cudatoolkit=11.0 -c pytorch
- 安装完成后,测试安装结果
$ python3
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.
>>> import torch
>>> x = torch.empty(5, 3)
>>> print(x)
tensor([[1.0966e+14, 4.5883e-41, 1.0966e+14],
[4.5883e-41, 1.0966e+14, 4.5883e-41],
[1.0968e+14, 4.5883e-41, 1.0966e+14],
[4.5883e-41, 1.0968e+14, 4.5883e-41],
[1.0968e+14, 4.5883e-41, 1.0968e+14]])
四、安装numpy、sklearn、yacs、tqdm
conda install numpy
conda install scikit-learn
conda install yacs
conda install tqdm
如果安装失败,另外一种源码安装
$ git clone https://github.com/rbgirshick/yacs.git
$ cd yacs
$ python setup.py install
五、安装NCCL
为了下载NCCL,请确保您已注册NVIDIA开发人员计划。
- 转到:NVIDIA NCCL主页。
- 点击下载。
- 完成简短调查,然后单击Submit。
- 接受条款和条件。显示NCCL的可用下载版本列表。
- 选择要安装的NCCL版本。显示可用资源列表。请参考以下各节,以根据所使用的Linux发行版选择正确的软件包。
Ubuntu
在Ubuntu上安装NCCL要求您首先将包含NCCL软件包的存储库添加到APT系统,然后通过APT安装NCCL软件包。有两个可用的存储库;本地存储库和网络存储库。建议选择后者以在发布新版本时轻松检索升级。
- 安装存储库。
- 对于本地NCCL 存储库:
sudo dpkg -i nccl-repo-<version>.deb
- 对于网络存储库:
sudo dpkg -i nvidia-machine-learning-repo-<version>.deb
- 更新APT数据库:
sudo apt update
- 安装 libnccl2与APT打包。此外,如果您需要使用NCCL编译应用程序,则可以安装 libnccl开发 包装:
注意:如果使用网络存储库,则以下命令将CUDA升级到最新版本。
sudo apt install libnccl2 libnccl-dev
如果您希望保留较旧版本的CUDA,请指定特定版本,例如:
sudo apt install libnccl2=2.4.8-1+cuda10.0 libnccl-dev=2.4.8-1+cuda10.0
请参阅下载页面以获取确切的软件包版本。
已知错误排查
(fastreid) oem@zxb:~/work/pwork/fast-reid$ python tools/train_net.py --config-file ./configs/Market1501/bagtricks_R50.yml --num-gpus 4
./fastreid/evaluation/rank.py:15: UserWarning: Cython rank evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython rank evaluation (very fast so highly recommended) is '
./fastreid/evaluation/roc.py:19: UserWarning: Cython roc evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython roc evaluation (very fast so highly recommended) is '
Command Line Args: Namespace(config_file='./configs/Market1501/bagtricks_R50.yml', dist_url='tcp://127.0.0.1:62767', eval_only=False, machine_rank=0, num_gpus=4, num_machines=1, opts=[], resume=False)
./fastreid/evaluation/rank.py:15: UserWarning: Cython rank evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython rank evaluation (very fast so highly recommended) is '
./fastreid/evaluation/rank.py:15: UserWarning: Cython rank evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython rank evaluation (very fast so highly recommended) is '
./fastreid/evaluation/rank.py:15: UserWarning: Cython rank evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython rank evaluation (very fast so highly recommended) is '
./fastreid/evaluation/rank.py:15: UserWarning: Cython rank evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython rank evaluation (very fast so highly recommended) is '
./fastreid/evaluation/roc.py:19: UserWarning: Cython roc evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython roc evaluation (very fast so highly recommended) is '
./fastreid/evaluation/roc.py:19: UserWarning: Cython roc evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython roc evaluation (very fast so highly recommended) is '
./fastreid/evaluation/roc.py:19: UserWarning: Cython roc evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython roc evaluation (very fast so highly recommended) is '
./fastreid/evaluation/roc.py:19: UserWarning: Cython roc evaluation (very fast so highly recommended) is unavailable, now use python evaluation.
'Cython roc evaluation (very fast so highly recommended) is '
Process group URL: tcp://127.0.0.1:62767
Process group URL: tcp://127.0.0.1:62767
Process group URL: tcp://127.0.0.1:62767
Process group URL: tcp://127.0.0.1:62767
Traceback (most recent call last):
File "tools/train_net.py", line 57, in <module>
args=(args,),
File "./fastreid/engine/launch.py", line 68, in launch
daemon=False,
File "/home/oem/anaconda3/envs/fastreid/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 199, in spawn
return start_processes(fn, args, nprocs, join, daemon, start_method='spawn')
File "/home/oem/anaconda3/envs/fastreid/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 157, in start_processes
while not context.join():
File "/home/oem/anaconda3/envs/fastreid/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 118, in join
raise Exception(msg)
Exception:
-- Process 2 terminated with the following error:
Traceback (most recent call last):
File "/home/oem/anaconda3/envs/fastreid/lib/python3.7/site-packages/torch/multiprocessing/spawn.py", line 19, in _wrap
fn(i, *args)
File "./fastreid/engine/launch.py", line 86, in _distributed_worker
raise e
File "./fastreid/engine/launch.py", line 81, in _distributed_worker
backend="NCCL", init_method=dist_url, world_size=world_size, rank=global_rank
File "/home/oem/anaconda3/envs/fastreid/lib/python3.7/site-packages/torch/distributed/distributed_c10d.py", line 442, in init_process_group
barrier()
File "/home/oem/anaconda3/envs/fastreid/lib/python3.7/site-packages/torch/distributed/distributed_c10d.py", line 1947, in barrier
work = _default_pg.barrier()
RuntimeError: NCCL error in: /opt/conda/conda-bld/pytorch_1603729047590/work/torch/lib/c10d/ProcessGroupNCCL.cpp:784, invalid usage, NCCL version 2.7.8
- 原因:NCCL 未安装或GPU数量设置错误
conda本地包安装
在想要安装 pytorch-1.2 时,安装pytorch官方指导,以管理员身份打开 Anaconda Prompt,输入以下命令进行安装
conda install pytorch torchvision cudatoolkit=10.0 -c pytorch
但是网速特别慢,过了一会儿后,显示以下信息
原因是网速太慢或被墙,导致安装失败,如何解决呢?
从该提示信息中,发现了安装包下载的网址为
https://conda.anaconda.org/pytorch/win-64/pytorch-1.2.0-py3.5_cuda100_cudnn7_1.tar.bz2
将该网址复制到浏览器的地址栏,将自动下载该地址包(前提是网络能穿墙)。
下载完后将该包放到 Anaconda3/pkgs 目录,或者移动到包所在的目录
执行以下命令可进行本地安装
conda install --use-local pytorch-1.2.0-py3.5_cuda100_cudnn7_1.tar.bz2
总结
以后遇到类似情况,可以先通过浏览器手动下载相应的包,然后利用conda install --use-local 进行本地安装
查看torch 和 CUDA版本
import torch
print(torch.__version__)
print(torch.cuda.is_available())
print(torch.version.cuda)
包安装
- pip批量导出包含环境中所有组件的requirements.txt文件
pip freeze > requirements.txt
- pip批量安装requirements.txt文件中包含的组件依赖
pip install -r requirements.txt
- conda批量导出包含环境中所有组件的requirements.txt文件
conda list -e > requirements.txt
- conda批量安装requirements.txt文件中包含的组件依赖
conda install --yes --file requirements.txt
- 安装opencv
pip install -i https://pypi.mirrors.ustc.edu.cn/simple/ opencv-python
查看 GPU 运行情况
- Linux
# -l 实时监控
nvidia-smi -l
- Windows
cd C:\Program Files\NVIDIA Corporation\NVSMI
# -l 实时监控
nvidia-smi.exe -l