Skip to content

Exporting PyTorch Lightning model to ONNX format not working #10063

Discussion options

You must be logged in to vote

Hi

A google search reveals some help on this issue here:

pytorch/pytorch#31591

Citing the thread there

As the error message indicates, the tracer detected that the output of your model didn't have any relationship to the input.

If we look closer at your code, we see that loss=0 and labels=None.

  def forward(self, input_ids, attention_mask, labels=None):
    output = self.bert(input_ids, attention_mask=attention_mask)
    output = self.classifier(output.pooler_output)
    output = torch.sigmoid(output)    
    loss = 0
    if labels is not None:
        loss = self.criterion(output, labels)
    return loss, output

the if condition does not hold, so the part of your output (the loss) can…

Replies: 3 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by rohitgr7
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
waiting on author Waiting on user action, correction, or update working as intended Working as intended
2 participants
Converted from issue

This discussion was converted from issue #10038 on October 21, 2021 08:21.