This is a sample:
import torch

x = torch.tensor(
    [
        [
            [[1, 2], [3, 4], ],
            [[5, 6], [7, 8], ],
            [[9, 10], [11, 12], ],
        ],
        [
            [[13, 14], [15, 16], ],
            [[17, 18], [19, 20], ],
            [[21, 22], [23, 24], ],
        ]
    ]
)

print(x.shape)
# torch.Size([2, 3, 2, 2])

print(x.reshape(2, 3, 4).transpose(2, 1).reshape(8, 3))
# tensor([[ 1,  5,  9],
#         [ 2,  6, 10],
#        [ 3,  7, 11],
#        [ 4,  8, 12],
#       [13, 17, 21],
#      [14, 18, 22],
#     [15, 19, 23],
#    [16, 20, 24]])


generally:
a, b, c, d = x.shape
x.reshape(a, b, c*d).transpose(2, 1).reshape(a*c*d, b)