简介:亲测绝对有效——解决PyTorch安装下载慢
亲测绝对有效——解决PyTorch安装下载慢
PyTorch是一个广泛使用的深度学习框架,但是在安装和下载过程中,很多用户可能会遇到速度缓慢的问题。以下是本人亲身测试的一些有效解决PyTorch安装下载慢的方法,希望对大家有所帮助。
其中,
conda install pytorch torchvision torchaudio cudatoolkit=<version> -c pytorch
<version>
是您的GPU驱动程序的版本号,例如10.1
或10.2
。如果您没有安装GPU驱动程序或者不想使用GPU,请将其替换为cpu
。在上述命令中,我们使用了pip安装PyTorch及其相关依赖项,而没有使用conda进行安装。此外,我们增加了
pip install pytorch torchvision torchaudio torchserve
torchserve
这个工具包,它可以让我们更方便地部署和运行PyTorch模型。在上述命令中,
pip install --proxy http://proxy_host:proxy_port pytorch torchvision torchaudio torchserve
proxy_host
和proxy_port
分别是代理服务器的地址和端口号。如果您没有使用代理服务器,可以忽略这一步。在上述代码中,我们首先将pip源地址切换到清华大学的水木源地址。这个地址可以通过搜索找到最新的PyTorch版本及其相关依赖项,并且提供高速的下载体验。如果您不想使用这个地址,也可以将其切换到其他国内的pip源地址。
import sys
import os
sys.path.append(os.path.expanduser("~/.pip"))
os.system("echo '\n[global]\ninstall_requires=True\n[install]\nmirrors = https://pypi.tuna.tsinghua.edu.cn/simple\n' >> ~/.pip/pip.conf")
os.system("echo 'https://pypi.tuna.tsinghua.edu.cn/simple' > ~/.pip/pip.index")