# pyre-strict # mypy: allow-untyped-defs import abc import os from concurrent.futures import Future import torch.distributed as dist from torch.distributed.checkpoint.metadata import STATE_DICT_TYPE from torch.distributed.checkpoint.planner import SavePlanner from torch.distributed.checkpoint.storage import StorageWriter class _AsyncCheckpointExecutor(abc.ABC): @abc.abstractmethod def execute_save( self, staging_future_or_state_dict: STATE_DICT_TYPE | Future[STATE_DICT_TYPE], *, checkpoint_id: str | os.PathLike | None = None, storage_writer: StorageWriter | None = None, planner: SavePlanner | None = None, process_group: dist.ProcessGroup | None = None, no_dist: bool = False, use_collectives: bool = True, ) -> Future: """ Execute the checkpoint save request asynchronously. This method is intended to be used as an abstraction for implementing async checkpointing. The actual checkpoint save operation is executed in a separate thread or process depending on the implementation of this interface. """