Isn’t it nothing but twice bmm()?
import torch
U = torch.arange(1,10).reshape(1, 3,3) 
V = torch.arange(1,10).reshape(1, 3,3) 
M = torch.tensor([1, 2, 3]).repeat(3,1).view(1,3,3) 
result = torch.bmm(U, M).bmm(V)

result: 
tensor([[[ 180,  216,  252],
         [ 450,  540,  630],
         [ 720,  864, 1008]]])