deepspeedai / deepspeedai/DeepSpeed

[REQUEST] DeepSpeed Zero3 swap off gradients unnecessarily when swap_optimizer is True

Open
#3,673 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
43.1k
Forks
5k
Avg merge
4d 15h
Merged PRs (30d)
112

Description

** DeepSpeed Zero3 swap off gradients unnecessarily when swap_optimizer is True

According to the function DeepSpeedZeroOptimizer_Stage3.partition_grads in
https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/runtime/zero/stage3.py#L1194, gradients are accumulated into tensors holding by self.__param_id_to_grad_partition, so why bother swap out gradients in gradient accumulation boundary?
https://github.com/microsoft/DeepSpeed/blob/master/deepspeed/runtime/zero/stage3.py#L1258

        if self.offload_optimizer and self.swap_optimizer:
            for i in offload_fp32_gradients.keys():
                self.optimizer_swapper.swap_out_gradients(parameter=self.fp32_partitioned_groups_flat[i],
                                                          gradient_offsets=offload_fp32_offsets[i],
                                                          gradient_tensors=offload_fp32_gradients[i])

I'm quite confused by this, please help me out. thanks!

@tjruwase

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in deepspeed/runtime/zero/stage3.py at DeepSpeedZeroOptimizer_Stage3.partition_grads, especially the gradient accumulation boundary around the cited lines. Trace self.__param_id_to_grad_partition, offload_fp32_gradients, and the optimizer_swapper.swap_out_gradients call to determine whether the swap is necessary when swap_optimizer is enabled. Done means explaining the behavior and identifying whether a code change is warranted.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
distributed-systems, machine-learning, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.