-
Notifications
You must be signed in to change notification settings - Fork 28.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: CustomTrainer.compute_loss() got an unexpected keyword argument 'num_items_in_batch' #36331
Comments
how is your compute loss defined ? we changed a couple of things with compute loss recently in Trainer and now it requires to have this new arg which is indeed a bit breaking. the issue you have is that it is being called when training to model here: |
def compute_loss(self, model, inputs, return_outputs=False):
input_ids, labels, attention_mask = inputs
# forward pass
outputs = model(input_ids,labels=labels, attention_mask=attention_mask)
# logits = outputs.get("logits")
loss = outputs.loss
# # compute custom loss (suppose one has 3 labels with different weights)
# loss_fct = nn.CrossEntropyLoss(weight=torch.tensor([1.0, 2.0, 3.0], device=model.device))
# loss = loss_fct(logits.view(-1, self.model.config.num_labels), labels.view(-1))
return (loss, outputs) if return_outputs else loss |
|
Could you try the PR above @bialatoheeb @ruidazeng without your changes ? |
This should work only if you specified |
System Info
transformers
version: 4.50.0.dev0Who can help?
@muellerzr @SunMarc
Information
Tasks
examples
folder (such as GLUE/SQuAD, ...)Reproduction
My code:
Error Info:
Data Set: https://huggingface.co/datasets/locuslab/TOFU
Expected behavior
Why would there be a compute_loss() error? I never gave a
num_items_in_batch
argument.The text was updated successfully, but these errors were encountered: