input_inds greater than the vocab_size in Question answering example
Author: yiliu30
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.21.0.dev0
- Platform: Linux-3.10.0-693.el7.x86_64-x86_64-with-glibc2.17
- Python version: 3.9.12
- Huggingface_hub version: 0.8.1
- PyTorch version (GPU?): 1.12.0+cu102 (False)
- Tensorflow version (GPU?): 2.9.1 (False)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in

### Who can help?

@SaulLu, @sgugger, @patil-suraj

### Information

- [X] The official example scripts
- [ ] My own modified scripts

### Tasks

- [X] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Hi, I got some errors when I run the [Question answering example](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/question-answering).
My commands:

```
cd /transformers/transformers/examples/tensorflow/question-answering

python run_qa.py --model_name_or_path distilbert-base-cased --output_dir output --dataset_name squad --do_train --do_eval
```

Error msg:
```
XXX: W tensorflow/core/framework/dataset.cc:768] Input of GeneratorDatasetOp::Dataset will not be optimized because the dataset does not implement the AsGraphDefInternal() method needed to apply optimizations.
Epoch 1/3
Traceback (most recent call last):
  File "/path1/xxxx/workdir/traner_env/transformers/examples/tensorflow/question-answering/run_qa.py", line 703, in <module>
    main()
  File "/path1/xxxx/workdir/traner_env/transformers/examples/tensorflow/question-answering/run_qa.py", line 487, in main
    processed_datasets["train"] = train_dataset
  File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 54, in quick_execute
    tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
tensorflow.python.framework.errors_impl.InvalidArgumentError: Graph execution error:

Detected at node 'tf_distil_bert_for_question_answering/distilbert/embeddings/Gather' defined at (most recent call last):
    File "/path1/xxxx/workdir/traner_env/transformers/examples/tensorflow/question-answering/run_qa.py", line 703, in <module>
      main()
    File "/path1/xxxx/workdir/traner_env/transformers/examples/tensorflow/question-answering/run_qa.py", line 487, in main
      processed_datasets["train"] = train_dataset
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/training.py", line 1409, in fit
      tmp_logs = self.train_function(iterator)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/training.py", line 1051, in train_function
      return step_function(self, iterator)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/training.py", line 1040, in step_function
      outputs = model.distribute_strategy.run(run_step, args=(data,))
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/training.py", line 1030, in run_step
      outputs = model.train_step(data)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/modeling_tf_utils.py", line 1409, in train_step
      y_pred = self(x, training=True)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/training.py", line 490, in __call__
      return super().__call__(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/base_layer.py", line 1014, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/modeling_tf_utils.py", line 1012, in run_call_with_unpacked_inputs
      _auto_class = None
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/models/distilbert/modeling_tf_distilbert.py", line 1029, in call
      distilbert_output = self.distilbert(
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/base_layer.py", line 1014, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/modeling_tf_utils.py", line 1012, in run_call_with_unpacked_inputs
      _auto_class = None
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/models/distilbert/modeling_tf_distilbert.py", line 400, in call
      embedding_output = self.embeddings(input_ids, inputs_embeds=inputs_embeds)  # (bs, seq_length, dim)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 64, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/engine/base_layer.py", line 1014, in __call__
      outputs = call_fn(inputs, *args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/keras/utils/traceback_utils.py", line 92, in error_handler
      return fn(*args, **kwargs)
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/models/distilbert/modeling_tf_distilbert.py", line 112, in call
      if input_ids is not None:
    File "/path1/xxxx/anaconda3/envs/traner_env/lib/python3.9/site-packages/transformers/models/distilbert/modeling_tf_distilbert.py", line 113, in call
      inputs_embeds = tf.gather(params=self.weight, indices=input_ids)
Node: 'tf_distil_bert_for_question_answering/distilbert/embeddings/Gather'
indices[4,22] = 29261 is not in [0, 28996)
         [[{{node tf_distil_bert_for_question_answering/distilbert/embeddings/Gather}}]] [Op:__inference_train_function_12652]

```

It seem that the `vocab_size` or the tokenizer has some issue?





### Expected behavior

I want to run the demo by the [descried command](https://github.com/huggingface/transformers/tree/main/examples/tensorflow/question-answering#example-command). 
If you need other information to reproduce the error, pls let me know.
Thanks :)

Comments:
The max of `input_ids` is 30511.

This is a TensorFlow example, so you tagged the wrong persons :-) cc @Rocketknight1 @gante 

Hi @yiliu30 I have just tried your command with the latest version of `transformers` installed from `main` and TensorFlow 2.9.1 and could not reproduce the issue. Can you install the latest versions of `transformers` and `datasets` from main/master and confirm that the issue is still occurring? 

Hi @Rocketknight1, this issue solved by install `datasets` from main instead of `pip`. 
BTW, may I know the possible deep reason for this issue?
Thanks.

@yiliu30 I'm not sure, I'm afraid! It's possible that there was some incompatibility between newer versions of `transformers` and your older version of `datasets`.

okay, thanks a lot.