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

Unwrap ckpt_io for model opt (async save) (#9622) #9634

Merged
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
17 changes: 12 additions & 5 deletions nemo/collections/nlp/parts/nlp_overrides.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ def save_checkpoint(
save_sharded_modelopt_state(
self.lightning_module.get_model_module_list(),
ckpt_to_dir(filepath),
self.checkpoint_io.save_sharded_strategy,
self.unwrapped_checkpoint_io.save_sharded_strategy,
prefix="model.",
)
else:
Expand Down Expand Up @@ -595,10 +595,7 @@ def remove_checkpoint(self, filepath: Union[str, Path]) -> None:

@property
def use_distributed_checkpointing(self):
checkpoint_io = self.checkpoint_io
while isinstance(checkpoint_io, _WrappingCheckpointIO):
checkpoint_io = checkpoint_io.checkpoint_io
has_dist_ckpt_io = HAVE_MEGATRON_CORE and isinstance(checkpoint_io, DistributedCheckpointIO)
has_dist_ckpt_io = HAVE_MEGATRON_CORE and isinstance(self.unwrapped_checkpoint_io, DistributedCheckpointIO)
has_sharded_state_dict = (
hasattr(self.lightning_module, 'sharded_state_dict')
and self.lightning_module.sharded_state_dict() is not None
Expand Down Expand Up @@ -638,6 +635,14 @@ def restore_checkpoint_after_setup(self) -> bool:
"""
return True

@property
def unwrapped_checkpoint_io(self) -> CheckpointIO:
"""Returns CheckpointIO unwrapped from any _WrappedCheckpointIO wrappers."""
checkpoint_io = self.checkpoint_io
while isinstance(checkpoint_io, _WrappingCheckpointIO):
checkpoint_io = checkpoint_io.checkpoint_io
return checkpoint_io


class NLPDDPStrategyNotebook(NLPDDPStrategy):
"""Version of NLPDDPStrategy to be used in a Jupyter Notebook
Expand Down Expand Up @@ -1011,6 +1016,8 @@ def dummy():
checkpoint_io.save_checkpoint(sharded_state_dict, dist_ckpt_dir)

if HAVE_MODELOPT and hasattr(model, "get_model_module_list"):
while isinstance(checkpoint_io, _WrappingCheckpointIO):
checkpoint_io = checkpoint_io.checkpoint_io
save_sharded_modelopt_state(
model.get_model_module_list(),
dist_ckpt_dir,
Expand Down
Loading