Yes. I got your point. But I am passing appropriate number of inputs to loss function.

        optimizer.zero_grad()
        outputs = model(data0,data1)

        if type(outputs) not in (tuple, list):
            outputs = (outputs,)

        loss_inputs = outputs
        if (target0,target1) is not None:
            target = (target0,target1)
            loss_inputs += target

        loss_outputs = loss_fn(*loss_inputs)
        loss = loss_outputs[0] if type(loss_outputs) in (tuple, list) else loss_outputs
        losses.append(loss.item())
        total_loss += loss.item()
        loss.backward()
        optimizer.step()

        for metric in metrics:
            metric(outputs, target), loss_outputs)

 loss_outputs = loss_fn(*loss_inputs)

This line is causing this bug. I observed the loss function as well. Which I defined:
class ContrastiveLoss(nn.Module):


    def __init__(self, margin):
        super(ContrastiveLoss, self).__init__()
        self.margin = margin
        self.eps = 1e-9

    def forward(self, output1, output2, target, size_average=False):
        distances = (output2 - output1).pow(2).sum(1)  # squared distances
        losses = 0.5 * (target.float() * distances +
                        (1 + -1 * target).float() * F.relu(self.margin - (distances + self.eps).sqrt()).pow(2))
        return losses.mean() if size_average else losses.sum()

Contrastive loss: it takes embeddings of two samples and a target label == 1 if samples are from the same class and label == 0 otherwise.
in which I tried keeping size_average= False still I am getting this bug.
is their any other problem which may cause this bug?