The number of layer is set to 1, so the loop could be simply removed and it would still work properly.

Agree, but just because n_layers = 1. Otherwise it would be weird.

All the sentences do have the same lengths, after pre-processing the data.

True, but the smaller sentences were padded, so part of the attention is in the padding, which is not what you want.