Fused Adamw RuntimeError: params, grads, exp_avgs, and exp_avg_sqs must have same dtype, device, and layout
Labels: module: optimizer, triaged

### 🐛 Describe the bug

Hello! I encountered `RuntimeError: params, grads, exp_avgs, and exp_avg_sqs must have same dtype, device, and layout ` when using fused adamw. When I check these variables, they are of the same dtype, device and layout. Does anyone know how may I fix this? Thank you!

Below is full traceback.
Traceback (most recent call last):
  File "/home/senzeyu@DEEPCELL.local/neoml/neoml/app/cell_class/train.py", line 298, in <module>
    optimize(train_config, args.job_type)
  File "/home/senzeyu@DEEPCELL.local/neoml/neoml/app/cell_class/train.py", line 263, in optimize
    _results, trainer, _, selected_trial = train_model(config, study, instance_id)
  File "/home/senzeyu@DEEPCELL.local/neoml/neoml/app/cell_class/train.py", line 216, in train_model
    trainer.fit(pl_module, data_module)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 603, in fit
    call._call_and_handle_interrupt(
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/call.py", line 38, in _call_and_handle_interrupt
    return trainer_fn(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 645, in _fit_impl
    self._run(model, ckpt_path=self.ckpt_path)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 1098, in _run
    results = self._run_stage()
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 1177, in _run_stage
    self._run_train()
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 1200, in _run_train
    self.fit_loop.run()
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/fit_loop.py", line 267, in advance
    self._outputs = self.epoch_loop.run(self._data_fetcher)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/epoch/training_epoch_loop.py", line 214, in advance
    batch_output = self.batch_loop.run(kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/batch/training_batch_loop.py", line 88, in advance
    outputs = self.optimizer_loop.run(optimizers, kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/loop.py", line 199, in run
    self.advance(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/optimizer_loop.py", line 200, in advance
    result = self._run_optimization(kwargs, self._optimizers[self.optim_progress.optimizer_position])
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/optimizer_loop.py", line 247, in _run_optimization
    self._optimizer_step(optimizer, opt_idx, kwargs.get("batch_idx", 0), closure)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/loops/optimization/optimizer_loop.py", line 357, in _optimizer_step
    self.trainer._call_lightning_module_hook(
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/trainer/trainer.py", line 1342, in _call_lightning_module_hook
    output = fn(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/core/module.py", line 1661, in optimizer_step
    optimizer.step(closure=optimizer_closure)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/core/optimizer.py", line 169, in step
    step_output = self._strategy.optimizer_step(self._optimizer, self._optimizer_idx, closure, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/strategies/strategy.py", line 234, in optimizer_step
    return self.precision_plugin.optimizer_step(
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/pytorch_lightning/plugins/precision/precision_plugin.py", line 121, in optimizer_step
    return optimizer.step(closure=closure, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/torch/optim/optimizer.py", line 373, in wrapper
    out = func(*args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/torch/optim/optimizer.py", line 76, in _use_grad
    ret = func(self, *args, **kwargs)
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/torch/optim/adamw.py", line 184, in step
    adamw(
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/torch/optim/adamw.py", line 335, in adamw
    func(
  File "/home/senzeyu@DEEPCELL.local/neoml/.venv/lib/python3.9/site-packages/torch/optim/adamw.py", line 666, in _fused_adamw
    torch._fused_adamw_(
RuntimeError: params, grads, exp_avgs, and exp_avg_sqs must have same dtype, device, and layout

Also attached printed dtype, device and layout.
<img width="950" alt="image" src="https://github.com/pytorch/pytorch/assets/31408450/450352e9-cb8e-4e05-a1e4-f8dfdad1a79d">


### Versions

Collecting environment information...
PyTorch version: 2.1.0+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.25.0
Libc version: glibc-2.35

Python version: 3.9.13 (main, Oct  3 2023, 14:51:13)  [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.2.0-33-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA H100 PCIe
GPU 1: NVIDIA H100 PCIe
GPU 2: NVIDIA H100 PCIe

Nvidia driver version: 535.104.12
cuDNN version: Could not collect
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
Address sizes:                      46 bits physical, 57 bits virtual
Byte Order:                         Little Endian
CPU(s):                             48
On-line CPU(s) list:                0-47
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Xeon(R) Silver 4310 CPU @ 2.10GHz
CPU family:                         6
Model:                              106
Thread(s) per core:                 2
Core(s) per socket:                 12
Socket(s):                          2
Stepping:                           6
CPU max MHz:                        3300.0000
CPU min MHz:                        800.0000
BogoMIPS:                           4200.00
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 monitor 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 intel_ppin 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 split_lock_detect wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq la57 rdpid fsrm md_clear pconfig flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          1.1 MiB (24 instances)
L1i cache:                          768 KiB (24 instances)
L2 cache:                           30 MiB (24 instances)
L3 cache:                           36 MiB (2 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-11,24-35
NUMA node1 CPU(s):                  12-23,36-47
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] flake8==3.9.2
[pip3] flake8-blind-except==0.2.1
[pip3] flake8-bugbear==23.3.12
[pip3] flake8-builtins==2.1.0
[pip3] flake8-comprehensions==3.14.0
[pip3] flake8-docstrings==1.7.0
[pip3] flake8-mutable==1.2.0
[pip3] flake8-rst-docstrings==0.3.0
[pip3] mypy==1.5.1
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.0
[pip3] onnx==1.14.1
[pip3] onnxconverter-common==1.14.0
[pip3] onnxruntime-gpu==1.16.0
[pip3] pytest-flake8==1.1.0
[pip3] pytest-mypy==0.10.3
[pip3] pytorch-lightning==1.8.4
[pip3] skl2onnx==1.15.0
[pip3] torch==2.1.0+cu118
[pip3] torch-tb-profiler==0.4.1
[pip3] torchmetrics==0.11.4
[pip3] torchvision==0.16.0+cu118
[pip3] triton==2.1.0

cc @vincentqb @jbschlosser @albanD @janeyx99 @crcrpar