Error using evaluation in run_clm.py
Author: andstor
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.17.0.dev0
- Platform: Linux-4.18.0-193.el8.x86_64-x86_64-with-glibc2.10
- Python version: 3.8.3
- PyTorch version (GPU?): 1.10.2+cu113 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: Yes
- Using distributed or parallel set-up in script?: Yes

### Who can help
@stas00, @patil-suraj

<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- ALBERT, BERT, XLM, DeBERTa, DeBERTa-v2, ELECTRA, MobileBert, SqueezeBert: @LysandreJik
- T5, BART, Marian, Pegasus, EncoderDecoder: @patrickvonplaten
- Blenderbot, MBART: @patil-suraj
- Longformer, Reformer, TransfoXL, XLNet, FNet, BigBird: @patrickvonplaten
- FSMT: @stas00
- Funnel: @sgugger
- GPT-2, GPT: @patrickvonplaten, @LysandreJik
- RAG, DPR: @patrickvonplaten, @lhoestq
- TensorFlow: @Rocketknight1
- JAX/Flax: @patil-suraj
- TAPAS, LayoutLM, LayoutLMv2, LUKE, ViT, BEiT, DEiT, DETR, CANINE: @NielsRogge
- GPT-Neo, GPT-J, CLIP: @patil-suraj
- Wav2Vec2, HuBERT, SpeechEncoderDecoder, UniSpeech, UniSpeechSAT, SEW, SEW-D, Speech2Text: @patrickvonplaten, @anton-l

If the model isn't in the list, ping @LysandreJik who will redirect you to the correct contributor.

Library:

- Benchmarks: @patrickvonplaten
- Deepspeed: @stas00
- Ray/raytune: @richardliaw, @amogkam
- Text generation: @patrickvonplaten @narsil
- Tokenizers: @SaulLu
- Trainer: @sgugger
- Pipelines: @Narsil
- Speech: @patrickvonplaten, @anton-l
- Vision: @NielsRogge, @sgugger

Documentation: @sgugger

Model hub:

- for issues with a model, report at https://discuss.huggingface.co/ and tag the model's creator.

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj

For research projetcs, please ping the contributor directly. For example, on the following projects:

- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

## Information

Model I am using: GPT-J-6B
Running on GPU cluster with 10 x NVIDIA A100 40G

The problem arises when using:
* [x] the official example scripts: (give details below)
* [ ] my own modified scripts: (give details below)

The tasks I am working on is:
* [ ] an official GLUE/SQUaD task: (give the name)
* [x] my own task or dataset: (give details below)

Purpose is to fine-tune GPT-J for generating smart contract code. 

## To reproduce

Steps to reproduce the behavior:

Run example training script `transformers/examples/pytorch/language-modeling/run_clm.py`.

HF launch script:

```bash
deepspeed --num_gpus=10 ./examples/pytorch/language-modeling/run_clm.py \
--deepspeed ./ds_config.json \
--model_name_or_path EleutherAI/gpt-j-6B \
--run_name gpt-j \
--dataset_name andstor/smart_contracts \
--dataset_config_name andstor--smart_contracts \
--output_dir ./finetuned \
--save_steps 100 \
--report_to all \
--logging_first_step \
--logging_steps 5 \
--evaluation_strategy steps \
--eval_steps 5 \
--block_size 1024 \
--do_train \
--do_eval \
--fp16 true \
--num_train_epochs 2 \
--gradient_accumulation_steps 2 \
--eval_accumulation_steps 2 \
--per_device_train_batch_size 1 \
--per_device_eval_batch_size 1
```

DeepSpeed config:

```json
{
    "fp16": {
        "enabled": "auto",
        "loss_scale": 0,
        "loss_scale_window": 1000,
        "initial_scale_power": 16,
        "hysteresis": 2,
        "min_loss_scale": 1
    },
    "optimizer": {
        "type": "AdamW",
        "params": {
            "lr": "auto",
            "betas": "auto",
            "eps": "auto",
            "weight_decay": "auto"
        }
    },
    "scheduler": {
        "type": "WarmupLR",
        "params": {
            "warmup_min_lr": "auto",
            "warmup_max_lr": "auto",
            "warmup_num_steps": "auto"
        }
    },
    "zero_optimization": {
        "stage": 2,
        "allgather_partitions": true,
        "allgather_bucket_size": 2e8,
        "overlap_comm": true,
        "reduce_scatter": true,
        "reduce_bucket_size": 2e8,
        "contiguous_gradients": true,
        "cpu_offload": true
    },
    "gradient_accumulation_steps": "auto",
    "gradient_clipping": "auto",
    "train_batch_size": "auto",
    "train_micro_batch_size_per_gpu": "auto",
    "wall_clock_breakdown": false
}
```

Fails with this error:
```python-traceback
Traceback (most recent call last): 
  File "./examples/pytorch/language-modeling/run_clm.py", line 541, in <module> 
    main() 
  File "./examples/pytorch/language-modeling/run_clm.py", line 489, in main 
    train_result = trainer.train(resume_from_checkpoint=checkpoint) 
  File "/cluster/home/andstorh/transformers/.venv/lib/python3.8/site-packages/transformers/trainer.py", line 1473, in train 
    self._maybe_log_save_evaluate(tr_loss, model, trial, epoch, ignore_keys_for_eval) 
  File "/cluster/home/andstorh/transformers/.venv/lib/python3.8/site-packages/transformers/trainer.py", line 1600, in _maybe_log_save_evaluate 
    metrics = self.evaluate(ignore_keys=ignore_keys_for_eval) 
  File "/cluster/home/andstorh/transformers/.venv/lib/python3.8/site-packages/transformers/trainer.py", line 2255, in evaluate 
    output = eval_loop( 
  File "/cluster/home/andstorh/transformers/.venv/lib/python3.8/site-packages/transformers/trainer.py", line 2446, in evaluation_loop 
    logits = self.preprocess_logits_for_metrics(logits, labels) 
  File "./examples/pytorch/language-modeling/run_clm.py", line 457, in preprocess_logits_for_metrics 
    return logits.argmax(dim=-1) 
AttributeError: 'tuple' object has no attribute 'argmax' 
```

The model runs fine without evaluation turned on.

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior
The example script should run without producing an error.


Comments:
Most likely this PR https://github.com/huggingface/transformers/pull/15473 introduced the breakage, since this code didn't exist before:

https://github.com/huggingface/transformers/blob/130b987880a9b1ade5c76dc1413c12c8924fda50/examples/pytorch/language-modeling/run_clm.py#L456-L457

Most likely the new code has been merged w/o a test exercising this particular code path and your use case triggered the issue.

pinging the author: @davidleonfdez and the reviewer: @sgugger 

to unblock you, @andstor, until this is sorted out please switch to a commit before that PR, that is:

```
git clone https://github.com/huggingface/transformers
cd transformers
git checkout 4f5faaf04407d4
```

Indeed, the problem comes from the model returning more than one logit (it has `use_cache` set to `True` in its config) which we didn't anticipate in that PR. I will send a fix when I have time.

Thanks ❤️ 
Switch to the commit before that PR did do the trick 👌

> Indeed, the problem comes from the model returning more than one logit (it has `use_cache` set to `True` in its config) which we didn't anticipate in that PR. I will send a fix when I have time.

Sorry, maybe I wasn't as careful with the examples as I should have been 😞. I've just learned about `past_key_values`. I had tested the example with GPT2, whose config has `keys_to_ignore_at_inference = ["past_key_values"]`, so it doesn't return a tuple. I can try to fix it. 


@davidleonfdez If you want to work on a fix, look at how the `compute_metrics` in the `run_glue` script is defined. I believe you just need to add a similar test as [this one](https://github.com/huggingface/transformers/blob/4cd7ed4b3b7360aef3a9fb16dfcc105001188717/examples/pytorch/text-classification/run_glue.py#L448) at the beginning of the `preprocess_logits_for_metrics` function for the case where the model returns more than one logit.

> @davidleonfdez If you want to work on a fix, look at how the `compute_metrics` in the `run_glue` script is defined. I believe you just need to add a similar test as [this one](https://github.com/huggingface/transformers/blob/4cd7ed4b3b7360aef3a9fb16dfcc105001188717/examples/pytorch/text-classification/run_glue.py#L448) at the beginning of the `preprocess_logits_for_metrics` function for the case where the model returns more than one logit.

Thanks!