Error on fine-tuning XLM like model on SQUaD like dataset
Author: mrm8488
Pull request: no
Labels: name: wontfix

# 🐛 Bug

## Information

I am trying to fine-tune the model [xlm-mlm-100-1280](https://huggingface.co/xlm-mlm-100-1280) on SQuAD v1 dataset like (tydiQA) with the script provided for this task (transformers/examples/run_squad.py) and I get the following error:

```python
Epoch:   0% 0/5 [00:00<?, ?it/s]
Iteration:   0% 0/2383 [00:00<?, ?it/s]Traceback (most recent call last):
  File "/content/transformers/examples/run_squad.py", line 829, in <module>
    main()
  File "/content/transformers/examples/run_squad.py", line 768, in main
    global_step, tr_loss = train(args, train_dataset, model, tokenizer)
  File "/content/transformers/examples/run_squad.py", line 204, in train
    outputs = model(**inputs)
  File "/usr/local/lib/python3.6/dist-packages/torch/nn/modules/module.py", line 532, in __call__
    result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'cls_index'

Epoch:   0% 0/5 [00:00<?, ?it/s]
Iteration:   0% 0/2383 [00:00<?, ?it/s]
```

## To reproduce
```bash
git clone https://github.com/huggingface/transformers
pip install -q ./transformers

# wget "your SQuAD v1 like dataset

python /content/transformers/examples/run_squad.py \
  --model_type xlm \
  --model_name_or_path xlm-mlm-100-1280 \
  --do_lower \
  --do_train \
  --do_eval \
  --train_file /content/dataset/tydiqa-goldp-v1.0-train.json \
  --predict_file /content/dataset/tydiqa-goldp-v1.0-dev.json \
  --per_gpu_train_batch_size 24 \
  --per_gpu_eval_batch_size 128 \
  --learning_rate 3e-5 \
  --num_train_epochs 5 \
  --max_seq_length 384 \
  --doc_stride 128 \
  --output_dir /content/model_output \
  --overwrite_output_dir \
  --save_steps 2000 \
  --threads 400
```

## Environment info
<!-- You can run the command `python transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->
     
- `transformers` version: 2.7.0
- Platform: Linux-4.14.137+-x86_64-with-Ubuntu-18.04-bionic
- Python version: 3.6.9
- PyTorch version (GPU?): 1.4.0 (True)
- Tensorflow version (GPU?): 2.2.0-rc1 (True)
- Using GPU in script?: Yes. Nvidia Tesla P100
- Using distributed or parallel set-up in script?: No


Comments:
Hi, any follow-up in this thread? I have received the same error with yours, but a different parameter  'model_name_or_path = xlm-mlm-tlm-xnli15-1024' is used in my experiment.

I had to revert all the way to 2.5.1 to get this to work (xlnet-base fine-tuning on SQuAD 1.1), FWIW, so it's been broken for a bit...

Thanks @nelson-liu 

Cc @julien-c 

> I had to revert all the way to 2.5.1
Thanks @nelson-liu
using `run_squad.py` at `huggingface/transformers/v2.5.1/examples`
https://raw.githubusercontent.com/huggingface/transformers/v2.5.1/examples/run_squad.py

I encountered a similar error fine-tuning a RoBERTa model on a SWAG-like dataset using the example scripts. The problem appears to be that the transformers.Trainer object defined [here](https://github.com/huggingface/transformers/blob/master/src/transformers/trainer.py) unpacks all the properties of the InputFeatures as arguments to the model's `forward`, like so:
```
for k, v in inputs.items():
    inputs[k] = v.to(self.args.device)
    ...
    outputs = model(**inputs)
```
The problem is that the InputFeatures have properties like example_id that are not valid keyword args for `forward`. (Same problem for this ticket: SquadFeatures has cls_index). 

As a workaround, I'm removing the example_id property from InputFeatures. Long-term, maybe the Trainer should be more selective about which arguments it passes?


`run_squad.py` doesn't currently use the Trainer so this is probably a distinct issue, @steeter-cyclist .

Same query as @andyweizhao. Any updates? Reverting to v2.5.1 throws ImportError: cannot import name 'MODEL_FOR_QUESTION_ANSWERING_MAPPING'

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.


Still occurs
```
Iteration:   0%|                                                                         | 0/44511 [00:00<?, ?it/s]
Epoch:   0%|                                                                                 | 0/4 [00:00<?, ?it/s]
Traceback (most recent call last):
  File "run_squad.py", line 820, in <module>
    main()
  File "run_squad.py", line 763, in main
    global_step, tr_loss = train(args, train_dataset, model, tokenizer)
  File "run_squad.py", line 202, in train
    outputs = model(**inputs)
  File "C:\Users\erann\AppData\Local\Programs\Python\Python38\lib\site-packages\torch\nn\modules\module.py", line 72
2, in _call_impl
    result = self.forward(*input, **kwargs)
TypeError: forward() got an unexpected keyword argument 'cls_index'
```

https://github.com/huggingface/transformers/issues/6360 shows stale-bot already kicked into action in there as well