测试pytorch(GPU)安装,并输出版本号

目录

GPU版本pytorch安装测试

CUDA信息显示

GPU版本pytorch安装测试

我们一般完成pytorch(GPU)版本后,要进行测试,以下代码用于备注:

python 复制代码
import torch
flag = torch.cuda.is_available()
print(flag)

ngpu= 1
device = torch.device("cuda:0" if (torch.cuda.is_available() and ngpu > 0) else "cpu")
print(device)
print(torch.__version__)
print(torch.cuda.get_device_name(0))
print(torch.rand(3,3).cuda())

测试结果如下:

True

cuda:0

2.0.0+cu118

NVIDIA GeForce RTX 3090

tensor(\[0.0756, 0.7062, 0.6051,

0.2772, 0.5758, 0.3481,

0.4451, 0.9666, 0.9337], device='cuda:0')

CUDA信息显示

在CUDA后续的更新中,windows系统的任务管理器看不见CUDA占用了,在Ubuntu中同样无法看见,需要在命令行窗口输入:

bash 复制代码
nvidia-smi
相关推荐
kyle~3 小时前
FastAPI --- 将业务能力以 API 的形式提供给外部系统
python·fastapi·前后端
aiotto资源分享4 小时前
Python 写 JSON 文件,程序中途退出会留下什么?
java·python·json·jsondecodeerror
梯度下降者5 小时前
Python信号量,条件变量,事件学习
python·条件变量·事件·信号量·线程通信
MSTcheng.5 小时前
【AI应用实战】用 FastAPI + SSE 做一个自己的 AI 聊天网页:流式输出、多轮对话与完整源码
人工智能·python·大模型·fastapi·sse·ai聊天助手
哈尔滨张谦蛋6 小时前
兰州大学 · 甘肃省可穿戴装备重点实验室 · 2027年博士招生
人工智能·深度学习
the局外人6 小时前
Python 实战检索优化:BM25、向量与重排
数据库·后端·python
__underline__6 小时前
冷门Python知识点006篇:Python 类体里的名字,能被"凭空造出来"
后端·python
用户0332126663677 小时前
使用 Python 轻松移除 Excel 文档中的重复行
python·excel
LiaoWL1237 小时前
从零搭一个 RAG 知识库(二):换上语义 Embedding——BGE 实测与阈值重校准
python·大模型·numpy·embedding·向量检索·rag
Dmz丶7 小时前
前端转 AI 100 天 Day 48:向量数据库——100 万向量的毫秒级检索
python