Qwen2VL fix cos,sin dtypes to float when used with deepspeed
Author: ArdalanM
Pull request: yes

# What does this PR do?

Minor fix for Qwen2VL models where  the sin and cos position embeddings where wrongly casted when used with DeepSpeed.  Related issue (#36187) 

cc @ArthurZucker 🤗

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [ ] 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?

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:

- 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 @MekkCyber

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:
Must have been fixed by https://github.com/huggingface/transformers/pull/36065?

> Must have been fixed by #36065?

Issue is reintroduced by #35837

Yep let's merge this (need to fix the modular fix not the modeling file! 🤗 )

Hey, let's merge this and have in the next patch release (dunno when that will be). Seems to be bothering more people as we wait

@ArdalanM can you please add the same changes in `modular_xxx.py` files and then run `make fix-copies` to make CI happy?

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

@ArdalanM Thanks for the fix! But now we are casting cos/sin embeds to fp32 at each layer, which is not efficient. How about casting them only once at the beginning? That is adding a float32 cast here:
https://github.com/huggingface/transformers/blob/a3201cea1432172febfa94b60ccfa44cc764d5b8/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py#L1020

and removing the cast from here:
https://github.com/huggingface/transformers/blob/a3201cea1432172febfa94b60ccfa44cc764d5b8/src/transformers/models/qwen2_vl/modeling_qwen2_vl.py#L222