DeepSpeed
078a057d - fix(zenflow): use optimizer_z3.device instead of hardcoded cuda (#8524)

Commit
3 days ago
fix(zenflow): use optimizer_z3.device instead of hardcoded cuda (#8524) ## Summary The ZenFlow optimizer module in `engine_stage3.py` hardcodes `device='cuda'` in 4 locations when creating tensors (`grad_sum_buffer`, `selected_indices`, `sum_buffer`, and `critic_sum_buffer`). This causes a crash on non-CUDA accelerators (NPU, XPU, HPU, etc.) with `Torch not compiled with CUDA enabled`. ## Root cause ```python optimizer_z3.grad_sum_buffer = torch.zeros(total_chunk_size, dtype=optimizer_z3.dtype, device='cuda') ``` The `DeepSpeedZeroOptimizer_Stage3` already has a `device` attribute set via `get_accelerator().current_device_name()`, which correctly reports the active accelerator. DeepSpeed has a device-agnostic accelerator abstraction (`deepspeed.accelerator.get_accelerator()`) used throughout the codebase. ## Fix Replace all 4 hardcoded `device='cuda'` with `device=optimizer_z3.device`. ```diff - optimizer_z3.grad_sum_buffer = torch.zeros(total_chunk_size, dtype=optimizer_z3.dtype, device='cuda') + optimizer_z3.grad_sum_buffer = torch.zeros(total_chunk_size, dtype=optimizer_z3.dtype, device=optimizer_z3.device) ``` ## Testing On a non-CUDA accelerator (Ascend NPU), the hardcoded `device='cuda'` raises: `RuntimeError: Torch not compiled with CUDA enabled` With this fix, tensor creation uses `optimizer_z3.device` which resolves to the active accelerator, and ZenFlow selection logic runs correctly. On CUDA, `optimizer_z3.device` is `cuda` (via `get_accelerator().current_device_name()`), so behavior is unchanged. ## Related Consistent with DeepSpeed's existing device-agnostic design via `get_accelerator()`. --------- Signed-off-by: li-lizhe <147392333@qq.com> Co-authored-by: pengdurice <pengduhit@gmail.com> Co-authored-by: Zhipeng Wang <zhipeng.rainbowserie@gmail.com>
Author
Parents
Loading