#@title 加载Google云端硬盘
from google.colab import drive
drive.mount('/content/drive')
import sys
sys.path.insert(0,'/content/drive/MyDrive/Colab Notebooks')
!wget -c https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
!chmod +x Miniconda3-latest-Linux-x86_64.sh
!bash ./Miniconda3-latest-Linux-x86_64.sh -b -f -p /usr/local #-p indicates where you want to install
# 13.测试自己的torch是否可以用GPU
import torch
# Check if CUDA (GPU support) is available
if torch.cuda.is_available():
print("GPU is available.")
# Print the current GPU device
print("Current GPU device:", torch.cuda.get_device_name(0))
else:
print("GPU is not available. Running on CPU.")
如果不可用,先执行nvcc --version查看CUDA及其tools的版本,之后打开https://pytorch.org/get-started/previous-versions/,找到对应版本的torch安装命令
安装前要查看你的环境是conda还是非conda
conda就用里面Conda OSX的conda install ...的命令
非conda就用里面Wheel OSX的pip install ...的命令
如果安装之后torch版本没有改变,或者pip list查询的torch版本和pip show torch版本不一致,那可能是缓存的问题,执行pip cache purge代码清空缓存后在执行pip list和pip show torch查看
例如:
1.我原本装的torch版本为2.1.0(通过pip list查询),运行上面代码后提示GPU is not available. Running on CPU.
2.之后运行nvcc --version后查询得知我的CUDA版本为cuda_11.7。
3.打开https://pytorch.org/get-started/previous-versions/网站,发现只有torch2.0.1版本及其以下才支持CUDA_11.7版本,且我用的是pip安装命令,故选择Wheel OSX下的安装命令
pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.24.安装成功后重新运行上面代码即可
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· AI Agent开发,如何调用三方的API Function,是通过提示词来发起调用的吗