设备序号无效,CUDA / TORCH

问题描述 投票:1回答:2

我在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行中。

python gpu pytorch
2个回答
2
投票

试试这个

import torch
print(torch.cuda.is_available())

如果输出为False,则意味着PyTorch未检测到GPU。我有同样的问题,并重新安装Pytorch为我工作。您可能还想看看这个https://github.com/pytorch/pytorch/issues/6098


0
投票

如果预先训练的模型在不同数量的Cuda设备上进行训练,则可能会出现该错误。例如,在训练模型时,您使用了3个Cuda设备,现在您在仅具有单个Cuda设备的设备上加载相同的训练模型。

© www.soinside.com 2019 - 2024. All rights reserved.