fairseq icon indicating copy to clipboard operation
fairseq copied to clipboard

Error in "Simple LSTM tutorial"

Open okgrammer opened this issue 7 years ago • 3 comments

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.

okgrammer avatar May 31 '19 03:05 okgrammer

Can you include the commands that you used for training and generation? Thanks!

lematt1991 avatar May 31 '19 13:05 lematt1991

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.

okgrammer avatar Jun 02 '19 06:06 okgrammer

Thanks, fixed in b35d9bcac47516a99e7cf34a2062ba28cdbf76d3

myleott avatar Jun 02 '19 14:06 myleott