Batched index_add

Hi everyone,

I need to perform an index_add operation on 3D tensors, however, this operation is only implemented for 2D tensors and the indices needs to be a vector. I have been trying to think of a workaround which achieves the same but with no success. I would be glad if I could get some help!

My input tensor has the following shape (batch_size, max_length, emb_dim) and my index is of size (batch_size, max_length). I want to add vectors from the input tensor to itself along dim=1 based on the index values. For example, index[0, 1] = 3 will mean input[0, 1] and input[0, 3] are to be added.

Thanks!

That’s not the case, as you can use tensors with having multiple dimensions with index_add_.
I don’t quite understand your use case, as it seems you would like to add the tensor to itself instead of another passed value tensor?
Could you post an example using randomly initialized tensors?