Skip to navigation

aistore.pytorch.shard_reader

View as MarkdownOpen in Claude

AIS Shard Reader for PyTorch

PyTorch Dataset and DataLoader for AIS.

Module Contents

Classes

NameDescription
AISShardReaderAn iterable-style dataset that iterates over objects stored as Webdataset shards

API

class aistore.pytorch.shard_reader.AISShardReader(
bucket_list: typing.Union[aistore.sdk.Bucket, typing.List[aistore.sdk.Bucket]],
prefix_map: typing.Dict[aistore.sdk.Bucket, typing.Union[str, typing.List[str]]] = {},
etl_name: str = None,
show_progress: bool = False,
partition_sources_by_worker: bool = False
)

Bases: AISBaseIterDataset

An iterable-style dataset that iterates over objects stored as Webdataset shards and yields samples represented as a tuple of basename (str) and contents (dictionary).

Parameters:

bucket_list
Union[Bucket, List[Bucket]]

Union[ Bucket , List[ Bucket ]] — Single or list of Bucket objects to load data

prefix_map
Dict[Bucket, Union[str, List[str]]]Defaults to {}

Dict[ Bucket , Union[str, List[str]]] — Prefixes to select from each bucket.

etl_name
strDefaults to None

Optional ETL on the AIS cluster to apply to each object

show_progress
boolDefaults to False

Enables console shard reading progress indicator

partition_sources_by_worker
boolDefaults to False

When True, distributes buckets across DataLoader workers so each worker only lists its share, avoiding duplicate paged listing calls. Most effective when bucket_list has at least as many buckets as workers. Defaults to False.

_observed_keys
= set()
aistore.pytorch.shard_reader.AISShardReader.__iter__() -> typing.Iterator
aistore.pytorch.shard_reader.AISShardReader.__len__() -> int

Return the number of samples in the dataset.

NOTE:

  • This lists and reads every shard without buffering its full payload.
  • Count samples during iteration to avoid a second read.

If ETL is enabled, this method counts samples before transformation. The count matches iteration only if ETL preserves the sample count in each shard.

aistore.pytorch.shard_reader.AISShardReader._count_samples_in_shard(
shard_stream
) -> int

Count sample basenames without seeking or reading the full payload at once.

aistore.pytorch.shard_reader.AISShardReader._iter_sample_members(
tar
) -> typing.Iterator
staticmethod

Yield regular members with an extension, their basename, and extension.

aistore.pytorch.shard_reader.AISShardReader._read_samples_from_shards(
shard_content
) -> typing.Dict