nemo_automodel.checkpoint._backports.filesystem
#
Module Contents#
Classes#
Enumeration of supported on-disk checkpoint formats. |
|
This is the per entry storage info. |
|
This is experimental, and will likely move elsewhere in the future. It lives here to minimize changes while we are still learning and gathering feedback. |
|
Basic implementation of StorageWriter using file IO. |
|
This is experimental, and will likely move elsewhere in the future. It lives here to minimize changes while we are still learning and gathering feedback. |
|
Basic implementation of StorageWriter using file IO. |
Functions#
Data#
API#
- nemo_automodel.checkpoint._backports.filesystem.__all__#
[‘FileSystemWriter’, ‘FileSystemReader’, ‘FileSystem’, ‘FileSystemBase’]
- nemo_automodel.checkpoint._backports.filesystem._metadata_fn: str#
‘.metadata’
- class nemo_automodel.checkpoint._backports.filesystem.SerializationFormat(*args, **kwds)[source]#
Bases:
enum.Enum
Enumeration of supported on-disk checkpoint formats.
Initialization
- TORCH_SAVE#
‘torch_save’
- SAFETENSORS#
‘safetensors’
- class nemo_automodel.checkpoint._backports.filesystem._StorageInfo[source]#
This is the per entry storage info.
- relative_path: str#
None
- offset: int#
None
- length: int#
None
- transform_descriptors: Optional[collections.abc.Sequence[str]]#
None
- nemo_automodel.checkpoint._backports.filesystem.DEFAULT_SUFFIX#
‘.distcp’
- class nemo_automodel.checkpoint._backports.filesystem._SerialCpuLoader(resolve_fun: Callable)[source]#
Bases:
nemo_automodel.checkpoint._backports.filesystem._TensorLoader
- class nemo_automodel.checkpoint._backports.filesystem._OverlappingCpuLoader(
- resolve_fun: Callable,
- stream: Optional[torch.Stream] = None,
- inflight_threshhold: int = 1000000,
Bases:
nemo_automodel.checkpoint._backports.filesystem._TensorLoader
- property _done: bool#
- class nemo_automodel.checkpoint._backports.filesystem._StorageWriterTransforms(
- extensions: Optional[collections.abc.Sequence[torch.distributed.checkpoint._extension.StreamTransformExtension]] = None,
This is experimental, and will likely move elsewhere in the future. It lives here to minimize changes while we are still learning and gathering feedback.
Initialization
If the extensions arg is None, this means the implementation should provide whatever defaults it chooses. An empty sequence indicates no extensions should be used. At this time, the default extensions sequence is empty.
- nemo_automodel.checkpoint._backports.filesystem._item_size(
- item: torch.distributed.checkpoint.planner.WriteItem,
- nemo_automodel.checkpoint._backports.filesystem._split_by_size_and_type(
- bins: int,
- items: list[torch.distributed.checkpoint.planner.WriteItem],
- nemo_automodel.checkpoint._backports.filesystem._write_item(
- transforms: nemo_automodel.checkpoint._backports.filesystem._StorageWriterTransforms,
- stream: io.IOBase,
- data: Union[io.BytesIO, torch.Tensor],
- write_item: torch.distributed.checkpoint.planner.WriteItem,
- storage_key: str,
- serialization_format: nemo_automodel.checkpoint._backports.filesystem.SerializationFormat,
- nemo_automodel.checkpoint._backports.filesystem._write_files_from_queue(
- create_stream: Callable,
- file_queue: queue.Queue,
- result_queue: queue.Queue,
- planner: torch.distributed.checkpoint.planner.SavePlanner,
- transforms: nemo_automodel.checkpoint._backports.filesystem._StorageWriterTransforms,
- inflight_threshhold: int,
- use_fsync: bool,
- thread_count: int,
- serialization_format: nemo_automodel.checkpoint._backports.filesystem.SerializationFormat,
- class nemo_automodel.checkpoint._backports.filesystem.FileSystemBase[source]#
Bases:
abc.ABC
- abstractmethod create_stream(
- path: Union[str, os.PathLike],
- mode: str,
- abstractmethod concat_path(
- path: Union[str, os.PathLike],
- suffix: str,
- abstractmethod rename(
- path: Union[str, os.PathLike],
- new_path: Union[str, os.PathLike],
- class nemo_automodel.checkpoint._backports.filesystem.FileSystem[source]#
Bases:
nemo_automodel.checkpoint._backports.filesystem.FileSystemBase
- class nemo_automodel.checkpoint._backports.filesystem._FileSystemWriter(
- path: Union[str, os.PathLike],
- single_file_per_rank: bool = True,
- sync_files: bool = True,
- thread_count: int = 1,
- per_thread_copy_ahead: int = 10000000,
- overwrite: bool = True,
- _extensions: Optional[collections.abc.Sequence[torch.distributed.checkpoint._extension.StreamTransformExtension]] = None,
- serialization_format: nemo_automodel.checkpoint._backports.filesystem.SerializationFormat = SerializationFormat.TORCH_SAVE,
- *args: Any,
- **kwargs: Any,
Bases:
torch.distributed.checkpoint.storage.StorageWriter
Basic implementation of StorageWriter using file IO.
This implementation makes the following assumptions and simplifications:
The checkpoint path is an empty or non-existing directory.
File creation is atomic
The checkpoint consist of one file per write request plus a
.metadata
file with the serialized metadata.Initialization
Initialize the writer pointing to
path
.- Parameters:
path – directory where the checkpoint will be written to.
single_file_per_rank – Produce one file per rank instead of one file per tensor/blob. Default to True.
sync_files – force files to be synced to permanent storage. Default to True.
thread_count – Number of IO threads to use to write. Default to 1.
per_thread_copy_ahead – How many bytes to copy from the GPU ahead of saving then. Default 10Mb.
overwrite – Whether to allow overwriting existing checkpoints. Defaults to True.
_extensions – Extensions to apply to output streams (EXPERIMENTAL)
N. B. If sync_files is disabled, there’s no guarantee that the checkpoint will be consistent in the case of a failure.
- prepare_local_plan(
- plan: torch.distributed.checkpoint.planner.SavePlan,
- prepare_global_plan(
- plans: list[torch.distributed.checkpoint.planner.SavePlan],
- write_data(
- plan: torch.distributed.checkpoint.planner.SavePlan,
- planner: torch.distributed.checkpoint.planner.SavePlanner,
- _write_data(
- planner: torch.distributed.checkpoint.planner.SavePlanner,
- file_queue: queue.Queue,
- finish(
- metadata: torch.distributed.checkpoint.metadata.Metadata,
- results: list[list[torch.distributed.checkpoint.storage.WriteResult]],
- property metadata_path: Union[str, os.PathLike]#
- property checkpoint_id: Union[str, os.PathLike]#
return the checkpoint_id that will be used to save the checkpoint.
- class nemo_automodel.checkpoint._backports.filesystem._StorageReaderTransforms(
- extension_registry: Optional[torch.distributed.checkpoint._extension.ExtensionRegistry] = None,
This is experimental, and will likely move elsewhere in the future. It lives here to minimize changes while we are still learning and gathering feedback.
Initialization
- class nemo_automodel.checkpoint._backports.filesystem.FileSystemReader(
- path: Union[str, os.PathLike],
- _extension_registry: Optional[torch.distributed.checkpoint._extension.ExtensionRegistry] = None,
Bases:
torch.distributed.checkpoint.storage.StorageReader
- read_data(
- plan: torch.distributed.checkpoint.planner.LoadPlan,
- planner: torch.distributed.checkpoint.planner.LoadPlanner,
- set_up_storage_reader(
- metadata: torch.distributed.checkpoint.metadata.Metadata,
- is_coordinator: bool,
- prepare_local_plan(
- plan: torch.distributed.checkpoint.planner.LoadPlan,
- prepare_global_plan(
- plans: list[torch.distributed.checkpoint.planner.LoadPlan],
- property checkpoint_id: Union[str, os.PathLike]#
return the checkpoint_id that will be used to load the checkpoint.
- class nemo_automodel.checkpoint._backports.filesystem.FileSystemWriter(
- path: Union[str, os.PathLike],
- single_file_per_rank: bool = True,
- sync_files: bool = True,
- thread_count: int = 1,
- per_thread_copy_ahead: int = 10000000,
- cache_staged_state_dict: bool = False,
- overwrite: bool = True,
- _extensions: Optional[collections.abc.Sequence[torch.distributed.checkpoint._extension.StreamTransformExtension]] = None,
- serialization_format: nemo_automodel.checkpoint._backports.filesystem.SerializationFormat = SerializationFormat.TORCH_SAVE,
Bases:
nemo_automodel.checkpoint._backports.filesystem._FileSystemWriter
,torch.distributed.checkpoint.staging.BlockingAsyncStager
Basic implementation of StorageWriter using file IO.
This implementation makes the following assumptions and simplifications:
The checkpoint path is an empty or non-existing directory.
File creation is atomic
The checkpoint consist of one file per write request plus a
.metadata
file with the serialized metadata.Initialization
Initialize the writer pointing to
path
.- Parameters:
path – directory where the checkpoint will be written to.
single_file_per_rank – Produce one file per rank instead of one file per tensor/blob. Default to True.
sync_files – force files to be synced to permanent storage. Default to True.
thread_count – Number of IO threads to use to write. Default to 1.
per_thread_copy_ahead – How many bytes to copy from the GPU ahead of saving then. Default 10Mb.
cache_staged_state_dict – Whether to cache the staged state_dict. This option decreases staging latency at the cost of increases memory usage. Additionally, if this parameter is set to True, it’s the expectation that the stager is maintained and re-used for multiple dcp.async_save calls. Default to False.
overwrite – Whether to allow overwriting existing checkpoints. Defaults to True.
_extensions – Extensions to apply to output streams (EXPERIMENTAL)
N. B. If sync_files is disabled, there’s no guarantee that the checkpoint will be consistent in the case of a failure.