Closed dangitstam closed 6 years ago
I got past the exception by adding a contiguous()
call at https://github.com/allenai/allennlp/blob/01ddd126e339971eb752ec32ba024ba1734e3b71/allennlp/modules/encoder_base.py#L107
I changed the line to
initial_states = [state.index_select(1, sorting_indices)[:, :num_valid, :].contiguous()
for state in hidden_state]
since asserting contiguousness from my model wasn't enough.
I don't think index_select()
guarantees a contiguous tensor but PyTorch LSTMs require them to be, which explains the exception I was getting.
Hey, nice one figuring that out - it looked a bit complicated! Would you mind sending a PR?
I'm doing nmt and my model involves initializing the hidden state of the LSTM that generates the translation in the target language. For some reason, about 18% of the way through training in the first epoch, I get a PyTorch error saying that
hx
is not contiguous when encoding the target utterance.I inserted asserts to ensure the hidden state i'm passing is contiguous but the asserts are never triggered and the error still happens.
I should also mention this only happens when training on the GPU, CPU training seems okay.
Here is the backtrace from
stderr.log
Here is my source code, in particular, it's my
forward()
functionself.en_encoder
is a Seq2VecEncoder andself.fr_encoder
is a Seq2SeqEncoder