【Python】环境配置,【Pytorch】GPU版本安装

总结:
使用conda新建切换环境,然后使用pip安装卸载包

pip换源

https://blog.csdn.net/maotenghua/article/details/104188086

在当前用户目录下创建pip目录,即C:\Users\xxx\pip\ (xxx指代用户名),在pip目录下创建pip.ini文件,文件内容如下
( C:\Users\jcz\pip )

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn

conda换源

https://mirrors4.tuna.tsinghua.edu.cn/help/anaconda/

GPU版本

疑问

【参考:Python深度学习:安装Anaconda与PyTorch库(GPU版本)_哔哩哔哩_bilibili

【参考:为什么电脑装了pytorch没有安装cuda,还是能够使用gpu? - 知乎

【参考:Pytorch-gpu版安装教程【注意:无需提前安装cuda和cudnn】_pytorch一定要cuda吗_山风wind的博客-CSDN博客
在这里插入图片描述

在这里插入图片描述
但下载很容易断,所以请看方法二

方法一

  1. 电脑安装显卡驱动
  2. 手动安装cuda
cmd中输入命令 nvidia-smi
CUDA Version显示的是最高支持的版本

+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 531.61                 Driver Version: 531.61       CUDA Version: 12.1     |
|-----------------------------------------+----------------------+----------------------+
| GPU  Name                      TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf            Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|=========================================+======================+======================|
|   0  NVIDIA GeForce RTX 3060       WDDM | 00000000:0A:00.0  On |                  N/A |
| 30%   27C    P8               13W / 170W|   1173MiB / 12288MiB |      1%      Default |
|                                         |                      |                  N/A |
+-----------------------------------------+----------------------+----------------------+


输入:nvcc -V  
即可看见自己安装的cuda版本

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2023 NVIDIA Corporation
Built on Wed_Feb__8_05:53:42_Coordinated_Universal_Time_2023
Cuda compilation tools, release 12.1, V12.1.66
Build cuda_12.1.r12.1/compiler.32415258_0

然后去这里https://developer.nvidia.com/cuda-toolkit-archive 下载对应的cuda并安装

  1. 用conda新建环境,使用pip安装pytorch-gpu (使用conda安装老是失败)

去pytorch官网找其他包对应的版本:https://pytorch.org/get-started/previous-versions/
在这里插入图片描述

把conda 换成pip即可

conda create -n pytorch python=3.7

conda activate pytorch

pip install torch==1.13.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
# torchvision==0.14.1+cu117 torchaudio==0.13.1  这两个选择性安装,这两个都是才几M的文件

# 验证
import torch 
print(torch.cuda.is_available()) # True

方法二(推荐)

建议:后续也可以把这三个包单独下载下来,使用pip分别安装
下载地址:https://download.pytorch.org/whl/cu117
安装命令 pip install 文件路径

pip install C:\Users\jcz\Downloads\torch-1.13.1+cu117-cp37-cp37m-win_amd64.whl

搜索torch-1.13.1+cu117 ,cp37就是python3.7

torchvision和torchaudio可以根据需要再安装,一般是用不上的

技巧:下载的时候复制链接到IDM,然后IDM下载过程中速度会波动,可以点击暂停然后点击开始,这样下载速度会很快!
在这里插入图片描述

在这里插入图片描述

方法三

【参考:完全小白部署GPU版的ChatGLM-6B,类chatGPT程序_哔哩哔哩_bilibili

下载cuda
https://developer.nvidia.com/cuda-11-6-1-download-archive?target_os=Windows&target_arch=x86_64&target_version=11&target_type=exe_local

下载cuDNN
https://developer.nvidia.com/rdp/cudnn-archive

双击下载好的cuda****.exe
将cudnn解压,将bin、include、lib复制和替换到
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6

conda create -n chatglm python=3.10

conda activate chatglm安装pytorch
# pytorch官网直接找
conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia  ==需要下载很多东西==
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值