For simplicity, say that output = net(input) and output is of dimension 100 x 1. During training, maybe I want to zero out the gradient for index 2 and 4 positions of output. I wonder how I could do this and still backprop the rest of the gradients through the model? I was thinking of a two-step approach where the gradient w.r.t output is computed first, then some partial gradient is zero-out, and then compute the gradients for the rest of the model parameters using the new output gradient.