Well, I would recommend you to look for hands on code to understand the concept.
Let me first to pose the problem (I think ) you are talking about, which is predicting sequences given a context.
Imagine you have N elements. When you train, you assume that for each element the network knows n_i and all the previous elements.
For example: to predict n3 you know n2 n1 and n0.
To predict n4 you know n3 n2 n1 and n0.
You achieve this by using masks and all this happens in parallel (thanks to the masks too).
On contrary, with lstms you need to predict element by element.
However, for testing the problem is different. Instead of doing all the predictions in parallel thanks to the masks, you will have to run the transformer element by element.
This is, you 1st predict n0. Then feed n0 to get n1. Then feed n0 and n1 and so on.