Skip to navigation
ReferenceFull Library ReferenceNemo AutomodelNemo AutomodelComponentsDatasetsnemo_automodel.components.datasets.lazy_mapped_dataset

nemo_automodel.components.datasets.lazy_mapped_dataset

View as MarkdownOpen in Claude

Module Contents

Classes

NameDescription
LazyMappedDatasetDataset wrapper that applies a transform function on-the-fly instead of
LazyMappedDatasetConfigConstruction-time configuration for LazyMappedDataset.
_IndexedSourceMap-style source with a length and integer indexing, e.g. a Hugging Face datasets.Dataset.

Data

InT

OutT

_ItemT_co

logger

API

class nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset(
map_fn: collections.abc.Callable[[InT], nemo_automodel.components.datasets.lazy_mapped_dataset.OutT],
cache_size: int | None = 10000
)

Bases: Dataset[OutT], Generic[InT, OutT]

Dataset wrapper that applies a transform function on-the-fly instead of preprocessing the whole dataset upfront with .map(fn).

Parameters:

dataset
_IndexedSource[InT]

Any object that supports __len__ and __getitem__ (e.g. a Hugging Face datasets.Dataset).

map_fn
Callable[[InT], OutT]

A callable that accepts a single example and returns the transformed example.

cache_size
int | NoneDefaults to 10000

Number of processed items to cache. Defaults to the 10k dataset samples. Set to 0 to disable caching or None to cache all.

Returns:

A map-style dataset that applies map_fn lazily on each item access.

_cache
_lru_cache_wrapper[OutT] | None
_get_item
Callable[[int], OutT]
cache_info
_CacheInfo | None

Return LRU cache statistics, or None if caching is disabled.

nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset.__getitem__(
index: int

Returns the transformed item at the given index

nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset.__getstate__() -> dict

Returns pickable state by dropping the unpicklable _get_item and _cache functions

nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset.__len__() -> int

Returns the number of items in the dataset

nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset.__repr__() -> str

returns a string representation of the dataset

nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset.__setstate__(
state: dict
) -> None

Restores state and rebuild _get_item after unpickling

nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDataset._build_get_item() -> None

Build the internal item accessor, with or without LRU caching

class nemo_automodel.components.datasets.lazy_mapped_dataset.LazyMappedDatasetConfig(
cache_size: int | None = 10000
)
Dataclass

Construction-time configuration for LazyMappedDataset.

dataset and map_fn are runtime objects rather than serializable config, so they are explicit build arguments.

cache_size
int | None = 10000

Number of processed items to cache (0 disables caching, None caches all).

Build a lazy mapping wrapper around a runtime dataset and transform.

Parameters:

dataset
_IndexedSource[InT]

Map-style dataset whose samples are transformed lazily.

map_fn
Callable[[InT], OutT]

Callable that converts one source sample into one output sample.

Returns: LazyMappedDataset[InT, OutT]

Lazy mapped dataset with the configured cache size.

class nemo_automodel.components.datasets.lazy_mapped_dataset._IndexedSource()
Protocol

Bases: Protocol[_ItemT_co]

Map-style source with a length and integer indexing, e.g. a Hugging Face datasets.Dataset.

nemo_automodel.components.datasets.lazy_mapped_dataset._IndexedSource.__getitem__(
index: int
nemo_automodel.components.datasets.lazy_mapped_dataset._IndexedSource.__len__() -> int
nemo_automodel.components.datasets.lazy_mapped_dataset.InT = TypeVar('InT')
nemo_automodel.components.datasets.lazy_mapped_dataset.OutT = TypeVar('OutT')
nemo_automodel.components.datasets.lazy_mapped_dataset._ItemT_co = TypeVar('_ItemT_co', covariant=True)
nemo_automodel.components.datasets.lazy_mapped_dataset.logger = logging.getLogger(__name__)