please note that the behavior(shift_tokens_right) in BartModel and BartForConditionalGeneration is different

  
      github.com
  
  
    huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py#L1140 1

    use_cache=None,
    output_attentions=None,
    output_hidden_states=None,
    return_dict=None,
):

    # different to other models, Bart automatically creates decoder_input_ids from
    # input_ids if no decoder_input_ids are provided
    if decoder_input_ids is None and decoder_inputs_embeds is None:
        decoder_input_ids = shift_tokens_right(
            input_ids, self.config.pad_token_id, self.config.decoder_start_token_id
        )

    output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
    output_hidden_states = (
        output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
    )
    use_cache = use_cache if use_cache is not None else self.config.use_cache
    return_dict = return_dict if return_dict is not None else self.config.use_return_dict

    if encoder_outputs is None:



  
  
    
    
  
  



  
      github.com
  
  
    huggingface/transformers/blob/master/src/transformers/models/bart/modeling_bart.py#L1274 3

    config.vocab_size]`` or -100 (see ``input_ids`` docstring). Tokens with indices set to ``-100`` are ignored
    (masked), the loss is only computed for the tokens with labels in ``[0, ..., config.vocab_size]``.

Returns:
"""
return_dict = return_dict if return_dict is not None else self.config.use_return_dict

if labels is not None:
    if decoder_input_ids is None:
        decoder_input_ids = shift_tokens_right(
            labels, self.config.pad_token_id, self.config.decoder_start_token_id
        )

outputs = self.model(
    input_ids,
    attention_mask=attention_mask,
    decoder_input_ids=decoder_input_ids,
    encoder_outputs=encoder_outputs,
    decoder_attention_mask=decoder_attention_mask,
    head_mask=head_mask,
    decoder_head_mask=decoder_head_mask,



  
  
    
    
  
  


you should consider manual provide decoder_input_ids, and you can get the correct results

擷取1081×134 5.78 KB