The example is just a general example of how to do a forward pass through the model, just like you can do in any model.  In practice, you’d see something like this:

  
      github.com
  
  
    huggingface/transformers/blob/4f7022d68d4bae4b5e6a748b7a7323515c6fdcd3/examples/seq2seq/seq2seq_trainer.py#L162-L176 4

def _compute_loss(self, model, inputs, labels):    if self.args.label_smoothing == 0:        if self.data_args is not None and self.data_args.ignore_pad_token_for_loss:            # force training to ignore pad token            logits = model(**inputs, use_cache=False)[0]            loss = self.loss_fn(logits.view(-1, logits.shape[-1]), labels.view(-1))        else:            # compute usual loss via models            loss, logits = model(**inputs, labels=labels, use_cache=False)[:2]    else:        # compute label smoothed loss        logits = model(**inputs, use_cache=False)[0]        lprobs = torch.nn.functional.log_softmax(logits, dim=-1)        loss, _ = self.loss_fn(lprobs, labels, self.args.label_smoothing, ignore_index=self.config.pad_token_id)    return loss, logits