MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / DeepSpeedZeroConfig

Class DeepSpeedZeroConfig

deepspeed/runtime/zero/config.py:90–418  ·  view source on GitHub ↗

Sets parameters for ZeRO optimizations.

Source from the content-addressed store, hash-verified

88
89
90class DeepSpeedZeroConfig(DeepSpeedConfigModel):
91 """
92 Sets parameters for ZeRO optimizations.
93 """
94
95 stage: ZeroStageEnum = 0
96 """
97 Chooses different stages of ZeRO Optimizer. Stage 0, 1, 2, and 3 refer
98 to disabled, optimizer state partitioning, and optimizer+gradient state
99 partitioning, and optimizer+gradient+parameter partitioning, respectively.
100 """
101
102 contiguous_gradients: bool = True
103 """
104 Copies the gradients to a contiguous buffer as they are produced. Avoids
105 memory fragmentation during backward pass.
106 """
107
108 reduce_scatter: bool = True
109 """
110 Uses reduce or reduce scatter instead of allreduce to average gradients
111 """
112
113 reduce_bucket_size: int = Field(pp_int(5e8), gt=0)
114 """
115 Number of elements reduced/allreduced at a time. Limits the memory required
116 for the allgather for large model sizes
117 """
118
119 use_multi_rank_bucket_allreduce: bool = True
120 """
121 Combine the reduce buckets of the different ranks and do an All-Reduce instead of multiple Reduce ops.
122 This feature is useful when the model is small and we want to scale it on too many GPUs which therefore
123 reduces the message sizes of each packet.
124 """
125
126 allgather_partitions: bool = True
127 """
128 Chooses between allgather collective or a series of broadcast collectives
129 to gather updated parameters from all the GPUs at the end of each step
130 """
131
132 allgather_bucket_size: int = Field(pp_int(5e8), ge=0)
133 """
134 Number of elements allgathered at a time. Limits the memory required for
135 the allgather for large model sizes
136 """
137
138 overlap_comm: Optional[bool] = None # None for dynamic default value (see validator `overlap_comm_valid` below)
139 """
140 Attempts to overlap the reduction of the gradients with backward computation
141 """
142
143 compute_grad_norm: bool = True
144 """
145 Compute and retain the global gradient norm during ZeRO Stage 1/2 optimizer steps.
146 Disable only when gradient clipping is off, the dedicated ZeRO-1 BF16 optimizer is not selected,
147 and callers do not use ``get_global_grad_norm()``.