DeepSpeed icon indicating copy to clipboard operation
DeepSpeed copied to clipboard

[BUG] DeepSpeedZeroOptimizer_Stage3: It cannot reduce the gradients remained in the bucket timely

Open tongping opened this issue 2 years ago • 2 comments

Describe the bug After each step, when gradient_accumulation_steps is set to be 1 and in the end of each step, __reduce_and_partition_ipg_grads should be invoked to reduce the remainning gradients in the bucket. Right now, it does not. It can cause the following issue: At the end of each step, only partial gradients are reduced, while the remained gradients are not reduced.

To Reproduce You could refer to independent_gradient_partition_epilogue, which is not invoked. Also, there is another bug that gradient_accumulation_steps is not used in stage3.py. It is easy to reproduce, which you can use any model to find out the issue.

Expected behavior At the beginning of each step, "self.elements_in_ipg_bucket" should be 0, while it is not right now.

tongping avatar Dec 28 '23 02:12 tongping

Thx @tongping for raising this issue.

gradient_accumulation_steps is not used at zero-3. But bydefault its value is 1. I also checked self.elements_in_ipg_bucket which is zero at beginning. The test code I run is https://github.com/microsoft/DeepSpeed/blob/master/tests/small_model_debugging/test_model.py by adding --zero 3 flag in cmd. Hope it helps.

GuanhuaWang avatar Jan 23 '24 22:01 GuanhuaWang

You should try the setting with the following one:

"zero_optimization": {
    "stage": 3,
    "allgather_partitions": true,
    "reduce_scatter": true,
    "allgather_bucket_size": 50000000,
    "reduce_bucket_size": 50000000,
    "overlap_comm": true
},

I noticed that you didn't use reduce bucket, then possibly the behavior will be different.

Thx @tongping for raising this issue.

gradient_accumulation_steps is not used at zero-3. But bydefault its value is 1. I also checked self.elements_in_ipg_bucket which is zero at beginning. The test code I run is https://github.com/microsoft/DeepSpeed/blob/master/tests/small_model_debugging/test_model.py by adding --zero 3 flag in cmd. Hope it helps.

tongping avatar Mar 12 '24 23:03 tongping