Enabled Flash Attention for PaliGemma models
Author: aroun-coumar
Pull request: yes
Labels: name: Flash Attention

name: Multimodal

name: run-slow

# 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 #33963 

## 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#create-a-pull-request),
      Pull Request section?
- [ ] 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.
- [ ] 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).
- [ ] Did you write any new necessary tests?


## Who can review?

@qubvel 

<!-- 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:

- text models: @ArthurZucker
- vision models: @amyeroberts, @qubvel
- speech models: @ylacombe, @eustlb
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc

Documentation: @stevhliu

HF projects:

- accelerate: [different repo](https://github.com/huggingface/accelerate)
- datasets: [different repo](https://github.com/huggingface/datasets)
- diffusers: [different repo](https://github.com/huggingface/diffusers)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Maintained examples (not research project or legacy):

- Flax: @sanchit-gandhi
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
@qubvel Please review the changes and comment 
Thanks!

make modified_only_fixup

all the tests passed but,
```
(myvenv)
Arun kumar@LAPTOP-0U925LO8 MINGW64 ~/OneDrive/Desktop/Transformers/transformers (enable-flash-attention-paligemma)
$ make repo-consistency
python utils/check_copies.py
python utils/check_modular_conversion.py

Differences found between the generated code and
src/transformers/models\gemma\modeling_gemma.py:

   1 --- src/transformers/models\gemma\modeling_gemma.py_generated
   2 +++ src/transformers/models\gemma\modeling_gemma.py
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 Google Inc. HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\gemma\configuration_gemma.py:

   1 --- src/transformers/models\gemma\configuration_gemma.py_generated
   2 +++ src/transformers/models\gemma\configuration_gemma.py
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 Google Inc. HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\gemma2\modeling_gemma2.py:

   1 --- src/transformers/models\gemma2\modeling_gemma2.py_generated
   2 +++ src/transformers/models\gemma2\modeling_gemma2.py
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 Google Inc. HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\gemma2\configuration_gemma2.py:

   1 --- src/transformers/models\gemma2\configuration_gemma2.py_generated
   2 +++ src/transformers/models\gemma2\configuration_gemma2.py
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 Google Inc. HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\instructblipvideo\modeling_instructblipvideo.py:

   1 --- src/transformers/models\instructblipvideo\modeling_instructblipvideo.p
   2 +++ src/transformers/models\instructblipvideo\modeling_instructblipvideo.p
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\instructblipvideo\configuration_instructblipvideo.py:

   1 --- src/transformers/models\instructblipvideo\configuration_instructblipvi
   2 +++ src/transformers/models\instructblipvideo\configuration_instructblipvi
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\llava_next_video\modeling_llava_next_video.py:

   1 --- src/transformers/models\llava_next_video\modeling_llava_next_video.py_
   2 +++ src/transformers/models\llava_next_video\modeling_llava_next_video.py
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  14  #

Differences found between the generated code and
src/transformers/models\llava_next_video\configuration_llava_next_video.py:

   1 --- src/transformers/models\llava_next_video\configuration_llava_next_vide
   2 +++ src/transformers/models\llava_next_video\configuration_llava_next_vide
   3 @@ -1,9 +1,9 @@
   4 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
   5 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
   6  #               This file was automatically generated from <path_to_modul
   7  #         Do NOT edit this file manually as any edits will be overwritten
   8  #         the file from the modular. If any change should be done, please
   9  #                           modular_xxx.py file directly. One of our CI e
  10 -#           🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨
  11 +#           ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ðŸš¨ð
  12  # coding=utf-8
  13  # Copyright 2024 HuggingFace Inc. team. All rights reserved.
  14  #
Traceback (most recent call last):
  File "C:\Users\Arun kumar\OneDrive\Desktop\Transformers\transformers\utils\check_modular_conversion.py", line 76, in <module>
    raise ValueError("Some diff and their modeling code did not match.")
ValueError: Some diff and their modeling code did not match.
make: *** [Makefile:39: repo-consistency] Error 1
```
Can you please point out what might be wrong?
I couldnt fix this part 

Thanks!

Hi @aroun-coumar 

The following error is in CI:
ValueError: paligemma should be in listed in the flash attention documentation but is not. Please update the documentation.

You have to add the model to the following doc file:
https://github.com/huggingface/transformers/blob/main/docs/source/en/perf_infer_gpu_one.md

Hey @qubvel Thanks a lot!

All the tests passed 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_34009). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

Can you please once again push `[run_slow] paligemma`, it should be the last commit to run slow tests

Hey @qubvel the single and multi gpu tests didnt pass.

i couldnt figure it out from the ci tests

I an working on it , if you find out what might be the problem Please let me know

Hey @qubvel  sorry but i cant circle down the cause of this error
Both the GPU tests fail
Please give some suggestion how to debug this

Thanks

Hi, I will take a look next week! Thanks for patience!