gpt4 book ai didi

python - 无效的设备序号,CUDA/TORCH

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:27 26 4
gpt4 key购买 nike

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

最佳答案

尝试这样做

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

如果输出为 False,则表示 PyTorch 未检测到 GPU。我遇到了同样的问题,重新安装 Pytorch 对我有用。您可能还想看看这个 https://github.com/pytorch/pytorch/issues/6098 .

关于python - 无效的设备序号,CUDA/TORCH,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50783853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com