Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable precision-aware optimizer with TE.optim #11676

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nemo/collections/llm/recipes/optim/adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ def distributed_fused_adam_with_cosine_annealing(
max_lr: float = 1e-4,
min_lr: Optional[float] = None,
clip_grad: float = 1.0,
use_precision_aware_optimizer: bool = False,
) -> run.Config[PytorchOptimizerModule]:

opt_cfg = run.Config(
Expand All @@ -45,6 +46,8 @@ def distributed_fused_adam_with_cosine_annealing(
use_distributed_optimizer=True,
clip_grad=clip_grad,
)
if hasattr(opt_cfg, "use_precision_aware_optimizer"):
opt_cfg.use_precision_aware_optimizer = use_precision_aware_optimizer

min_lr = min_lr if min_lr is not None else (0.1 * max_lr)
sched = run.Config(
Expand Down
4 changes: 4 additions & 0 deletions nemo/core/classes/modelPT.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,10 @@ def setup_megatron_optimization(self, optim_config: Union[Dict[str, Any], DictCo
'overlap_param_gather_with_optimizer_step', False
),
)
if hasattr(megatron_optim_config, 'use_precision_aware_optimizer'):
megatron_optim_config.use_precision_aware_optimizer = self.cfg.optim.get(
'use_precision_aware_optimizer', False
)
return megatron_optim_config

def setup_optimization(
Expand Down
Loading