compute_metric is not being shown
Author: rdstettler
Pull request: no
Labels: name: trainer

name: bug

### System Info

transformers 4.38.0
python 3.9.6

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction



```

from transformers import AutoTokenizer
from peft import get_peft_model
from transformers import AutoModelForSequenceClassification
from peft import LoraConfig
from datasets import load_dataset
import evaluate
dataset = load_dataset("dair-ai/emotion")
splits = ['train', 'validation', 'test']

model = AutoModelForSequenceClassification.from_pretrained(
  "distilbert-base-uncased",
  num_labels=6,
  id2label={0: 'sadness', 1: 'joy', 2: 'love', 3: 'anger', 4: 'fear', 5: 'surprise'},
  label2id={'sadness': 0, 'joy': 1, 'love': 3, 'anger': 4, 'fear': 5, 'surprise': 6}
)
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
tokenizer.pad_token = tokenizer.eos_token
tokenizer.add_special_tokens({'pad_token': '[PAD]'})

config = LoraConfig()
config.pad_token_id = 50256
config.target_modules = ["classifier"]

peft_model = get_peft_model(model, config)

tokenized_dataset = {}
for split in splits:
    tokenized_dataset[split] = dataset[split].map(
        lambda x: tokenizer(x["text"], padding=True, truncation=True),
        batched=True
    )

metric = evaluate.load("accuracy")

def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    predictions = predictions.argmax(-1)
    return metric.compute(predictions=predictions, references=labels)

from transformers import Trainer, TrainingArguments
from transformers import DataCollatorWithPadding
from accelerate import Accelerator

# Set up the Trainer
training_args = TrainingArguments(
    output_dir="./results",
    num_train_epochs=1,
    per_device_train_batch_size=16,
    per_device_eval_batch_size=16,
    learning_rate=2e-5,
    evaluation_strategy="epoch",
    save_strategy="epoch",
    weight_decay=0.01,
    load_best_model_at_end=True,
    do_eval=True,
    do_predict=True,
    metric_for_best_model="accuracy",
    label_names=["label"],
)
trainer = Trainer(
    model=peft_model,
    args=training_args,
    train_dataset=tokenized_dataset["train"],
    eval_dataset=tokenized_dataset["test"],
    tokenizer=tokenizer,
    data_collator=DataCollatorWithPadding(tokenizer),
    compute_metrics=compute_metrics,
)

results = trainer.evaluate()
print(results)
```


### Expected behavior

Full script to reproduce behavior
At the end, I expect to see the compute_metric result, but only eval_runtime, eval_samples_per_second and eval_steps_per_second are being shown. 
I also tried with 

`
def compute_metrics(eval_pred):
    predictions, labels = eval_pred
    predictions = predictions.argmax(-1)
    return {'accuracy', metric.compute(predictions=predictions, references=labels)}
`

I figured, that when I change model to model (not peft_model) the trainer correctly computes the accuracy, now why not with peft model?

Comments:
cc @muellerzr @pacman100 

@rdstettler I had the same issue. Not sure if you managed to resolve this but changing `label_names=["label"]` to `label_names=["labels"]` fixed it for me: https://github.com/huggingface/peft/issues/782#issuecomment-1670703455.

This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.

> @rdstettler I had the same issue. Not sure if you managed to resolve this but changing `label_names=["label"]` to `label_names=["labels"]` fixed it for me: [huggingface/peft#782 (comment)](https://github.com/huggingface/peft/issues/782#issuecomment-1670703455).

Thanks! Adding this on the **TrainingArguments** also solved the issue!

I'm doing multi task classification and I have: 
`label_names` = ['line_label', 'cat_label', 'sub_cal_label', 'motive_label']`
I will try to modify it. But this should be looked into you should be able to choose the label name and not be constraint in your label name of choice.

> > @rdstettler I had the same issue. Not sure if you managed to resolve this but changing `label_names=["label"]` to `label_names=["labels"]` fixed it for me: [huggingface/peft#782 (comment)](https://github.com/huggingface/peft/issues/782#issuecomment-1670703455).
> 
> Thanks! Adding this on the **TrainingArguments** also solved the issue!

This worked for me too!