This code should work:
a = torch.randn(10, 1000, 1, 4)
b = torch.randn(10, 1000, 6, 4)

dots = torch.Tensor(10, 1000, 6, 1)
for x in range(10):
     for y in range(1000):
         for z in range(6):
             dots[x,y,z] = torch.dot(b[x,y,z], a[x,y,0]) 


ret = torch.matmul(b, a.permute(0, 1, 3, 2))
print((ret - dots).abs().max())
> tensor(9.5367e-07)