nemo_automodel.components.datasets.llm.offline_cache
nemo_automodel.components.datasets.llm.offline_cache
Shared on-disk helpers for speculative offline cache readers.
Module Contents
Classes
Functions
Data
API
Bases: Dataset
Lazily read fixed-key safetensors shards by sample index.
Buffer per-batch cache tensors and flush them as fixed-size sequential shards.
Shard indices count up from start_shard_index; a trailing partial shard is
written by :meth:finalize. Shared by the single-process and distributed
precompute loops so both produce the identical on-disk shard layout.
Append one computed batch, flushing whole shards as they fill.
Write the trailing partial shard, if any.
Return a sequential loader over dataset[start:end) mirroring dataloader.
Preserves the source loader’s worker settings: in particular
multiprocessing_context — the precompute paths load the target onto CUDA
before iterating, so fork-started workers would inherit a live CUDA context and
abort (see build_eagle3_dataloader’s forkserver note).
Write through a sibling temporary file, then atomically replace the target path.
Build a dataloader over a precomputed offline cache dataset.
Stack per-sample cache dicts into a batch.
Return an equivalent sequential dataloader beginning at start_sample.
Return the shard indices already present in cache_dir.
Return (save_file, safe_open) or raise a clear dependency error.
Return the manifest path inside cache_dir.
Assign a contiguous, shard-aligned block of samples to rank.
Splits the ceil(num_samples / shard_size) shards into contiguous runs across
world_size ranks (the first total_shards % world_size ranks take one
extra shard). Because the split is on whole shards, every shard is owned by
exactly one rank, so ranks can write straight into a shared output directory
with global shard indices and no cross-rank overlap. Ranks that receive no
shards (when total_shards < world_size) get num_local_samples == 0.
Returns (start_shard_index, start_sample, num_local_samples).
Load and validate an offline-cache manifest.
Return the sample index where a deterministic sequential resume should start.
Return the path of shard shard_index inside cache_dir.
Return shard indices, requiring exactly 0..N-1 for the manifest size.
Run a precompute loop and write sequential cache shards.
Distributed precompute loop: each rank writes its contiguous shard block.
The target model is sharded across all ranks (expert-parallel / FSDP), so every
compute_batch call is a collective that all ranks must enter the same number
of times. This rank forwards its own contiguous slice of the dataset (a different
slice per rank — pure data parallelism, which the MoE all-to-all routes tokens
for), and pads its step count up to the global maximum with dummy forwards whose
output is discarded, keeping the collectives in lockstep.
Writes are idempotent (atomic replace), so re-running after a partial failure
safely recomputes and overwrites rather than resuming. sync_max_steps reduces
the per-rank step count to the global max across ranks (an all-reduce MAX); it
defaults to the identity for a single-process run.
Persist an offline-cache manifest atomically.
Write one cache shard containing exactly the requested tensor keys.