dec_hidden[0].repeat(1, beam_size, 1)

changing dec_hidden to dec_hidden[0],  I got a new error.
File “/usr/local/lib/python3.5/dist-packages/torch/nn/modules/rnn.py”, line 187, in check_hidden_size
raise RuntimeError(msg.format(expected_hidden_size, tuple(hx.size())))
RuntimeError: Expected hidden[0] size (2, 64, 500), got (64, 500)