pytorch 4. 0
KeyError: tensor
This is an obvious error. In the dict self.int_to_char, its keys are the type of integer rather than tensors. Therefore, you can change source code in line 169 as:
self.int_to_char[sequence[i].item()]
Should be fine.
说白了就是字典的key不是tensor而是值,所以在tensor后面加.item()
One of the variables needed for gradient computation has been modified by an inplace operation;
这是原地计算,去掉inplace操作,几个基本的要解决,一个是+=问题就是形如out+=x的改变成out = out+x,还有一个就是这个self.flatten_parameters()操作移动到init 中去,因为在GPU中计算时候回修改LSTM值,会使得backward不能进行。######
Move the self.flatten_parameters()
call in def forward
to def __init__
. It has no effect on CPU, but on CUDA it will modify the LSTM’s parameters part way through the computation which would break backwards (leading to the exception).