Skip to content

Commit

Permalink
Add docstrings for all Entry classes (#152)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #152

Update docstrings for all Entry classes in `manifest.py`, no code changes

Reviewed By: ananthsub

Differential Revision: D48618089

fbshipit-source-id: 0caab2484ac5609ce49f140db0baefbbe2ca9e13
  • Loading branch information
Rafi Ayub authored and facebook-github-bot committed Oct 25, 2023
1 parent 7d77929 commit f2de547
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions torchsnapshot/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ def from_yaml_obj(cls, yaml_obj: Any) -> "Entry":

@dataclass
class TensorEntry(Entry):
"""
Entry dataclass for a torch.Tensor object.
Attributes:
location (str): the file storage location of the object in the saved snapshot
serializer (str): the function that serialized the object (usually torch_save)
dtype (str): torch datatype of the tensor
shape (List[int]): shape of the tensor
replicated (bool): whether the tensor is replicated on other ranks
byte_range (Optional[List[int]]): indexable range of bytes in a continguous block of memory
"""

location: str
serializer: str
dtype: str
Expand Down Expand Up @@ -81,6 +93,16 @@ def byte_range_tuple(self) -> Optional[Tuple[int, int]]:

@dataclass
class Shard:
"""
An individual shard dataclass for a ShardedTensorEntry.
Attributes:
offsets (List[int]): starting indices by dimension of the shard within the original tensor,
should match n dims of tensor
sizes (List[int]): shape of the shard, should be identical to shape of underlying TensorEntry
tensor (TensorEntry): entry of actual tensor object in shard
"""

offsets: List[int]
sizes: List[int]
tensor: TensorEntry
Expand All @@ -93,6 +115,13 @@ def from_yaml_obj(cls, yaml_obj: Any) -> "Shard":

@dataclass
class ShardedTensorEntry(Entry):
"""
Entry for overall ShardedTensor that can contain multiple shards.
Attributes:
shards (List[Shard]): list of individual Shard entries for each shard
"""

shards: List[Shard]

def __init__(self, shards: List[Shard]) -> None:
Expand All @@ -111,6 +140,16 @@ def from_yaml_obj(cls, yaml_obj: Any) -> "ShardedTensorEntry":

@dataclass
class ChunkedTensorEntry(Entry):
"""
Entry for Tensor object that has been chunked when saving for performance optimization.
Attributes:
dtype (str): dtype of all tensor chunks
shape (List[int]): shape of overall unchunked tensor
chunks (List[Shard]): individual entries for each chunk, represented as a Shard dataclass
replicated (bool): whether the overall tensor is replicated across ranks
"""

dtype: str
shape: List[int]
chunks: List[Shard]
Expand All @@ -137,6 +176,16 @@ def from_yaml_obj(cls, yaml_obj: Any) -> "ChunkedTensorEntry":

@dataclass
class ObjectEntry(Entry):
"""
Entry for a generic object.
Attributes:
location (str): the file storage location of the object in the saved snapshot
serializer (str): the function that serialized the object (usually torch_save)
obj_type (str): name of the object class
replicated (bool): whether the object is replicated on other ranks
"""

location: str
serializer: str
obj_type: str
Expand All @@ -154,12 +203,20 @@ def __init__(

@dataclass
class ListEntry(Entry):
"""
Entry for a Python list primitive.
"""

def __init__(self) -> None:
super().__init__(type="list")


@dataclass
class DictEntry(Entry):
"""
Entry for a Python dict primitive.
"""

keys: List[Union[str, int]]

def __init__(self, keys: List[Union[str, int]]) -> None:
Expand All @@ -169,6 +226,10 @@ def __init__(self, keys: List[Union[str, int]]) -> None:

@dataclass
class OrderedDictEntry(Entry):
"""
Entry for a Python OrderedDict primitive.
"""

keys: List[Union[str, int]]

def __init__(self, keys: List[Union[str, int]]) -> None:
Expand Down Expand Up @@ -276,6 +337,17 @@ def from_yaml_obj(

@dataclass
class SnapshotMetadata:
"""
Overall manifest object that contains all the entries in a snapshot and
the associated metadata. Converts all yaml objects into their appropriate
Entry dataclass.
Attributes:
version (str): version of TorchSnapshot package
world_size (str): total number of ranks in distributed environment where snapshot was taken
manifest (Manifest): Manifest object containing all the entries in the snapshot
"""

version: str
world_size: int
manifest: Manifest
Expand Down

0 comments on commit f2de547

Please sign in to comment.