How was self.loss_function implemented

Hi, I was curious about how the self.loss_function is implemented in the Qwen2.5-VL model to compute the loss during training.
Could someone explain how it works or point me to the relevant part of the code?

Here’s the link to the line I’m referring to:

Thanks in advance!

Maybe this?

Thank you so much for sharing. However, these issues predated the Transformers version 4.53.0.dev0. What I want to know is where the self.loss_function was implemented for these models so I can modify it correctly.

Thank you!

The loss functions are defined in src/transformers/loss/loss_utils.py. The logic for selecting which loss function to use is implemented in the PreTrainedModel class, located in src/transformers/modeling_utils.py.

link: transformers/src/transformers/loss/loss_utils.py at main · huggingface/transformers · GitHub
link: transformers/src/transformers/modeling_utils.py at main · huggingface/transformers · GitHub