Sentence_transformers tracing inference issue
Author: yzGao22
Pull request: no

### System Info

- `transformers` version: 4.34.0
- Platform: Linux-5.15.0-1033-aws-x86_64-with-glibc2.31
- Python version: 3.9.18
- Huggingface_hub version: 0.17.3
- Safetensors version: 0.4.0
- Accelerate version: not installed
- Accelerate config: not found
- PyTorch version (GPU?): 1.13.1+cu117 (False)
- 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?: no
- Using distributed or parallel set-up in script?: no

### Who can help?

@ArthurZucker and @younesbelkada

### Information

- [ ] The official example scripts
- [X] 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

The issue occurs when I tried to neuron trace a sentence_transformers model.
The model page: https://huggingface.co/sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
The tracing guide: https://github.com/philschmid/sentence-transformers-huggingface-inferentia/blob/main/sagemaker-notebook.ipynb

The inference code from these 2 pages are different which makes the traced sentence_transformers model output different sentence embedding, compared to the original model.

Inference code from model page:
```
model_id = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
embed_model = AutoModel.from_pretrained(model_id, torchscript=True)
dummy_input = "dummy input which will be padded later"
max_length = 512

embeddings = tokenizer(dummy_input, max_length=max_length, padding="max_length",return_tensors="pt")
ori_out = embed_model(**embeddings)
sentence_embeddings = mean_pooling(ori_out, embeddings['attention_mask'])
print(sentence_embeddings[0].tolist())
```
Inference code from the tracing guide:
```
model_id = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
embed_model = AutoModel.from_pretrained(model_id, torchscript=True)
dummy_input = "dummy input which will be padded later"
max_length = 512

embeddings = tokenizer(dummy_input, max_length=max_length, padding="max_length",return_tensors="pt")
neuron_inputs = tuple(embeddings.values())
ori_out = embed_model(*neuron_inputs)#for tuple
sentence_embeddings = mean_pooling(ori_out, embeddings['attention_mask'])
print(sentence_embeddings[0].tolist())
```
These 2 codes above output 2 different sentence embedding for a same input sentence.

### Expected behavior

The inference output for traced model should be same as the original model.

Comments:
Hi @yzGao22, thanks for raising this issue! 

For the code examples, the only difference I see is how the inputs are passed to the model. In the first case, using `**` to unpack the dictionary means the inputs are passed in as keywords and is equivalent to: 

```
ori_out = embed_model(
    input_ids=input_ids, 
    token_type_ids=token_type_ids, 
    attention_mask=attention_mask
)
```

In the second case, the values of the dictionary are taken, cast as a tuple and passed using `*` to unpack, which is equivalent to:

```
ori_out = embed_model(input_ids,  token_type_ids, attention_mask)
```

If you look at the forward signature for [BertModel](https://github.com/huggingface/transformers/blob/4557a0dede92ce985576fac478b754d76bba3c18/src/transformers/models/bert/modeling_bert.py#L910), you'll notice that the order of the input arguments is input_ids, attention_mask, token_type_ids, and so passing in as positional arguments using `* neuron_inputs` results in the wrong arrays being assigned to the forward arguments. 

You can create the input tuple by simply doing:

```py
neuron_inputs =(embeddings['input_ids'], embeddings['attention_mask'], embeddings['token_type_ids'])
```

cc @philschmid as it seems the current code in transformers is out-of-sync with the linked blog :) 

The problem solved. Thank you @amyeroberts