赞
踩
众所周知的,Mindspore的GPU版本只能在Linux系统上使用。并且VMWare虚拟机无法使用主机的GPU资源,除非显卡支持虚拟化。以下是两种解决方案:
参考:
开启Linux子系统:
wsl -l -v
查看分配给每个已安装的 Linux 分发版的 WSL 版本;至此,Linux子系统开启完毕。使用GPU需要升级到WSL2:
wsl --set-version Ubuntu 2
设置WSL版本为2。Windows端更新支持WSL的显卡驱动:
nvidia-smi
,结果一致即可。-gpus all
命令即可允许容器使用主机GPU;nvidia-smi
,与主机结果一致即可;docker pull ubuntu:18.04
docker run --gpus all -it ubuntu:18.04 /bin/bash
vim /etc/ssh/sshd_config
→修改 PermitRootLogin yes
→service ssh start
重启服务;ipconfig
查看本机ip地址;IP:50001
登陆即可docker commit {Container ID} ubuntu-dl
docker run --gpus all -it -p 50001:22 ubuntu-dl /bin/bash
wget https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2022.10-Linux-x86_64.sh
bash ./Anaconda3-2022.10-Linux-x86_64.sh
export PATH=$PATH:/root/anaconda3/bin
conda create -n mindspore-py37 python=3.7
#解决CommandNotFoundError: Your shell has not been properly configured to use 'conda activate'.
source ~/anaconda3/etc/profile.d/conda.sh
conda activate mindspore-py37
安装CUDA11.1:
wget https://developer.download.nvidia.com/compute/cuda/11.1.1/local_installers/cuda_11.1.1_455.32.00_linux.run
sudo sh cuda_11.1.1_455.32.00_linux.run
echo -e "export PATH=/usr/local/cuda-11.1/bin:\$PATH" >> ~/.bashrc
echo -e "export LD_LIBRARY_PATH=/usr/local/cuda-11.1/lib64:\$LD_LIBRARY_PATH" >> ~/.bashrc
source ~/.bashrc
安装cuDNN8.7,下载→cuDNN Download:
tar -xf ./cudnn-linux-x86_64-8.7.0.84_cuda11-archive.tar.xz
chmod 666 /usr/local/cuda/include
cd ./cudnn-linux-x86_64-8.7.0.84_cuda11-archive
cp ./include/cudnn*.h /usr/local/cuda/include
cp ./lib/libcudnn* /usr/local/cuda/lib64
chmod a+r /usr/local/cuda/include/cudnn*.h /usr/local/cuda/lib64/libcudnn*
查看版本,测试安装是否成功:
(mindspore-py37) root:/# nvcc -V
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
(mindspore-py37) root:/# cat /usr/local/cuda/include/cudnn_version.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 8
#define CUDNN_MINOR 7
#define CUDNN_PATCHLEVEL 0
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
/* cannot use constexpr here since this is a C-only file */
在PyTorch官网寻找对应的版本,根据提供的命令安装即可。
我的环境是:CUDA=11.1,cuDNN=8.7.0,python=3.7;对应的pytorch版本为1.8。
注意:如果anaconda更换了清华源则不能使用conda安装,请使用pip。
具体原因可以参考torch.cuda.is_available()返回false——解决办法这篇博客,简单说就是清华源的问题。
pip install torch==1.8.0+cu111 torchvision==0.9.0+cu111 torchaudio==0.8.0 -f https://download.pytorch.org/whl/torch_stable.html
测试:
>>> import torch
>>> torch.cuda.is_available()
True
参考MindSpore官网即可,安装gcc和1.9版本的MindSpore。
apt-get install gcc -y
export MS_VERSION=1.9.0
# CUDA11.1 + Python3.7
pip install https://ms-release.obs.cn-north-4.myhuaweicloud.com/${MS_VERSION}/MindSpore/gpu/x86_64/cuda-11.1/mindspore_gpu-${MS_VERSION/-/}-cp37-cp37m-linux_x86_64.whl --trusted-host ms-release.obs.cn-north-4.myhuaweicloud.com -i https://pypi.tuna.tsinghua.edu.cn/simple
测试:
>>> import mindspore
>>> mindspore.run_check()
MindSpore version: 1.9.0
The result of multiplication calculation is correct, MindSpore has been installed successfully!
metrics (Union[dict, set]) - 用于模型评估的一组评价函数。例如:{‘accuracy’, ‘recall’}。默认值:None。
可以通过nn.names()
获取所有评价函数列表,如下:
>>> import mindspore
>>> names = mindspore.nn.names()
>>> print(names)
['F1', 'acc', 'accuracy', 'auc', 'bleu_score', 'confusion_matrix', 'confusion_matrix_metric', 'cosine_similarity', 'dice', 'hausdorff_distance', 'loss', 'mae', 'mean_surface_distance', 'mse', 'occlusion_sensitivity', 'perplexity', 'precision', 'recall', 'roc', 'root_mean_square_distance', 'top_1_accuracy', 'top_5_accuracy', 'topk']
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。