I think the confusion here stems from the fact that PyTorch by default uses a NCHW memory format, with tensor dimensions structured accordingly. In other words, tensor dimensions are (batch, channel, height, width).
Therefore, in your example, if you change the input tensor to the assumed structure, everything should work as expected;
input = torch.randn(6, 768, 512) 

Note that some work has been done, which shipped in v1.5, that allows you to change the memory format to one that is (arguably) more intuitive, namely the NHWC format. An additional benefit of the NHWC format is that it can lead to drastic performance improvements in some specific scenarios due to CuDNN optimizations.
Some references regarding the memory format:

https://pytorch.org/tutorials/intermediate/memory_format_tutorial.html 9
https://github.com/pytorch/pytorch/issues/28619 3