How to assign gradients to model parameters manually?
onlytailei
to answer your second question, you can create a mask tensor and index elements via this mask tensor: example: <SCODE>import torch

x = torch.randn(2, 3, 2)

mask = x.gt(0.5)
print(mask)

# mask is a torch.ByteTensor of same shape and size as x

print(x[mask])
<ECODE> Output: <SCODE>
(0 ,.,.) =
  0  0
  0  0
  0  1

(1 ,.,.) =
  0  1
  1  0
  1  0
[torch.ByteTensor of size 2x3x2]


 1.3140
 0.8220
 1.5169
 0.9264
[torch.FloatTensor of size 4]

<ECODE>
smth
Then I think this method is useless.
onlytailei
apaszke
But gather always returns a tensor with same dimension as the input right?
onlytailei
Yes, that’s the limitation.
apaszke