Bert-BiLSTM-CRF-pytorch icon indicating copy to clipboard operation
Bert-BiLSTM-CRF-pytorch copied to clipboard

使用 gpu运行出现TypeError: 'generator' object is not subscriptable?

Open cjjjy opened this issue 4 years ago • 2 comments

你好,我使用gpu运行您的代码时出现以下错误,我的pytorch 版本是0.4.1:
self.check_forward_args(input, hx, batch_sizes) File "/home/nlp/anaconda2/envs/Bert-BiLSTM-CRF-pytorch/lib/python3.5/site-packages/torch/nn/modules/rnn.py", line 146, in check_forward_args check_hidden_size(hidden[0], expected_hidden_size, TypeError: 'generator' object is not subscriptable

cjjjy avatar Oct 01 '20 01:10 cjjjy

你好,我使用gpu运行您的代码时出现以下错误,我的pytorch 版本是0.4.1: self.check_forward_args(input, hx, batch_sizes) File "/home/nlp/anaconda2/envs/Bert-BiLSTM-CRF-pytorch/lib/python3.5/site-packages/torch/nn/modules/rnn.py", line 146, in check_forward_args check_hidden_size(hidden[0], expected_hidden_size, TypeError: 'generator' object is not subscriptable

解决了,将
hidden = (i.cuda() for i in hidden)这行代码改成下面即可运行: hidden1=hidden[0].cuda() hidden2=hidden[1].cuda() hidden=(hidden1,hidden2)

cjjjy avatar Oct 01 '20 01:10 cjjjy

謝謝您

ken19980727 avatar Nov 07 '20 08:11 ken19980727