I’m training a transformer model from scratch, and was able to run a “mini” train and dev set on the CPU without any errors, but when I run the training loop on the larger dataset, I encounter this error (also includes debug print statements):
-- Inside Encoder Init --
d_vocab: 5493
d_embedding: 128
-- Inside Decoder Init --
d_vocab: 3194
d_embedding: 128
-- Inside Encoder Forward --
embedding in: torch.Size([64, 60])
embedding out: torch.Size([64, 60, 128])
-- Inside Decoder Forward --
embedding in: torch.Size([64, 60])
Traceback (most recent call last):
File "~/transformer_training.py", line 176, in <module>
out = model(src,trg, mask)
File "~/myenv2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1186, in _call_impl
return forward_call(*input, **kwargs)
File "~/transformer.py", line 237, in forward
x = self.decoder(x, trg, mask)
File "~/myenv2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1186, in _call_impl
return forward_call(*input, **kwargs)
File "~/transformer.py", line 205, in forward
x = self.embedding(x)
File "~/myenv2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1186, in _call_impl
return forward_call(*input, **kwargs)
File "~/transformer.py", line 20, in forward
x = self.embedding(x)
File "~/myenv2/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1186, in _call_impl
return forward_call(*input, **kwargs)
File "~/myenv2/lib/python3.9/site-packages/torch/nn/modules/sparse.py", line 159, in forward
return F.embedding(
File "~/myenv2/lib/python3.9/site-packages/torch/nn/functional.py", line 2197, in embedding
return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
IndexError: index out of range in self
NOTE: This does not occur when I use a smaller train and dev set for debug purposes (terminal output):
-- Inside Encoder Init --
d_vocab: 1435
d_embedding: 128
-- Inside Decoder Init --
d_vocab: 1446
d_embedding: 128
-- Inside Encoder Forward --
embedding in: torch.Size([64, 60])
embedding out: torch.Size([64, 60, 128])
-- Inside Decoder Forward --
embedding in: torch.Size([64, 60])
embedding out: torch.Size([64, 60, 128])