RTX 3090的深度学习环境配置指南:Pytorch、TensorFlow、Keras

点击上方“AI遇见机器学习”,选择“星标”公众号
重磅干货,第一时间送达

来源 | 知乎

编辑 | 极市平台

作者 | Yukyin

最近刚入了3090,发现网上写的各种环境配置相当混乱而且速度很慢。所以自己测了下速度最快的3090配置环境,欢迎补充!

基本环境(整个流程大约需要5分钟甚至更少)

 
 
py37或py38
cuda11.0
cudnn8.0.4
tf2.5(tf-nightly)或 tf1.15.4
pytorch1.7
keras2.3

(1)官网下载,安装显卡驱动:

 
 
bash NVIDIA-Linux-x86_64-455.23.04.run

(2)安装Anaconda并换源

 
 
bash Anaconda3-5.2.0-Linux-x86_64.sh
vim ~/.bashrc
export PATH=/home/XXX/anaconda3/bin:$PATH(XXX为自己的用户名)(在文件末尾处添加该语句)
source ~/.bashrc


conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge 
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/
conda config --set show_channel_urls yes
之后vim ~/.condarc,把defaults删掉

(3)创建虚拟环境,一般用py37或py38(以下都在虚拟环境中操作)

 
 
conda create -n exp38 python==3.8
conda activate exp38

(4)安装cuda11.0和pytorch1.7(不用再conda install cudatoolkit==11.0)

conda install pytorch torchvision cudatoolkit=11

(5)安装cudnn8(因为conda还不支持cudatoolkit=11中下载cudnn)

从https://developer.nvidia.com/rdp/cudnn-download下载cudnn,解压后进入cuda/lib64路径下,把里面所有文件拷入对应虚拟环境(exp38)的lib中

(6)装tf2.5(不要装tensorflow-gpu==2.4.0rc0,会报错'NoneType' object has no attribute 'TFE_MonitoringDeleteBuckets')

pip install tf-nightly-gpu -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install tf-nightly -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

(7)装tf1.15.4

此处参考这位大佬的tf1.15.4安装步骤
https://blog.csdn.net/wu496963386/article/details/109583045?utm_medium=distribute.wap_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-2.wap_blog_relevant_pic

pip install google_pasta-0.2.0-py3-none-any.whl nvidia_cublas-11.2.1.74-cp36-cp36m-linux_x86_64.whl nvidia_cuda_cupti-11.1.69-cp36-cp36m-linux_x86_64.whl nvidia_cuda_nvcc-11.1.74-cp36-cp36m-linux_x86_64.whl nvidia_cuda_nvrtc-11.1.74-cp36-cp36m-linux_x86_64.whl nvidia_cuda_runtime-11.1.74-cp36-cp36m-linux_x86_64.whl nvidia_cudnn-8.0.4.30-cp36-cp36m-linux_x86_64.whl nvidia_cufft-10.3.0.74-cp36-cp36m-linux_x86_64.whl nvidia_curand-10.2.2.74-cp36-cp36m-linux_x86_64.whl nvidia_cusolver-11.0.0.74-cp36-cp36m-linux_x86_64.whl nvidia_cusparse-11.2.0.275-cp36-cp36m-linux_x86_64.whl nvidia_dali_cuda110-0.26.0-1608709-py3-none-manylinux2014_x86_64.whl nvidia_dali_nvtf_plugin-0.26.0+nv20.10-cp36-cp36m-linux_x86_64.whl nvidia_nccl-2.7.8-cp36-cp36m-linux_x86_64.whl  nvidia_tensorrt-7.2.1.4-cp36-none-linux_x86_64.whl tensorflow_estimator-1.15.1-py2.py3-none-any.whl nvidia_tensorboard-1.15.0+nv20.10-py3-none-any.whl
nvidia_tensorflow-1.15.4+nv20.10-cp36-cp36m-linux_x86_64.whl -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

(8)装keras2.3

pip install keras==2.3 -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

(9)测试(使用cuda10.2也可以测试使用gpu,但貌似不能把数据写入gpu)

bacf03c78086e237f6e25b1bcc0cf0e3.png

pytorch

61bd3c65f288315e8b9b228acd802203.png

tensorflow-2.5或1.15.4

feccb2608f5e21b50fb370b46c76f515.png bf9ff6ed30744f125e7545c8ac5ee72a.png

keras(测试需要改部分源码_get_available_gpus())

 
 
import tensorflow as tf
import keras.backend.tensorflow_backend as tfback
print("tf.__version__ is", tf.__version__)
print("tf.keras.__version__ is:", tf.keras.__version__)
 
def _get_available_gpus():
    if tfback._LOCAL_DEVICES is None:
        devices = tf.config.list_logical_devices()
        tfback._LOCAL_DEVICES = [x.name for x in devices]
    return [x for x in tfback._LOCAL_DEVICES if 'device:gpu' in x.lower()]
tfback._get_available_gpus = _get_available_gpus


from keras import backend as K
K.tensorflow_backend._get_available_gpus()
4e16b8067c5e6c50a1e5f4bfb49e18f7.png f2bf76c403757b99874b285b85f495a6.png

后记:实际3090需要cuda11.1,但pytorch和tf目前只支持11.0。而且讲真不需要单独配cuda、cudnn,在虚拟环境里搞就行了。

欢迎关注我们,看通俗干货

3b2e4bf48d10e08633aa80b6254bd0c6.png

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值