Hi All,
I’m trying to broadcast a 2D Tensor over a 4D Tensor and I’m not 100% how to do it. Let’s say I have two tensors, mat1 of size [B, D] and another Tensor mat2 of size [B, D, N, N]. How could I broadcast mat1 over dim 2 and 3 of mat2?
mat1 = torch.randn(1, 4)
mat2 = torch.randn(1,4,2,2) #B=1, D=4, N=2
mat1*mat2 #throws errror

RuntimeError: The size of tensor a (2) must match the size of tensor b (4) at non-singleton dimension 3

The one thing I have done is use torch.unsqueeze to force a broadcasting but another problem arises during the backward pass as I’m changing the size of the Tensor!
Any help is appreciated!