Give `modeling_t5.py` a `_prune_heads`
Author: CaffreyR
Pull request: yes

# What does this PR do?

<!--
Congratulations! You've made it this far! You're not quite done yet though.

Once merged, your PR is going to appear in the release notes with the title you set, so make sure it's a great title that fully reflects the extent of your awesome contribution.

Then, please replace this with a description of the change and which issue is fixed (if applicable). Please also include relevant motivation and context. List any dependencies (if any) that are required for this change.

Once you're done, someone will review your PR shortly (see the section "Who can review?" below to tag some potential reviewers). They may suggest changes to make the code even better. If no one reviewed your PR after a week has passed, don't hesitate to post a new comment @-mentioning the same persons---sometimes notifications get lost.
--> 

<!-- Remove if not applicable -->

Fixes # (issue) 19960 (not perfectly)
I refer a colab script in issue, it can prune but with forward problems. 
You can see here https://colab.research.google.com/drive/1b9mHjtn2UxuHU_Sb_RXts12rDzbebBX0#scrollTo=hUSe4a1oOp6D


I use `opendelta` to visualize the  pruning process.

But we seems to be a forward problem


## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#start-contributing-pull-requests),
      Pull Request section?
- [x] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [x] Did you make sure to update the documentation with your changes? Here are the
      [documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
      [here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
- [x] Did you write any new necessary tests?


## Who can review?

@ArthurZucker

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

<!-- Your PR 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: @LysandreJik
- blenderbot, bart, marian, pegasus, encoderdecoder,  t5: @patrickvonplaten, @patil-suraj
- longformer, reformer, transfoxl, xlnet: @patrickvonplaten
- fsmt: @stas00
- funnel: @sgugger
- gpt2: @patrickvonplaten, @LysandreJik
- rag: @patrickvonplaten, @lhoestq
- tensorflow: @LysandreJik

Library:

- benchmarks: @patrickvonplaten
- deepspeed: @stas00
- ray/raytune: @richardliaw, @amogkam
- text generation: @patrickvonplaten
- tokenizers: @n1t0, @LysandreJik
- trainer: @sgugger
- pipelines: @LysandreJik

Documentation: @sgugger

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
- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->


Comments:
Great work! Fell free to ping me for a review 👍

Hi @ArthurZucker , please pay more attention to the `position_bias`, I think I change it too sharply otherwise the shape will not be the same to the `score`

Hi @ArthurZucker , I upload a new commits, it seems better deal with `position_bias`. And if we do not add `head_mask` and `decoder_head_mask` in the model `forward`, the code can run. But we just ignore this line's problem.

https://github.com/huggingface/transformers/blob/c3a93d8d821bc1df3601ba858e7385eada8db3a5/src/transformers/models/t5/modeling_t5.py#L547





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

Okay! That's way better, the least code we change the better. I remember seeing a similar fix, let me link that and I think we will be able to merge if slow tests pass 👍

Great @ArthurZucker ! What other tests should be done? 

gently pin @patrickvonplaten Thanks

Hey, the tests are simply the CircleCI tests! Try running `make fixup` and `make fix-copies`. The integrations tests have to pass to be able to merge the PR! 

Hi @ArthurZucker  I have try to pull new request after `make fixup` and `make fix-copies`, but it still can not pass CircleCI :(

Hey! You didn't have to open a new PR! I will have a look and help you fix the tests ☺️

OK then ! Thanks! It seems my flat can not work on the `make fixup`

Okay, it seems that #19097 also wanted to adress part of this issue. Since it has not really progressed, we can do everything here

Great! Anything that I can help?


OKay, try running : 
- `make style` to pass the `check_code_quality` 
- `git pull upstream main` to merge the changes from the `huggingface/transformers/main` branch. 
Then we will try to debug the tests that are failing. 
You can also do this by running `RUN_SLOW=1 pytest tests/models/t5/test_modeling_t5.py`. 

Hi @ArthurZucker ,I try to `make style`, it reports error ! And this commits seems unsuccessful
```
All done! ✨ 🍰 ✨
597 files reformatted, 1299 files left unchanged.
isort examples tests src utils
Skipped 1 files
/Library/Developer/CommandLineTools/usr/bin/make autogenerate_code
running deps_table_update
updating src/transformers/dependency_versions_table.py
/Library/Developer/CommandLineTools/usr/bin/make extra_style_checks
python utils/custom_init_isort.py
python utils/sort_auto_mappings.py
doc-builder style src/transformers docs/source --max_len 119 --path_to_docs docs/source
make[1]: doc-builder: No such file or directory
make[1]: *** [extra_style_checks] Error 1
make: *** [style] Error 2

```

Maybe it is my machine's problem of `make style`? @ArthurZucker  Macbook pro with m1 maybe? I could not install `doc-builder`


No, the error is from the missing `huggingface_doc` package ! Don't worry. Try installing it. 
The files should still have been formatted 

OK! I install it and rerun `make style` and `python utils/check_copies.py --fix_and_overwrite`
Hope it will work this time

Hi @ArthurZucker it seems that `make style` can run well on linux but cannot run well in macOS system. :) Maybe it is better to find a new method for Apple M1 :)

Hi @ArthurZucker , could you please give me a review? Many thanks!

Hi @ArthurZucker  


Hey, let's try to rebase to `be59316681fca13483da0ac2eac341f7df090e35`, since a loooot of files were modified by make style ( and this is not normal!). The issue most probably comes from your version of `black.  `pip install hf-doc-builder` or upgrading it sould solve this! 
I will review once that's clean! I can also help with make style if you are still unable to have the expected result! 🤗  

Hi @ArthurZucker , what is rebase? BTW? Could you please help me make style? Since my machine's version is too tricky

Let me re-fork the link it seems too dirty at this point