常見用法:
torch.cuda.is_available() # 查看是否有可用GPU
torch.cuda.device_count() # 查看GPU數(shù)量
torch.cuda.get_device_capability(device) # 查看指定GPU容量
torch.cuda.get_device_name(device) # 查看指定GPU名稱
torch.cuda.empty_cache() # 清空程序占用的GPU資源
torch.cuda.manual_seed(seed) # 設(shè)置隨機(jī)種子
torch.cuda.manual_seed_all(seed) # 設(shè)置隨機(jī)種子
torch.cuda.get_device_properties(i) # i為第幾張卡,顯示該卡的詳細(xì)信息
?
場景問題:我使用torch.cuda.device_count()返回1但是我用nvidia-smi顯示是2個(gè)顯卡,這個(gè)是為啥呢?
第一個(gè)原因:你在環(huán)境變量設(shè)置了CUDA_VISIBLE_DEVICES
第二個(gè)原因:你顯卡壞了一個(gè),如何判斷是不是壞了可以使用上面接口測試
import torch
device=torch.device("cuda:0")
print(torch.cuda.get_device_capability(device))文章來源:http://www.zghlxwxcb.cn/news/detail-692415.html
把0改成1如果報(bào)錯(cuò)則表示1這個(gè)顯卡有問題或者不存在,據(jù)此可以判斷顯卡壞了。但是這個(gè)只是系統(tǒng)層面表示壞了。還需要進(jìn)一步判斷。首先重啟系統(tǒng)在測試一次,不行就把顯卡拔插一下,依然不行則做最后嘗試把系統(tǒng)重裝一次(這個(gè)一般都沒效果),還不行只能說明顯卡壞了。文章來源地址http://www.zghlxwxcb.cn/news/detail-692415.html
到了這里,關(guān)于[pytorch]torch.cuda用法以及判斷顯卡是不是存在問題的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!