Hi,
Asking question for specific projects on the forum is fine.
You should be careful and never use .data. You should use .detach() or with torch.no_grad().
binary_gates.grad will only be populated if it’s a leaf variable and it requires gradients.
Also, the backward hook on nn.Modules (that should not be used, see the doc), run before the .grad field for its inputs is populated. So it is expected even for a leaf Tensor that you don’t see it in the hook.