Solved by albanD in post #2 
              
              
                Hi, 
The proposed method is actually the right way to do it. 
Another approach not using hooks is to no include these rows into the computation of the loss, so that the .backward() will not required to be hooked into. 
Few examples below: 
output = model(data)
to_keep_indices = get_indices_to_keep(o…