Skip to content

Commit

Permalink
Merge branch 'fix_chained_opt_with_dist_opt_overlap' into 'main'
Browse files Browse the repository at this point in the history
Add disable/enable_pre_hook attributes for ChainedOptimizer.

See merge request ADLR/megatron-lm!1289
  • Loading branch information
jaredcasper committed Apr 4, 2024
2 parents 94c3228 + 2acadf3 commit ba77325
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions megatron/core/optimizer/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,24 @@ def load_state_dict(self, state_dict):
for optimizer in self.chained_optimizers:
self.param_groups += optimizer.param_groups

def disable_pre_hook(self):
if not self.config.use_distributed_optimizer or not self.config.overlap_param_gather:
raise ValueError(
"disable_pre_hook should only be called with 'use_distributed_optimizer' "
"and 'overlap_param_gather' are both enabled."
)
for optimizer in self.chained_optimizers:
optimizer.disable_pre_hook()

def enable_pre_hook(self):
if not self.config.use_distributed_optimizer or not self.config.overlap_param_gather:
raise ValueError(
"enable_pre_hook should only be called with 'use_distributed_optimizer' "
"and 'overlap_param_gather' are both enabled."
)
for optimizer in self.chained_optimizers:
optimizer.enable_pre_hook()

def step(self):
"""ChainedOptimizer will step all optimizers one by one.
"""
Expand Down

0 comments on commit ba77325

Please sign in to comment.