In fact all the computations at the level of nn.MultiheadAttention 2 are done with this shape (seq_len, batch_size, dim), that is  batch_first=False.
Below, seq_len corresponds to source_seq_len in the case of the query, and to target_seq_len in the case of the key and value.
As you can see here 4, when  batch_first=True, i.e. the entries (query, key, value) are of the shape (batch_size, seq_len, dim), they are first transposed into (seq_len, batch_size, dim) before the computations, and then the result (attn_output), of shape (seq_len, batch_size, dim), is re-transposed to (batch_size, seq_len, dim) before being returned.