cursus.processing.datasets¶
Dataset classes for PyTorch training pipelines.
Provides both regular (map-style) and streaming (iterable-style) datasets with identical pipeline injection APIs.
- class PipelineDataset(*args, **kwargs)[source]¶
Bases:
DatasetCustom dataset for multimodal input supporting text, tabular, categorical, and Parquet/CSV/TSV file formats with per-column processing pipelines.
- add_pipeline(field_name, processor_pipeline)[source]¶
Adds a processing pipeline for a specified field. The pipeline is built by composing Processors via the >> operator. For example, for the text field ‘dialogue’, you might have:
- pipeline = (HTMLNormalizerProcessor() >> EmojiRemoverProcessor() >>
TextNormalizationProcessor() >> DialogueSplitterProcessor() >> DialogueChunkerProcessor(tokenizer, max_tokens=512) >> TokenizationProcessor(tokenizer, add_special_tokens=True))
- which you then add via:
dataset.add_pipeline(“dialogue”, pipeline)
- class PipelineIterableDataset(*args, **kwargs)[source]¶
Bases:
IterableDatasetStreaming dataset for multimodal input with distributed training support.
Memory-efficient alternative to PipelineDataset that loads data incrementally from multiple shard files. Maintains the same pipeline injection API for backward compatibility.
Distributed Training Support:
The dataset implements two-tier sharding for distributed training:
Rank-based sharding: Shards are distributed across GPU ranks using round-robin assignment (rank 0 gets shards [0, world_size, 2*world_size, …]). This ensures each GPU processes unique data in FSDP/DDP training.
Worker-based sharding: Within each rank, shards are further distributed across DataLoader workers for parallel loading.
Example Usage:
- Single GPU training:
>>> dataset = PipelineIterableDataset( ... config=config, ... file_dir="/data/train", ... ) >>> loader = DataLoader(dataset, batch_size=32, num_workers=4)
- Distributed training (FSDP):
>>> # Same code! Distribution happens automatically >>> dataset = PipelineIterableDataset( ... config=config, ... file_dir="/data/train", ... ) >>> loader = DataLoader(dataset, batch_size=32, num_workers=4) >>> >>> trainer = pl.Trainer(strategy=FSDPStrategy(), devices=8) >>> trainer.fit(model, loader)
- Epoch-aware shuffling:
>>> for epoch in range(num_epochs): ... dataset.set_epoch(epoch) # Important for deterministic shuffling ... for batch in loader: ... # Training step
- config¶
Configuration dictionary (same as PipelineDataset)
- processor_pipelines¶
Dictionary mapping field names to Processor pipelines
- shard_files¶
List of shard file paths to stream through
- shuffle_shards¶
Whether to shuffle shard order per epoch
- Key Differences from PipelineDataset:
Inherits from IterableDataset (not Dataset)
Implements __iter__() instead of __getitem__()
Loads shards incrementally (not all at once)
No __len__() by default (optional estimate available)
Automatic multi-GPU and multi-worker shard distribution
- add_pipeline(field_name, processor_pipeline)[source]¶
Add a processing pipeline for a specified field.
IDENTICAL API to PipelineDataset.add_pipeline() for drop-in compatibility.
The pipeline is built by composing Processors via the >> operator. For example:
- pipeline = (HTMLNormalizerProcessor() >>
EmojiRemoverProcessor() >> TextNormalizationProcessor() >> DialogueSplitterProcessor() >> DialogueChunkerProcessor(tokenizer, max_tokens=512) >> TokenizationProcessor(tokenizer))
- fill_missing_value(**kwargs)[source]¶
Configure missing value handling rules.
IDENTICAL API to PipelineDataset.fill_missing_value() for compatibility.
Note: For IterableDataset, this sets rules to apply during iteration. The actual filling happens in _postprocess_dataframe() when each shard is loaded.
- Parameters:
**kwargs – Configuration updates (label_name, cat_field_list, etc.)
- get_shard_distribution_info()[source]¶
Get diagnostic information about shard distribution.
- Returns:
total_shards: Total number of shards
shards_per_rank: Number of shards assigned to this rank
shards_per_worker: Number of shards per worker
rank: Current rank
world_size: Total number of ranks
worker_id: Current worker ID (if available)
num_workers: Total number of workers per rank
assigned_shards: List of shard files assigned to this rank/worker
- Return type:
Dict containing
Modules
Streaming dataset implementation using PyTorch's IterableDataset. |