In the case of nn.TransformerEncoderLayer 5 (below I do not distinguish between embed_dim and d_model in the case of internal operations):

if batch_first=True, then the input of the model will be of shape (batch_size, seq_len, dim) : here N of nn.LayerNorm corresponds to batch_size, * to (seq_len, dim) and normalized_shape to dim

otherwise, the input of the model will be of shape (seq_len, batch_size, dim) : here N of nn.LayerNorm corresponds to seq_len, * to (batch_size, dim) and normalized_shape to dim


But in all cases, the normalization is done along the last dimension (dim), because according to the documentation of nn.LayerNorm, when a single integer is used for normalized_shape, it is treated as a singleton list, and this module will normalize over the last dimension which is expected to be of that specific size.
There is no need to talk about target length in the case of the encoder, we have only one input of length seq_len / source_seq_len. It is in the case of the nn.TransformerDecoderLayer 1 that we can even talk about T and S (target length and source length). And in this case an nn.LayerNorm will be applied to (target_seq_len, batch_size, dim) (or (batch_size, target_seq_len, dim) for batch_first=True) and others to (source_seq_len, batch_size, dim) (or (batch_size, source_seq_len, dim) for batch_first=True), always following the last dimension, no matter what value batch_first has.
See :

TransformerEncoderLayer : pytorch/transformer.py at master · pytorch/pytorch · GitHub 4

TransformerDecoderLayer : pytorch/transformer.py at master · pytorch/pytorch · GitHub