def find_latest_checkpoint(self) -> Tuple[str, str]:
        """
        Return the location of the latest model and training state files.
        If there isn't a valid checkpoint then return None.
        """
        have_checkpoint = (self._serialization_dir is not None and
                           any("model_state_epoch_" in x for x in os.listdir(self._serialization_dir)))

        if not have_checkpoint:
            return None

        serialization_files = os.listdir(self._serialization_dir)
        model_checkpoints = [x for x in serialization_files if "model_state_epoch" in x]
        # Get the last checkpoint file.  Epochs are specified as either an
        # int (for end of epoch files) or with epoch and timestamp for
        # within epoch checkpoints, e.g. 5.2018-02-02-15-33-42
        found_epochs = [
                re.search(r"model_state_epoch_([0-9\.\-]+)\.th", x).group(1)
                for x in model_checkpoints
        ]
        int_epochs: Any = []
        for epoch in found_epochs:
            pieces = epoch.split('.')
            if len(pieces) == 1:
                # Just a single epoch without timestamp
                int_epochs.append([int(pieces[0]), '0'])
            else:
                # has a timestamp
                int_epochs.append([int(pieces[0]), pieces[1]])
        last_epoch = sorted(int_epochs, reverse=True)[0]
        if last_epoch[1] == '0':
            epoch_to_load = str(last_epoch[0])
        else:
            epoch_to_load = '{0}.{1}'.format(last_epoch[0], last_epoch[1])

        model_path = os.path.join(self._serialization_dir,
                                  "model_state_epoch_{}.th".format(epoch_to_load))
        training_state_path = os.path.join(self._serialization_dir,
                                           "training_state_epoch_{}.th".format(epoch_to_load))

        return (model_path, training_state_path)
def find_latest_checkpoint ( self ) -> Tuple [ str , str ] : have_checkpoint = ( self . _serialization_dir is not None and any ( "model_state_epoch_" in x for x in os . listdir ( self . _serialization_dir ) ) ) if not have_checkpoint : return None serialization_files = os . listdir ( self . _serialization_dir ) model_checkpoints = [ x for x in serialization_files if "model_state_epoch" in x ] found_epochs = [ re . search ( r"model_state_epoch_([0-9\.\-]+)\.th" , x ) . group ( 1 ) for x in model_checkpoints ] int_epochs : Any = [ ] for epoch in found_epochs : pieces = epoch . split ( '.' ) if len ( pieces ) == 1 : int_epochs . append ( [ int ( pieces [ 0 ] ) , '0' ] ) else : int_epochs . append ( [ int ( pieces [ 0 ] ) , pieces [ 1 ] ] ) last_epoch = sorted ( int_epochs , reverse = True ) [ 0 ] if last_epoch [ 1 ] == '0' : epoch_to_load = str ( last_epoch [ 0 ] ) else : epoch_to_load = '{0}.{1}' . format ( last_epoch [ 0 ] , last_epoch [ 1 ] ) model_path = os . path . join ( self . _serialization_dir , "model_state_epoch_{}.th" . format ( epoch_to_load ) ) training_state_path = os . path . join ( self . _serialization_dir , "training_state_epoch_{}.th" . format ( epoch_to_load ) ) return ( model_path , training_state_path )
Return the location of the latest model and training state files.
        If there isn't a valid checkpoint then return None.