算力3.5显卡服务器:子用户通过conda安装cuda9.0+cudnn7.6.4+torch1.2.0+配置远程jupyter+tensorflow[可选]

算力3.5,现在绝大多数笔记本的独显都有了,我的是tesla k40m,这里提供如何安装cuda版本的torch,如果需要tensorflow也一起装了,下面是我的配置,供大家参考:

这几个版本一定要对应好:
python=3.6
cudatoolkit=9.0
cudnn=7.6.4
tensorflow-gpu==1.10.0
torch-1.2.0+cu92-cp36-cp36m-manylinux1_x86_64.whl
torchvision-0.4.0+cu92-cp36-cp36m-manylinux1_x86_64.whl
numpy==1.15.1
mkl-fft==1.0.6
pandas==1.0.0  # 一定要指定这个版本,否则默认装最新的pandas会升级numpy,然后tensorflow和torch就不可以用了

1. windows的话,清华源下载Anaconda3-2019.07-Linux-x86_64.sh,然后rz到服务器上(rz  是linux的一个指令,你在xshell中敲一下就知道干什么的了,为什么在windows下载,因为我这边服务器网速太慢),然后sh Anaconda3-2019.07-Linux-x86_64.sh一路到头,有yes/no输入yes,部分版本会问你是否需要安装VSCode,输入no;(如果清华源也很慢,就用北外源,https://mirrors.bfsu.edu.cn/anaconda/archive/

注:这个版本的Anaconda自带的Python是3.7的,因为我们要的是python36,包括如果已经装了anaconda,但是环境不是python3.6,可以用conda创建3.6环境,然后再切换到3.6环境:

conda create -n py36 python=3.6 # 新环境的名字叫py36,自定义
conda activate py36 # 切换到py36环境

如果conda指令报错 Solving environment: failed,输入指令以下后后重新使用conda即可:

conda config --set channel_priority flexible

2. vi ~/.condarc

channels:
  - defaults
show_channel_urls: true
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud

有时候清华源用的人太多,也卡,可以用清华源建设的备胎北外源,当然,如果北外用的多了,肯定以后也会卡,没办法:

channels:
  - defaults
show_channel_urls: true
default_channels:
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/main
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/free
  - https://mirrors.bfsu.edu.cn/anaconda/pkgs/r
custom_channels:
  conda-forge: https://mirrors.bfsu.edu.cn/anaconda/cloud
  msys2: https://mirrors.bfsu.edu.cn/anaconda/cloud
  bioconda: https://mirrors.bfsu.edu.cn/anaconda/cloud
  menpo: https://mirrors.bfsu.edu.cn/anaconda/cloud
  pytorch: https://mirrors.bfsu.edu.cn/anaconda/cloud
  simpleitk: https://mirrors.bfsu.edu.cn/anaconda/cloud

注:一般情况下,condarc文件出现在/home/user目录下,但有时会出现找不到情况,解决办法如下:

conda config --add channels r

即在/home/user目录下出现condarc文件,然后再vi ~/.condarc

3. 安装环境内的cuda环境,conda最好的就是不用本机安装CUDA,可以直接装,且对本机不影响,且conda每个python环境都互不影响

conda install cudatoolkit=9.0

注: cudatoolkit 不能用pip 装,而且是conda install cudatoolkit=9.0,不是conda install cudatoolkit==9.0 ,只有一个等于号!

注:conda: command not found解决办法

是因为~/.bashrc文件没有配置好,vi ~/.bashrc ,在最后一行加上

export PATH=$PATH:/home/yilin/anaconda3/bin

因为我的Linux用户名是yilin,anconda3是安装在/home/yilin/anaconda3/bin下面,所以你需要换成自己的安装目录,即

export PATH=$PATH:【你的安装目录】

然后保存更改,运行

source ~/.bashrc

此时再运行以下指令验证

conda info --envs # 出现所有的环境信息,即为成功

4. conda install cudnn=7.6.4

5. 下载 torch-1.2.0+cu92-cp36-cp36m-manylinux1_x86_64.whl 、torchvision-0.4.0+cu92-cp36-cp36m-manylinux1_x86_64.whl ,sz到服务器

pip install torch-1.2.0+cu92-cp36-cp36m-manylinux1_x86_64.whl 

pip install torchvision-0.4.0+cu92-cp36-cp36m-manylinux1_x86_64.whl

6. conda install jupyter

7. jupyter notebook --generate-config

8. vi ~/.jupyter/jupyter_notebook_config.py

按一下大写G,到底,按一下insert键盘

c.NotebookApp.ip = '*'
c.NotebookApp.password = 'sha1:a533db5b5e56:1b652a8ad120e7119471c*****5a79620'
c.NotebookApp.open_browser = False

# 指定端口号
c.NotebookApp.port = 8888

9. 生成密码回来替换上面文件的password:

In [1]: from notebook.auth import passwd
In [2]: passwd()
Enter password:
Verify password:
Out[2]: 'sha1:67c9e60bb8b6:9ffede0825894254b2e042ea597d771089e11aed'

10. nohup ~/anaconda3/bin/jupyter notebook &

注意:这一步尤为重要,如果直接jupyter notebook,可能是服务器root安装的Python,所以要用anaconda里面的jupyter。

11. 去浏览器输入http://服务器ip:8888/tree/,如果是本机,那服务器ip就是0.0.0.0

12. 如果服务器执行12的时候没问题,且服务器目录下的 nohup文件内容没有报错,但是本地就是连不上,那可能就是服务器开了防火墙(开了防火墙本地也可以ping通,但是连不上jupyter),关闭方法:

# 查看防火墙状态
firewall-cmd --state

# 停止firewall
systemctl stop firewalld.service

# 禁止firewall开机启动
systemctl disable firewalld.service 


tips:

1. pip -V 可以确认anaconda前后是否有变化

2. find -name jupyter

3. torch.cuda.is_available()
   torch.cuda.device_count()
   torch.cuda.get_device_name(0)
   torch.cuda.current_device()

转载请注明作者与地址:

版权声明:本文为CSDN博主「Maru_Lim」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Maru_Lim/article/details/109749052

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值