I guess you are talking about this line (in the future please link to the code that you are talking about so that we can easily look it up).

  

      github.com
  

  
    huggingface/transformers/blob/143738214cb83e471f3a43652617c8881370342c/src/transformers/data/data_collator.py#L281-L287 1



      
      
          if labels is not None:
              max_label_length = max(len(l) for l in labels)
              padding_side = self.tokenizer.padding_side
              for feature in features:
                  remainder = [self.label_pad_token_id] * (max_label_length - len(feature["labels"]))
                  feature["labels"] = (
                      feature["labels"] + remainder if padding_side == "right" else remainder + feature["labels"]
      
    
  


  

  
    
    
  

  


It is not changing the given labels but it is padding them to ensure that all items in the batch have the same length. Pad tokens are ignored when the loss is calculated.
It is a collator, so it happens after the shuffling process of the dataloader. It receives a number of items from the dataloader (possibly shuffled) and then collates them (prepares them for the model).