If flag is set, you run the model in no_grad mode. This means that you won’t be able to compute any gradient for it.
As I mentioned above, here you set the requires_grad flag on an intermediary Tensor. But that won’t make you able to backprop before it.
If you set flag to False, it should work fine no?