Hi,
This happens because the F.binary_cross_entropy() can only compute gradients wrt to its first argument. But in the second call you make, the second argument (input) is a Tensor that requires gradients. Hence the error.
If you need gradients for the target, it might be simpler to re-write the bce as a simple function that just computes (-self.weight (target * input.log() + (1 - target) * (1-input).log())).mean() (assuming mean reduction).