remove disabled autocast context and device type calc, as freqs are already force upcast to float precision (and fix https://github.com/pytorch/pytorch/issues/128394)
Author: lessw2020
Pull request: yes

# What does this PR do?
This PR:
1 - Removes the redundant autocast and device_type calcs regarding the Rope frequency embeddings, both for code efficiency and more importantly to re-enable torch export tracing of llama models. 

In order to ensure that the frequencies are cast to float32 (to avoid loss of precision over long context) a disabled autocontext was added along with a .float() upcast to the relevant variables (frequency and position).
However, this autocast is redundant, adds unneeded context overhead, and also creates a problem for torch.export for the llama models as autocast does not support meta device. 

Since the upcasts are already hardcoded to the float dtype, a disabled autocast is not needed.  Similarly the device type checks are then also not needed.

Thus, this PR simply removes the autocast context which should resolve the outstanding torch.export issue here:
https://github.com/pytorch/pytorch/issues/128394


<!--
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)
https://github.com/pytorch/pytorch/issues/128394

## 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?
- [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.
      https://github.com/huggingface/transformers/pull/29285#issuecomment-2227392566
      
- [ ] 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?
@gante  @kwen2501  @angelayi @danielhanchen 

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
- speech models: @sanchit-gandhi
- graph models: @clefourrier

Library:

- flax: @sanchit-gandhi
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Narsil
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @muellerzr and @SunMarc

Integrations:

- deepspeed: HF Trainer/Accelerate: @muellerzr
- ray/raytune: @richardliaw, @amogkam
- Big Model Inference: @SunMarc
- quantization (bitsandbytes, autogpt): @SunMarc 

Documentation: @stevhliu and @MKhalusova

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:
The context manager was added to disable torch auto cast because the upcasting was ignored by amp auto cast in torch 2.2 and 2.3. I'm unsure if later versions of torch fixed it.

During fine-tuning and inference, RoPE must upcast to float32 to preserve precision, since mixed precision training will downcast everything that is not explicitly marked.

One way to test is this is adding a print statement to print the dtype, and if it is float32, then the auto cast context manager is unnecessary.

For inference yes the autocast context manager is redundant, but when enabling mixed precision, the autocast disabler had to be placed - I'm unsure if newer versions of torch can bypass this issue

👋 

What I'm reading then is that we SHOULDN'T merge this PR until we confirm that pytorch doesn't change the type of an explicit `.float()` cast when `autocast` is active. Otherwise, we will get a regression (thank you @danielhanchen for confirming 🤗 )

______________________

Running `make fix-copies` on the `transformers` root folder and then pushing will make our CI green. In a nutshell, running that command will push the same change to other llama-like models.

Hi all - we have a much better solution now by making some changes to how PP does the model tracing via PT export and with that, it now handles the autocast issue directly so no changes needed here in the transformer code.
Thus, I'm going to close this PR as the proper fix is within export/PP directly.
The PR for reference is here in PyTorch:
https://github.com/pytorch/pytorch/pull/130998