I’m not sure, if I understand the use case correctly, but could you check, if this code snippet would work for you:
a, b, c = 2, 3, 4

x = torch.randn(a, b)
y = torch.randn(a, c)

z = torch.matmul(x.unsqueeze(2), y.unsqueeze(1))
z = z.view(a, -1)

If not, could you provide dummy tensors and the expected result?