Thanks! You actually answered the question I should have asked. I wanted to make sure no gradients flow back along the mask. I take it that if I calculated the mask in a differentiable way, I would have to add a detach or no_grad, to ensure that no gradients flow back along the mask.