本篇文章记录下自己安装pytorch的过程,由于我装过3~4次了,所以还算是比较有经验了。
1.检查电脑配置
右键打开

打开系统信息

切换为组件栏

在3D设置中找到自己的cuda版本,我这里是11.1。

2.下载
打开pytorch下载官网:https://pytorch.org/get-started/locally/。然后选择好各个选项,其中CUDA版本根据自己电脑选择,我这里为11.1。

然后我们发现最下面有一行命令。

复制这行命令。打开anaconda的命令行。

在命令行中一条一条的输入以下命令,下面是为了添加国内的镜像源,这不单单是为了更快,而是更加稳定,我第一次直接按默认的来,结果中途有一个包卡住了,然后就中断了下载,这时我把之前下载的包都删除干净,重新下,才弄好。
下面的源虽然这次你不一定都用得上,(这次只用得上一两个)但是,这次把这么多源添加好了,下次你下载其他的包时或许就能用上。
<code>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/r conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2 conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/menpo/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/bioconda/ 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/conda-forge/ conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/simpleitk conda config --set show_channel_urls yes </code>
然后,我们将之前我们从官网上复制下来的那一行命令复制到命令行中,不过把-c之后的内容通通去掉,-c是指定从哪个源来下载我们要的包,但是我们用的是国内源,我们上一步已经配置,这记录在系统中了,而且在源使用列表中的最前面,所以conda能够自动使用国内源。
去掉c后命令大致如下(换成你自己的),回车,然后输入y,开始下载。。。

我们等一会,下载成功之后我们测试一下。
3.测试
打开jupyter notebook,输入以下命令:
<code>import torch#1测试是否成功安装pytorch print(torch.cuda.is_available())#2检测cuda是否安装正确和可用. #3判断是否能够真正使用GPU。即cuda,pytorch,显卡都兼容。这步很关键,很多4,5年前的电脑前两步都没问题,这步就出问题,多半是显卡算力太低。 a=torch.Tensor([1,2]) a=a.cuda() a </code>
结果:


如果你上面代码都没报错,那么说明成功了!GPU加速就在眼前。
如果你的电脑比较新,那么多半按上述操作都没有问题。
如果你的电脑非常旧,可以参考之前我写的(我之前是旧电脑),或许可以给你提供一些思路,产生一些共鸣:
1.https://blog.csdn.net/qq_43391414/article/details/109672442
2.https://blog.csdn.net/qq_43391414/article/details/109695111
3.https://blog.csdn.net/qq_43391414/article/details/110562749
我现在电脑配置:
<code>联想 thinkbook 14 2021款 win10 独显MX450 集成显卡:Iris(R) Xe 内存16G CPU:i5 1135G7 </code>
所以,目前搞些中小型网络好像还是没啥压力的。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!