Remove unnecessary `view`s of `position_ids`
Author: ramiro050
Pull request: yes

When `position_ids` is `None`, its value is generated using `torch.arange`, which creates a tensor of size `(seq_length + initial_val) - initial_val = seq_length`. The tensor is then unsqueezed, resulting in a tensor of shape `(1, seq_length)`. This means that the last `view` to a tensor of shape `(-1, seq_length)` is a no-op.

Simiarly, when `position_ids` is not `None`, the documentation for the models specifies that it should be of shape `(batch_size, seq_length)`, making the `view` made in this case also unnecessary.

This commit removes the unnecessary views.

@gante @ArthurZucker

Comments:
For context, I work in the [Torch-MLIR project](https://github.com/llvm/torch-mlir), which converts PyTorch models into [MLIR](https://mlir.llvm.org/). Handling the `view` op in its most general form (especially the use of `-1`s) has been a big challenge for us for a while now (there's some work we need to do to improve the shape information propagation and dynamic shape support in our project). While the goal is to support this as is in the future, in the short term, removing this `view` from the computation would unblock us to run LLaMA in our compiler.


pinging @gante for a second look 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_26059). All of your documentation changes will be reflected on that endpoint.

Running `RUN_SLOW=1 pytest tests/models/llama`, I get `172 passed, 47 skipped, 35 warnings`. The warnings are either due to deprecation or from using PyTorch's tracer; they don't seem related to the changes in this PR. The skipped tests are these:

```
test_modeling_llama.py::LlamaModelTest::test_cpu_offload SKIPPED (test requires CUDA)
test_modeling_llama.py::LlamaModelTest::test_disk_offload SKIPPED (test requires CUDA)
test_modeling_llama.py::LlamaModelTest::test_equivalence_flax_to_pt SKIPPED (test is PT+FLAX test)
test_modeling_llama.py::LlamaModelTest::test_equivalence_pt_to_flax SKIPPED (test is PT+FLAX test)
test_modeling_llama.py::LlamaModelTest::test_model_parallel_beam_search SKIPPED (test requires multiple GPUs)
test_modeling_llama.py::LlamaModelTest::test_model_parallel_equal_results SKIPPED (test requires multiple GPUs)
test_modeling_llama.py::LlamaModelTest::test_model_parallelism SKIPPED (test requires multiple GPUs)
test_modeling_llama.py::LlamaModelTest::test_model_parallelization SKIPPED (test requires multiple GPUs)
test_modeling_llama.py::LlamaModelTest::test_multi_gpu_data_parallel_forward SKIPPED (test requires multiple GPUs)
test_modeling_llama.py::LlamaModelTest::test_pipeline_audio_classification SKIPPED (LlamaModelTest::test_pipeline_audio_classification is skipped: `audio-classification` is not in `self.pipeline_model_mapping` for `...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_automatic_speech_recognition SKIPPED (LlamaModelTest::test_pipeline_automatic_speech_recognition is skipped: `automatic-speech-recognition` is not in `self.pipel...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_conversational SKIPPED (LlamaModelTest::test_pipeline_conversational is skipped: `conversational` is not in `self.pipeline_model_mapping` for `LlamaModelTest`.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_depth_estimation SKIPPED (LlamaModelTest::test_pipeline_depth_estimation is skipped: `depth-estimation` is not in `self.pipeline_model_mapping` for `LlamaModelTe...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_document_question_answering SKIPPED (LlamaModelTest::test_pipeline_document_question_answering is skipped: `document-question-answering` is not in `self.pipeline...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_fill_mask SKIPPED (LlamaModelTest::test_pipeline_fill_mask is skipped: `fill-mask` is not in `self.pipeline_model_mapping` for `LlamaModelTest`.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_image_classification SKIPPED (LlamaModelTest::test_pipeline_image_classification is skipped: `image-classification` is not in `self.pipeline_model_mapping` for `...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_image_segmentation SKIPPED (LlamaModelTest::test_pipeline_image_segmentation is skipped: `image-segmentation` is not in `self.pipeline_model_mapping` for `LlamaM...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_image_to_text SKIPPED (LlamaModelTest::test_pipeline_image_to_text is skipped: `image-to-text` is not in `self.pipeline_model_mapping` for `LlamaModelTest`.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_mask_generation SKIPPED (`run_pipeline_test` is currently not implemented.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_object_detection SKIPPED (LlamaModelTest::test_pipeline_object_detection is skipped: `object-detection` is not in `self.pipeline_model_mapping` for `LlamaModelTe...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_question_answering SKIPPED (LlamaModelTest::test_pipeline_question_answering is skipped: `question-answering` is not in `self.pipeline_model_mapping` for `LlamaM...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_summarization SKIPPED (LlamaModelTest::test_pipeline_summarization is skipped: `summarization` is not in `self.pipeline_model_mapping` for `LlamaModelTest`.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_table_question_answering SKIPPED (LlamaModelTest::test_pipeline_table_question_answering is skipped: `table-question-answering` is not in `self.pipeline_model_ma...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_text2text_generation SKIPPED (LlamaModelTest::test_pipeline_text2text_generation is skipped: `text2text-generation` is not in `self.pipeline_model_mapping` for `...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_text_to_audio SKIPPED (LlamaModelTest::test_pipeline_text_to_audio is skipped: `text-to-audio` is not in `self.pipeline_model_mapping` for `LlamaModelTest`.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_token_classification SKIPPED (LlamaModelTest::test_pipeline_token_classification is skipped: `token-classification` is not in `self.pipeline_model_mapping` for `...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_translation SKIPPED (LlamaModelTest::test_pipeline_translation is skipped: `translation` is not in `self.pipeline_model_mapping` for `LlamaModelTest`.)
test_modeling_llama.py::LlamaModelTest::test_pipeline_video_classification SKIPPED (LlamaModelTest::test_pipeline_video_classification is skipped: `video-classification` is not in `self.pipeline_model_mapping` for `...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_visual_question_answering SKIPPED (LlamaModelTest::test_pipeline_visual_question_answering is skipped: `visual-question-answering` is not in `self.pipeline_model...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_zero_shot_audio_classification SKIPPED (LlamaModelTest::test_pipeline_zero_shot_audio_classification is skipped: `zero-shot-audio-classification` is not in `self...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_zero_shot_image_classification SKIPPED (LlamaModelTest::test_pipeline_zero_shot_image_classification is skipped: `zero-shot-image-classification` is not in `self...)
test_modeling_llama.py::LlamaModelTest::test_pipeline_zero_shot_object_detection SKIPPED (LlamaModelTest::test_pipeline_zero_shot_object_detection is skipped: `zero-shot-object-detection` is not in `self.pipeline_mo...)
test_modeling_llama.py::LlamaModelTest::test_pt_tf_model_equivalence SKIPPED (test is PT+TF test)
test_modeling_llama.py::LlamaModelTest::test_save_load_fast_init_from_base SKIPPED (LLaMA buffers include complex numbers, which breaks this test)
test_modeling_llama.py::LlamaIntegrationTest::test_model_13b_greedy_generation SKIPPED (Model is curently gated)
test_modeling_llama.py::LlamaIntegrationTest::test_model_13b_logits SKIPPED (Logits are not exactly the same, once we fix the instabalities somehow, will update!)
test_modeling_llama.py::LlamaIntegrationTest::test_model_13bf_logits SKIPPED (Logits are not exactly the same, once we fix the instabalities somehow, will update!)
test_modeling_llama.py::LlamaIntegrationTest::test_model_70b_logits SKIPPED (Logits are not exactly the same, once we fix the instabalities somehow, will update! Also it is gonna be a `too_slow` test)
test_modeling_llama.py::LlamaIntegrationTest::test_model_7b_logits SKIPPED (Logits are not exactly the same, once we fix the instabalities somehow, will update!)
test_modeling_llama.py::CodeLlamaIntegrationTest::test_model_7b_logits SKIPPED (test requires CUDA)
test_tokenization_llama.py::LlamaTokenizationTest::test_batch_encode_plus_tensors SKIPPED (test is PT+TF test)
test_tokenization_llama.py::LlamaTokenizationTest::test_pickle_subword_regularization_tokenizer SKIPPED (worker 'gw4' crashed on CI, passing locally.)
test_tokenization_llama.py::LlamaTokenizationTest::test_save_pretrained SKIPPED (Let's wait for the fast tokenizer!)
test_tokenization_llama.py::LlamaTokenizationTest::test_save_slow_from_fast_and_reload_fast SKIPPED (Unfortunately way too slow to build a BPE with SentencePiece.)
test_tokenization_llama.py::LlamaTokenizationTest::test_subword_regularization_tokenizer SKIPPED (worker 'gw4' crashed on CI, passing locally.)
test_tokenization_llama.py::LlamaTokenizationTest::test_tf_encode_plus_sent_to_model SKIPPED (test requires TensorFlow)
test_tokenization_llama.py::LlamaIntegrationTest::test_integration_test_xnli SKIPPED (RUN_TOKENIZER_INTEGRATION=1 to run tokenizer integration tests)
```

@gante, bumping this :)

He is off for a while so won't be able to review this! le me ping @fxmarty for a second look! 👁️ 

> It could be nice to fix it in this PR as well. Some that may be impacted: codgen, gpt2, gpt_neo, gpt_neox, gptj, gpt_bigcode, imagegpt, llama.

Done! PTAL

@ArthurZucker @fxmarty, bumping this

@ArthurZucker, bumping this