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

[Nemo1] Generate sharded optimizer state dicts only if needed for saving #11451

Merged
merged 1 commit into from
Dec 3, 2024
Merged
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
15 changes: 7 additions & 8 deletions nemo/collections/nlp/parts/nlp_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,17 +390,16 @@ def save_checkpoint(
"""
# check if using distributed checkpointing
if self.use_distributed_checkpointing:
assert (
len(checkpoint['optimizer_states']) == 1
), "Currently only support checkpointing 1 distributed optimizer per time!"
# converts the optimizer states to their sharded equivalents
sharded_optim_state = self.optimizer_sharded_state_dict(
unsharded_optim_state=checkpoint['optimizer_states'][0]
)

# Check whether to save optim states
include_optimizer = True if not storage_options else storage_options.get('include_optimizer', True)
if include_optimizer:
assert (
len(checkpoint['optimizer_states']) == 1
), "Currently only support checkpointing 1 distributed optimizer per time!"
# converts the optimizer states to their sharded equivalents
sharded_optim_state = self.optimizer_sharded_state_dict(
unsharded_optim_state=checkpoint['optimizer_states'][0]
)
checkpoint['optimizer_states'] = [sharded_optim_state]
else:
checkpoint['optimizer_states'] = None
Expand Down
Loading