I have one scores tensor with gradients attached to it and I have a corresponding lengths tensor where sum(lengths) = len(scores)
I would like to scatter these scores in a matrix in a diagonal way such that
length_so_far = 0
for i in lengths:
    adj[i][length_so_far:length_so_far+lengths[i]] = scores[length_so_far:length_so_far+lengths[i]]
    length_so_far += lengths[i]

while maintaining the gradients so that it can flow back to the original scores tensor during backpropagation
image1322×1480 9.73 KB
Will appreciate any hints. Thanks