问题解决 | 关于torch中遇到的错误及解决

本博客主要解决在torch使用中遇到的问题与解决~

1.安装相关问题

1.1.conda虚拟环境内无法安装torch(pip install torch ×)

 解决方案: 

如果是GPU版本,先查看cuda版本如果nvcc -V 命令运行后出来的是cuda11.3的话,其他版本请查看Previous PyTorch Versions | PyTorch

pip install torch==1.12.1+cu113 torchvision==0.13.1+cu113 torchaudio==0.12.1 --extra-index-url https://download.pytorch.org/whl/cu113

2.导入torch出错

2.1.ImportError: cannot import name 'TypeAlias' from 'typing_extensions' (/usr/local/lib/python3.8/dist-packages/typing_extensions.py)

 解决方案:

pip install typing-extensions --upgrade

3.运行程序出现的问题

3.1.TypeError: can't set attributes of built-in/extension type'torch._C.DisableTorchFunctionSubclass'

 解决方案:

更换torch版本,出现以上错误大概率是电脑GPU/CUDA/CUDA toolkit不兼容。

猜你喜欢

转载自blog.csdn.net/weixin_44649780/article/details/131944413