(self,
                        directory,
                        global_step,
                        optimizer=None,
                        name=None)
r"""
        Saves checkpoint at a certain global step during training. Optimizer state
        is also saved together.

        Args:
            directory (str): Path to save checkpoint to.
            global_step (int): The global step variable during training.
            optimizer (Optimizer): Optimizer state to be saved concurrently.
            name (str): The name to save the checkpoint file as.

        Returns:
            None
r"""
        Saves checkpoint at a certain global step during training. Optimizer state
        is also saved together.
r Saves checkpoint at a certain global step during training . Optimizer state is also saved together .
def save_checkpoint(self,
                        directory,
                        global_step,
                        optimizer=None,
                        name=None):
        r"""
        Saves checkpoint at a certain global step during training. Optimizer state
        is also saved together.

        Args:
            directory (str): Path to save checkpoint to.
            global_step (int): The global step variable during training.
            optimizer (Optimizer): Optimizer state to be saved concurrently.
            name (str): The name to save the checkpoint file as.

        Returns:
            None
        """
        # Create directory to save to
        if not os.path.exists(directory):
            os.makedirs(directory)

        # Build checkpoint dict to save.
        ckpt_dict = {
            'model_state_dict':
            self.state_dict(),
            'optimizer_state_dict':
            optimizer.state_dict() if optimizer is not None else None,
            'global_step':
            global_step
        }

        # Save the file with specific name
        if name is None:
            name = "{}_{}_steps.pth".format(
                os.path.basename(directory),  # netD or netG
                global_step)

        megengine.save(ckpt_dict, os.path.join(directory, name))
def save_checkpoint ( self , directory , global_step , optimizer = None , name = None ) : # Create directory to save to if not os . path . exists ( directory ) : os . makedirs ( directory ) # Build checkpoint dict to save. ckpt_dict = { 'model_state_dict' : self . state_dict ( ) , 'optimizer_state_dict' : optimizer . state_dict ( ) if optimizer is not None else None , 'global_step' : global_step } # Save the file with specific name if name is None : name = "{}_{}_steps.pth" . format ( os . path . basename ( directory ) , # netD or netG global_step ) megengine . save ( ckpt_dict , os . path . join ( directory , name ) )