Fix convert_and_export_with_cache failures for GPU models
Author: Stonepia
Pull request: yes

# What does this PR do?

Fixes #38975 

This PR passes `device` to tensor initialization, so to fix the `torch.export` error when the model is on GPU. Otherwise, dynamo  will throw errors like `Unhandled FakeTensor Device Propagation for aten.embedding.default, found two different devices cuda:0, cpu'`

This PR mainly contains two parts:
1. Infer device information from the model and make all the `torch.tensor()` initialization contains device information.
2. Change the corresponding tests from CPU only to `torch_device`.

## 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: @eustlb
- graph models: @clefourrier

Library:

- flax: @gante and @Rocketknight1
- generate: @zucchini-nlp (visual-language models) or @gante (all others)
- pipelines: @Rocketknight1
- tensorflow: @gante and @Rocketknight1
- tokenizers: @ArthurZucker
- trainer: @zach-huggingface, @SunMarc and @qgallouedec
- chat templates: @Rocketknight1

Integrations:

- deepspeed: HF Trainer/Accelerate: @SunMarc @zach-huggingface
- 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: @Rocketknight1
- PyTorch: See Models above and tag the person corresponding to the modality of the example.
- TensorFlow: @Rocketknight1

 -->


Comments:
@Rocketknight1 @gante , could you pls help review this PR or point us the right reviewer? Thx very much

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: cohere2, gemma, gemma2, llama, olmo, olmo2, phi3, qwen2, qwen3, t5

Hi @gante , may I ask for a re-review of this PR?

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

@Stonepia @liangan1 @yao-matrix there is possibly something wrong with model on GPU + torch.export + this integration: `test_export_static_cache` results in CUDA OOM even when there is plenty of memory (e.g. `google/gemma-2-2b` on a 24GB GPU, with a total generation length of ~20 new tokens).

The memory consumption is highly dependent on the generation length, but I couldn't figure out the exact cause -- some help is appreciated 🙏 

Meanwhile, I'm reverting the tests back to run on `cpu`, to prevent other regressions (#39662) 🤗