Added some debug code to functional.py in the pytorch library:
    print("*******************")
    print(f"weight.size(): {weight.size()}")
    print(f"weight: {weight}")
    print(f"input.size(): {input.size()}")
    print(f"input: {input}")
    print(f"padding_idx: {padding_idx}")
    print(f"scale_grad_by_freq: {scale_grad_by_freq}")
    print(f"sparse: {sparse}")

Here’s what I see for the values when it crashes:
*******************
len(weight): 209
weight: Parameter containing:
tensor([[-0.0065,  0.0223,  0.0171,  ..., -0.0050,  0.0034,  0.0075],
        [ 0.0000,  0.0000,  0.0000,  ...,  0.0000,  0.0000,  0.0000],
        [ 0.0193, -0.0405,  0.0071,  ...,  0.0088, -0.0047,  0.0087],
        ...,
        [ 0.0138,  0.0307,  0.0120,  ..., -0.0131, -0.0176, -0.0025],
        [ 0.0308,  0.0078,  0.0159,  ..., -0.0149, -0.0200, -0.0039],
        [-0.0060, -0.0121, -0.0120,  ..., -0.0102,  0.0054,  0.0141]],
       requires_grad=True)
input.size(): torch.Size([8, 512])
input: tensor([[  2,   3,   4,  ..., 511, 512, 513],
        [  2,   3,   4,  ..., 511, 512, 513],
        [  2,   3,   4,  ..., 511, 512, 513],
        ...,
        [  2,   3,   4,  ..., 511, 512, 513],
        [  2,   3,   4,  ..., 511, 512, 513],
        [  2,   3,   4,  ..., 511, 512, 513]])
padding_idx: 1
scale_grad_by_freq: False
sparse: False