There are at least 2 issues in your code:

BCELoss takes sigmoid outputs not logits, if you want to use logits (recommended) use BCEWithLogitsLoss
like the error message recommends, labels should not be of type float but of type long. Hence, just drop the float from labels.float() and it should be fine (or make it long-type if it is some other type: labels.long())

I guess applying 1 & 2 should fix your issues