RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument state_steps in method wrapper_CUDA___fused_adamw_)
Labels: module: optimizer, triaged

### 🐛 Describe the bug

When using deepspeed to train LoRA, I want to use the resume function of the trainer. The sample code is as follows:
```python
causal_model = AutoModelForCausalLM.from_pretrained(model_pretrained_path_,
                                                    config=config,
                                                    trust_remote_code=True,
                                                    low_cpu_mem_usage=self.params["low_cpu_mem_usage"])

peft = PEFT(config_path_or_data=peft_params)
causal_model = peft.get_peft_model(model=causal_model)

trainer = Seq2SeqTrainer(
        params=trainer_params,
        model=causal_model,
        tokenizer=tokenizer,
        train_dataset=train_dataset,
        data_collator=data_collator,
        eval_dataset=eval_dataset,
        compute_metrics=dataset_t.metric,
    )

trainer.train(resume_from_checkpoint=True)
```

Encountered the following error:

```bash
  File "train.py", line 82, in train
    trainer.train(resume_from_checkpoint=model_params["resume_from_checkpoint"])
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/transformers/trainer.py", line 1589, in train
    return inner_training_loop(
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/transformers/trainer.py", line 1890, in _inner_training_loop
    tr_loss_step = self.training_step(model, inputs)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/transformers/trainer.py", line 2785, in training_step
    self.accelerator.backward(loss)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/accelerate/accelerator.py", line 1847, in backward
    self.deepspeed_engine_wrapped.backward(loss, **kwargs)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/accelerate/utils/deepspeed.py", line 176, in backward
    self.engine.step()
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/deepspeed/runtime/engine.py", line 2083, in step
    self._take_model_step(lr_kwargs)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/deepspeed/runtime/engine.py", line 1989, in _take_model_step
    self.optimizer.step()
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1786, in step
    self._optimizer_step(i)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/deepspeed/runtime/zero/stage_1_and_2.py", line 1697, in _optimizer_step
    self.optimizer.step()
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/torch/optim/lr_scheduler.py", line 69, in wrapper
    return wrapped(*args, **kwargs)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/torch/optim/optimizer.py", line 280, in wrapper
    out = func(*args, **kwargs)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/torch/optim/optimizer.py", line 33, in _use_grad
    ret = func(self, *args, **kwargs)
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/torch/optim/adamw.py", line 171, in step
    adamw(
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/torch/optim/adamw.py", line 321, in adamw
    func(
  File "/mnt/bn/data-ecom-govern-kk/soft/anaconda/envs/kk/lib/python3.10/site-packages/torch/optim/adamw.py", line 615, in _fused_adamw
    torch._fused_adamw_(
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cpu! (when checking argument for argument state_steps in method wrapper_CUDA___fused_adamw_)
```

I think it is caused by not placing the step on the corresponding device when loading the optimizer parameters.

![image](https://github.com/pytorch/pytorch/assets/48399040/6c5fae89-6454-4c30-aaaf-f9cb37af7c21)

But I don't know how to solve this problem.


### Versions

Collecting environment information...
PyTorch version: 2.0.1+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Debian GNU/Linux 10 (buster) (x86_64)
GCC version: (Debian 8.3.0-6) 8.3.0
Clang version: Could not collect
CMake version: version 3.27.2
Libc version: glibc-2.28

Python version: 3.10.12 (main, Jul  5 2023, 18:54:27) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.4.143.bsk.8-amd64-x86_64-with-glibc2.28
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: A100-SXM-80GB
Nvidia driver version: 450.191.01
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.7.0
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.7.0
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
Address sizes:       46 bits physical, 57 bits virtual
CPU(s):              128
On-line CPU(s) list: 0-127
Thread(s) per core:  2
Core(s) per socket:  32
Socket(s):           2
NUMA node(s):        4
Vendor ID:           GenuineIntel
CPU family:          6
Model:               106
Model name:          Intel(R) Xeon(R) Platinum 8336C CPU @ 2.30GHz
Stepping:            6
CPU MHz:             3000.014
CPU max MHz:         3500.0000
CPU min MHz:         800.0000
BogoMIPS:            4600.00
Virtualization:      VT-x
L1d cache:           48K
L1i cache:           32K
L2 cache:            1280K
L3 cache:            55296K
NUMA node0 CPU(s):   0-15,64-79
NUMA node1 CPU(s):   16-31,80-95
NUMA node2 CPU(s):   32-47,96-111
NUMA node3 CPU(s):   48-63,112-127
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local wbnoinvd dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid md_clear pconfig flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] flake8==6.1.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.25.2
[pip3] torch==2.0.1+cu118
[pip3] torch-tb-profiler==0.4.1
[pip3] torchaudio==2.0.2
[pip3] torchvision==0.15.2
[pip3] triton==2.0.0
[conda] numpy                     1.25.2                   pypi_0    pypi
[conda] torch                     2.0.1+cu118              pypi_0    pypi
[conda] torch-tb-profiler         0.4.1                    pypi_0    pypi
[conda] torchaudio                2.0.2                    pypi_0    pypi
[conda] torchvision               0.15.2                   pypi_0    pypi
[conda] triton                    2.0.0                    pypi_0    pypi

cc @vincentqb @jbschlosser @albanD @janeyx99 @crcrpar