How to add 2 tensors of unequal shapes in the last dimension?

I’m trying to add 2 tensors in the forward() function.

Eg Tensor 1 shape = (1,365,12) and Tensor 2 shape = (1,365,10) . I want the result such that Result Tensor shape = (1,365,12) but we only add the first 10 dim on Tensor1 with Tensor2 and the last 2 dim remain unchanged. (Changing the shape of Tensor 2 to add 2 zero columns in last dim is not possible).

I tried doing it using this approach : Tensor1[:, :, :10] = Tensor1[:, :, :10] + Tensor2. Also, fyi I got Tensor1 and Tensor2 using torch.split(Tensor3,[12,10],dim=2) where Tensor3 shape = (1,365,22) .
It works, although I get the following warning :

Output 0 of SliceBackward is a view and is being modified inplace. This view is an output of a function that returns multiple views. Inplace operators on such views are being deprecated and will be forbidden starting from version 1.8. Consider using unsafe_ version of the function that produced this view or don’t modify this view inplace. (Triggered internally at …\torch\csrc\autograd\variable.cpp:547.)

Is there any alternate way I can approach this?


result = Tensor3[...,:12].clone()
result[...,:10] += Tensor3[...,12:22]

this may work without clone, but output will be non-contiguous, and it may get cloned by autograd anyway