binary_cross_entropy expects FloatTensors as the model output and target as seen here:
F.binary_cross_entropy(torch.sigmoid(torch.randn(10, 10)), torch.rand(10, 10)) # works
F.binary_cross_entropy(torch.sigmoid(torch.randn(10, 10)), torch.rand(10, 10).long()) # RuntimeError: Found dtype Long but expected Float

Are you sure the second RuntimeError is raised by this loss function and not nn.CrossEntropyLoss?