【发布时间】:2018-11-19 21:14:18
【问题描述】:
我在 ubuntu 16.04 中运行脚本时遇到此错误。请多多包涵,我是 python 新手, 我已经检查了互联网上已经可用的选项,但无法修复它。
RuntimeError: cuda runtime error (10) : invalid device ordinal at torch/csrc/cuda/Module.cpp:32
我目前正在运行这个文件。
from __future__ import print_function
from models import LipRead
import torch
import toml
from training import Trainer
from validation import Validator
print("Loading options...")
with open('options.toml', 'r') as optionsFile:
options = toml.loads(optionsFile.read())
if(options["general"]["usecudnnbenchmark"] and options["general"] ["usecudnn"]):
print("Running cudnn benchmark...")
torch.backends.cudnn.benchmark = True
#Create the model.
model = LipRead(options)
if(options["general"]["loadpretrainedmodel"]):
model.load_state_dict(torch.load(options["general"] ["pretrainedmodelpath"]))
#Move the model to the GPU.
if(options["general"]["usecudnn"]):
model = model.cuda(options["general"]["gpuid"])
trainer = Trainer(options)
validator = Validator(options)
for epoch in range(options["training"]["startepoch"], options["training"]["epochs"]):
if(options["training"]["train"]):
trainer.epoch(model, epoch)
if(options["validation"]["validate"]):
validator.epoch(model)
我怀疑这个文件与弹出的错误有关
Title = "TOML Example"
[general]
usecudnn = true
usecudnnbenchmark = true
gpuid = 0
loadpretrainedmodel = true
pretrainedmodelpath = "trainedmodel.pt"
savemodel = true
modelsavepath = "savedmodel.pt"
[input]
batchsize = 18
numworkers = 18
shuffle = true
[model]
type = "LSTM"
inputdim = 256
hiddendim = 256
numclasses = 500
numlstms = 2
[training]
train = true
epochs = 15
startepoch = 10
statsfrequency = 1000
dataset = "/udisk/pszts-ssd/AV-ASR-data/BBC_Oxford/lipread_mp4"
learningrate = 0.003
momentum = 0.9
weightdecay = 0.0001
[validation]
validate = true
dataset = "/udisk/pszts-ssd/AV-ASR-data/BBC_Oxford/lipread_mp4"
saveaccuracy = true
accuracyfilelocation = "accuracy.txt"
错误主要出现在我终于到达的 gpuid 行中。
【问题讨论】:
-
什么错误?您的帖子不包含错误,还包括可能产生错误的源代码
-
@Lasitha 感谢您的评论,我正在编辑问题,看看您是否可以对其进行排序
-
你确定你有一个受支持的、工作的 GPU 吗?您能否正确运行 CUDA Toolkit 中的任何示例?
-
是的,我用过其他代码,它们工作正常