[pytorch]torch.cuda用法以及判断显卡是不是存在问题

常见用法:

torch.cuda.is_available() # 查看是否有可用GPU

torch.cuda.device_count() # 查看GPU数量

torch.cuda.get_device_capability(device) # 查看指定GPU容量

torch.cuda.get_device_name(device) # 查看指定GPU名称

torch.cuda.empty_cache() # 清空程序占用的GPU资源

torch.cuda.manual_seed(seed) # 设置随机种子

torch.cuda.manual_seed_all(seed) # 设置随机种子

torch.cuda.get_device_properties(i) # i为第几张卡,显示该卡的详细信息

场景问题:我使用torch.cuda.device_count()返回1但是我用nvidia-smi显示是2个显卡,这个是为啥呢?

第一个原因:你在环境变量设置了CUDA_VISIBLE_DEVICES

第二个原因:你显卡坏了一个,如何判断是不是坏了可以使用上面接口测试

import torch

device=torch.device("cuda:0")

print(torch.cuda.get_device_capability(device))

把0改成1如果报错则表示1这个显卡有问题或者不存在,据此可以判断显卡坏了。但是这个只是系统层面表示坏了。还需要进一步判断。首先重启系统在测试一次,不行就把显卡拔插一下,依然不行则做最后尝试把系统重装一次(这个一般都没效果),还不行只能说明显卡坏了。

相关推荐
小爷毛毛_卓寿杰1 小时前
我把一个 3B 模型塞进了 Xinference,然后它干掉了 DeepSeek V3.2
人工智能·开源·github
秦先生在广东1 小时前
Agent 闭环才是真正的护城河:Anthropic “300 个 Agent“ 背后被忽视的秘密
人工智能
Bigfish_coding1 小时前
前端转agent-【python】- 14 记忆系统优化:摘要与遗忘
人工智能
Bigfish_coding1 小时前
前端转agent-【python】-13 Ollama Python流式输出教程:stream=True 与 async 实践
人工智能
ZhengEnCi3 小时前
P2M-Matplotlib折线图完全指南-从数据可视化到趋势分析的Python绘图利器
python·matlab·数据可视化
字节跳动数据库3 小时前
文章分享——相似函数处理方法
人工智能·后端·程序员
Bigfish_coding3 小时前
前端转agent-【python】-12 LangChain 入门实战:RAG + LCEL 链式调用
人工智能
程序员cxuan4 小时前
读懂 Claude Code 架构分析系列,第一篇,开始!
人工智能·后端·架构
ZhengEnCi4 小时前
P2L-Matplotlib饼图完全指南-从数据可视化到图表定制的Python绘图利器
python·matlab
曲幽4 小时前
你的REST接口还在“过度投喂”数据吗?——FastAPI + GraphQL实战避坑指南
python·fastapi·web·graphql·route·cors·rest·strawberry