hmm did you by chance swap M and M2 in the paste here? when i do M[0,:,:], and M[1,:,:] i get:

M[0,:,:] = tensor([[1., 2., 3.],
[4., 5., 6.]])


M[1,:,:] = tensor([[10., 20., 30.],
[40., 50., 60.]])

and the transpose is:

tensor([[[ 1.,  2.,  3.],
[10., 20., 30.]],

    [[ 4.,  5.,  6.],
     [40., 50., 60.]]])

transposing just swaps axes, so transpose(M,0,1) is same as transpose(M,1,0)
You need M3 = torch.transpose(M.flip(0),0,1)