As given in the linked docs, the shapes for src and tgt are expected as:


src: [S,N,E], [N, S, E] if batch_first.
tgt: [T,N,E], [N, T, E] if batch_first.


while a and b seem to have a single dimension with a shape of 256 which raises the indexing error.