Hi everyone,
- I have a tensor
t
withrequires_grad = True
- I apply a boolean advanced indexing to
t
, sayt1 = t[mask]
. - The mask is regular so I can reshape
t1
to have a shapes
, that ist2 = t1.reshape(s)
(ort1.view(s)
)
Now, I want to access the gradient of t2
, that is, to retrieve a tensor g
with shape s
containing the gradient of t
at the corresponding positions of mask
.
The view
/reshape
operators make t2
a non-leaf tensor, thus calling t2.grad
returns None
.
Is there a way to get these gradients?