已开启
[BUG] torch >= 2.8 下 fused AdamW + cpu_ram_efficient_loading 触发 device 检查失败 #198
cuiyushi创建于  6月9日
cuiyushi
cuiyushi成员
6月9日 创建

该问题是怎么引起的?

在 torch >= 2.8 上,开启 cpu_ram_efficient_loading=True 时参数先放到 meta,再由 load_state_dict 材料化。HSDPModule.load_state_dict 忽略 assign,走 in-place(只改 Python 的 _local_tensor,不替换 param 对象)。torch >= 2.8 下这种方式 Python 层 param.device 已是真实 device、检查不出问题,但 DTensor 外壳的 C++ device 仍停在 meta;fused AdamW 在 C++ 层比对 device 时报错。torch 2.7.1 不暴露此问题。

重现步骤

同时满足以下三个条件即可复现:

  1. torch >= 2.8
  2. cpu_ram_efficient_loading=True
  3. AdamW fused=True(如 optim=adamw_torch_fused)

跑 LlamaFactory + HyperParallel 训练,在第一个 optimizer step 触发。

报错信息

RuntimeError: Tensors of the same index must be on the same device and the same dtype
except `step` tensors that can be CPU and float32/64 notwithstanding

调用栈:optimizer.step() → AdamW.step → _fused_adam → _group_tensors_by_device_and_dtype(C++ 抛)。

likedislike