python/ray/ml/checkpoint.py
def to_directory(self, path: Optional[str] = None) -> str:
        """Write checkpoint data to directory.

        Args:
            path (str): Target directory to restore data in.

        Returns:
            str: Directory containing checkpoint data.
        """
        path = path if path is not None else _temporary_checkpoint_dir()

        os.makedirs(path, exist_ok=True)
        # Drop marker
        open(os.path.join(path, ".is_checkpoint"), "a").close()

        if self._data_dict or self._obj_ref:
            # This is a object ref or dict
            data_dict = self.to_dict()

            if _FS_CHECKPOINT_KEY in data_dict:
                # This used to be a true fs checkpoint, so restore
                _unpack(data_dict[_FS_CHECKPOINT_KEY], path)
            else:
                # This is a dict checkpoint. Dump data into checkpoint.pkl
                checkpoint_data_path = os.path.join(path, _DICT_CHECKPOINT_FILE_NAME)
                with open(checkpoint_data_path, "wb") as f:
                    pickle.dump(data_dict, f)
        else:
            # This is either a local fs, remote node fs, or external fs
            local_path = self._local_path
            external_path = _get_external_path(self._uri)
            if local_path:
                if local_path != path:
                    # If this exists on the local path, just copy over
                    if path and os.path.exists(path):
                        shutil.rmtree(path)
                    shutil.copytree(local_path, path)
            elif external_path:
                # If this exists on external storage (e.g. cloud), download
                download_from_uri(uri=external_path, local_path=path)
            else:
                raise RuntimeError(
                    f"No valid location found for checkpoint {self}: {self._uri}"
                )

        return path
Write checkpoint data to directory.

        Args:
            path (str): Target directory to restore data in.

        Returns:
            str: Directory containing checkpoint data.
        
Write checkpoint data to directory.
Write checkpoint data to directory .
def to_directory(self, path: Optional[str] = None) -> str:
        path = path if path is not None else _temporary_checkpoint_dir()
        os.makedirs(path, exist_ok=True)
        open(os.path.join(path, ".is_checkpoint"), "a").close()
        if self._data_dict or self._obj_ref:
            data_dict = self.to_dict()
            if _FS_CHECKPOINT_KEY in data_dict:
                _unpack(data_dict[_FS_CHECKPOINT_KEY], path)
            else:
                checkpoint_data_path = os.path.join(path, _DICT_CHECKPOINT_FILE_NAME)
                with open(checkpoint_data_path, "wb") as f:
                    pickle.dump(data_dict, f)
        else:
            local_path = self._local_path
            external_path = _get_external_path(self._uri)
            if local_path:
                if local_path != path:
                    if path and os.path.exists(path):
                        shutil.rmtree(path)
                    shutil.copytree(local_path, path)
            elif external_path:
                download_from_uri(uri=external_path, local_path=path)
            else:
                raise RuntimeError(
                    f"No valid location found for checkpoint {self}: {self._uri}"
                )
        return path
def to_directory ( self , path : Optional [ str ] = None ) -> str : path = path if path is not None else _temporary_checkpoint_dir ( ) os . makedirs ( path , exist_ok = True ) open ( os . path . join ( path , ".is_checkpoint" ) , "a" ) . close ( ) if self . _data_dict or self . _obj_ref : data_dict = self . to_dict ( ) if _FS_CHECKPOINT_KEY in data_dict : _unpack ( data_dict [ _FS_CHECKPOINT_KEY ] , path ) else : checkpoint_data_path = os . path . join ( path , _DICT_CHECKPOINT_FILE_NAME ) with open ( checkpoint_data_path , "wb" ) as f : pickle . dump ( data_dict , f ) else : local_path = self . _local_path external_path = _get_external_path ( self . _uri ) if local_path : if local_path != path : if path and os . path . exists ( path ) : shutil . rmtree ( path ) shutil . copytree ( local_path , path ) elif external_path : download_from_uri ( uri = external_path , local_path = path ) else : raise RuntimeError ( f"No valid location found for checkpoint {self}: {self._uri}" ) return path
Write checkpoint data to directory.
Write checkpoint data to directory .
"""Write checkpoint data to directory.

        Args:
            path (str): Target directory to restore data in.

        Returns:
            str: Directory containing checkpoint data.
        """ # Drop marker # This is a object ref or dict # This used to be a true fs checkpoint, so restore # This is a dict checkpoint. Dump data into checkpoint.pkl # This is either a local fs, remote node fs, or external fs # If this exists on the local path, just copy over # If this exists on external storage (e.g. cloud), download
Directory containing checkpoint data.
Directory containing checkpoint data .
str
self
path
Optional[str]
Target directory to restore data in.
Target directory to restore data in .