RTX 3090的深度學習環境配置指南:Pytorch、TensorFlow、Keras。配置顯卡


最近剛入了3090,發現網上寫的各種環境配置相當混亂而且速度很慢。所以自己測了下速度最快的3090配置環境,歡迎補充!

基本環境(整個流程大約需要5分鍾甚至更少)

py37或py38
cuda11.1
tf2.5(tf-nightly)或 tf1.15.4
pytorch1.8
keras2.3

(1)安裝gcc

sudo apt install build-essential
gcc -v #查看gcc版本

(2)官網下載對應版本顯卡驅動及cuda:(以下版本對應11.1cuda,此處安裝cuda是為了tf的某個缺失的文件)

wget https://developer.download.nvidia.com/compute/cuda/11.1.0/local_installers/cuda_11.1.0_455.23.05_linux.run
sudo sh cuda_11.1.0_455.23.05_linux.run

(3)安裝Anaconda並換源

bash Anaconda3-5.2.0-Linux-x86_64.sh
vim ~/.bashrc
export PATH=/home/yukyin/anaconda3/bin:$PATH(在文件末尾處添加該語句) 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刪掉

(4)創建虛擬環境,一般用py37或py38(以下都在虛擬環境中操作)

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

(5)安裝pytorch

官網下載cuda11.1輪子:torch-1.8.1+cu111-cp38-cp38-linux_x86_64.whl

pip install torch-1.8.1+cu111-cp38-cp38-linux_x86_64.whl #在輪子所在的目錄下操作

(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
conda install cudatoolkit=11.0 cp /usr/local/cuda-11.1/targets/x86_64-linux/lib/libcusolver.so.11.0.0.74 /home/yukyin/anaconda3/envs/exp382/lib/ mv /home/yukyin/anaconda3/envs/exp382/lib/libcusolver.so.11.0.0.74 /home/yukyin/anaconda3/envs/exp382/lib/libcusolver.so.11.0

(7)裝tf1.15

pip install nvidia-pyindex -i http://pypi.douban.com/simple --trusted-host pypi.douban.com
pip install nvidia-tensorflow -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

(10)測試(使用cuda10.2也可以測試使用gpu,但貌似不能把數據寫入gpu)

pytorch

tensorflow-2.5或1.15.4

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()

后記:不需要單獨配cuda、cudnn,在虛擬環境里搞就行了。

 

 

 

 

 

 

 

 

參考:https://zhuanlan.zhihu.com/p/279401802


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM