Error in "Simple LSTM tutorial"
Hi, I am trying the simple LSTM tutorial for adding new modules in fairseq. Training works fine, but the following error appears when I run fairseq-generate.
... in forward
[x, final_encoder_hidden.unsqueeze(1).expand(bsz, tgt_len, -1)],
RuntimeError: The expanded size of the tensor (2095) must match the existing size (2160) at non-singleton dimension 0. Target sizes: [2095, 4, -1]. Tensor sizes: [2160, 1, 256]`
I printed the dimension of "prev_output_tokens" inside decoder's forward method:
bsz 2160
tgt_len 1
final_encoder_hidden torch.Size([2160, 256])
bsz 2160
tgt_len 2
final_encoder_hidden torch.Size([2160, 256])
bsz 2160
tgt_len 3
final_encoder_hidden torch.Size([2160, 256])
bsz 2095
tgt_len 4
final_encoder_hidden torch.Size([2160, 256])
It seems the batch size changes at the 4th token. Could you help with this issue? Thank you.
Can you include the commands that you used for training and generation? Thanks!
Hi, thanks for your reply. I used the following commands:
Training:
fairseq-train data-bin/iwslt14.tokenized.de-en \
--arch tutorial_simple_lstm \
--encoder-dropout 0.2 \
--decoder-dropout 0.2 \
--optimizer adam \
--lr 0.005 \
--lr-shrink 0.5 \
--max-tokens 12000 \
--user-dir ~/machine_translation/
Generation:
fairseq-generate data-bin/iwslt14.tokenized.de-en \
--path checkpoints/checkpoint_best.pt \
--beam 5 \
--remove-bpe \
--user-dir ~/machine_translation/
I put the lstm code from the tutorial in ~/machine_translation/ directory.
Thanks, fixed in b35d9bcac47516a99e7cf34a2062ba28cdbf76d3