Yet, after Training for an hour, It went to do an evaluation and I got this error;
TypeError: compute_loss() got an unexpected
keyword argument 'return_outputs'
I don’t have compute_loss() variable within my code so I don’t think it was me inputting something to it. I was thinking perhaps it has to do with my custom loss?
by the way, this is my trainer:
trainer = MyTrainer(
args=training_args, # training arguments, defined above
train_dataset=train_dataset, # training dataset
eval_dataset=val_dataset, # evaluation dataset
model_init=model_init,
compute_metrics=compute_metrics,
First of all, thank you @lewtun for all your input, you have been helping me loads the past few days and I am really grateful! This forum is amazing.
Just one thing, I am not too sure about what’s in the return, because the loss and the output are there
Would it be
return (loss(logits, labels), outputs) if return_output else loss
or we don’t need to call the logits and labels into loss, like what you did?
I think in your case what you might need is something like
return (loss(logits, labels), outputs) if return_output else loss(logits, labels)
since my understanding is that your loss object is really a loss function and we should be returning a scalar in compute_loss. As a sanity check you can try feeding some inputs to your function to see what the outputs look like, e.g.
ok it seems there is a problem with the nested_detach function. do your inputs have a labels field (which seems to be the default for self.label_names)?
if that doesn’t solve the problem, my suggestion would be to try debug the prediction_step function by getting a batch of inputs and seeing what happens when you apply nested_detach to them
I am only trying to do this because my dataset is unbalanced and I want the loss function to take that into consideration…
Im not even sure what input is, from what I understand it is the data from the training data loader, if the so, it should have a labels field, seeing I defined it as follows
import torch
class SequenceDataset(torch.utils.data.Dataset):
def __init__(self, encodings, labels):
self.encodings = encodings
self.labels = labels
def __getitem__(self, idx):
item = {key: torch.tensor(val[idx]) for key, val in self.encodings.items()}
item['label'] = torch.tensor(self.labels[idx])
return item
def __len__(self):
return len(self.labels)
I see you run into the same issue in the end of this notebook. Did you find a solution?
Oh thanks for flagging the example in the doc was not up to date. If any of you want to open a PR to fix it that would be awesome!
For the labels problem, I think from what I see in the stack trace that you do not have an install from source. There was a bug recently fixed (basically your compute_loss function pops the labels out of the inputs so they are not there anymore, now we copy them before the compute_loss to avoid that).