Solved by ptrblck in post #2 
              
              
                You are passing a target tensor, which requires gradients (labels) in the second use case. 
Since the derivative for the target is not supported for nn.BCELoss, you should detach it before calling loss_fn.