I have a doubt. According to Pytorch documentation for BCEWithLogitsLoss, sigmoid calculation will be done. My question is why are you taking sigmoid again in torch.nn.Sigmoid()(pred)?
nn.BCEwithLogitLoss applies the sigmoid internally and calculates the loss given the logits as inputs. If you want to use the probabilities given by the model, you would have to apply the sigmoid manually.