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

Method _is_checkpointable

deepspeed/runtime/pipe/module.py:660–679  ·  view source on GitHub ↗
(self, funcs)

Source from the content-addressed store, hash-verified

658 self._synchronize_tied_weights()
659
660 def _is_checkpointable(self, funcs):
661
662 if self.activation_checkpoint_func is not checkpointing.non_reentrant_checkpoint:
663 # This hook excludes the embedding layer
664 # because only non_reentrant_checkpoint can accept inputs with requires_grad=False
665 # otherwise, the backward of the embedding layer won't receive gradients.
666 if self.__class__.__name__ in ('GPTModelPipe', 'GPT2ModelPipe'):
667 # For GPT models, checkpoint both transformer layers and any additional
668 # layers specified in checkpointable_layers (if provided)
669 return all('ParallelTransformerLayerPipe' in f.__class__.__name__ or (
670 self.checkpointable_layers is not None and f.__class__.__name__ in self.checkpointable_layers)
671 for f in funcs)
672
673 if self.checkpointable_layers is not None:
674 # For non-GPT models, only checkpoint layers specified in checkpointable_layers
675 return all(f.__class__.__name__ in self.checkpointable_layers for f in funcs)
676
677 # Default behavior: checkpoint any layer that has parameters
678 params = [f.parameters() for f in funcs if isinstance(f, torch.nn.Module)]
679 return any(len(list(p)) > 0 for p in params)
680
681 def get_additional_losses(self):
682 """ Returns model specific additional losses for reporting

Calls 1

parametersMethod · 0.45

Tested by 1