DeepSpeed
b43c383f - Keep fp32 CPU optimizer states in fp32 when loading a state_dict (#8974)

Commit
25 days ago
Keep fp32 CPU optimizer states in fp32 when loading a state_dict (#8974) ## Summary `DeepSpeedCPUAdam`, `DeepSpeedCPULion` and `DeepSpeedCPUAdagrad` keep fp32 states for bf16/fp16 params when `fp32_optimizer_states` is set (the default), but the `load_state_dict` they inherit from torch casts the states to the param dtype. A resume with `bf16_master_weights_and_grads` and `offload_optimizer` (ZeRO-1/2/3, and SuperOffload with #8972) therefore continues without an error on rounded bf16 moments and the bf16-state kernel. This PR overrides `load_state_dict` to take these states from the saved tensors in fp32 again. Nothing changes for fp32 params or with `fp32_optimizer_states` off. <img width="1841" height="504" alt="image" src="https://github.com/user-attachments/assets/07ee75ae-52aa-4d81-9f15-a7a62a6d8fe7" /> ## Before → after - Right after `load_checkpoint`, all but 3 of the 131,584 elements of each moment were rounded, by up to 0.39% → the saved fp32 values. - A resume against the uninterrupted run (ZeRO-1, 2 and 3, betas of 0.5): up to 1.0e-2 off → bit-identical. <img width="1811" height="484" alt="image" src="https://github.com/user-attachments/assets/6413c434-248f-4a00-b5e3-8ca2514f2293" /> <img width="1802" height="706" alt="image" src="https://github.com/user-attachments/assets/56b1a407-9147-4374-814f-7a0b57e99d8d" /> --------- Signed-off-by: Xinyu Lian <lian7@illinois.edu>
Author
Parents
Loading