In your first problem, Autograd won’t be able to calculate the gradients for the model parameters, if you try to call backward on total_score as the computation graph is detached from this variable.
You would need to calculate total_score using your model’s output and target in some kind of loss function.
In general, you could use nn.BCEWithLogitsLoss with pos_weight, which makes it possible to trade off recall and precision.
Also, in your second problem you are re-wrapping your tensor into a Variable, thus detaching the computation graph.
Try to use the tensors directly without creating a new tensor.
That being said, Variables are deprecated since 0.4.0. You can use tensors directly now and should set requires_grad=True in case your tensor needs gradients.