Solved by KFrank in post #2 
              
              
                Hi Fly! 

Use torch.bmm() (“batch matrix-matrix”), together with torch.transpose() 
to line up the D dimensions properly: 
S = torch.bmm (X1, torch.transpose (X2, 1, 2))

Best. 
K. Frank