Combine multiple datasets with CombinedStreamingDataset
mainUse CombinedStreamingDataset to mix multiple datasets into a single stream. This is useful for creating data mixtures (e.g., combining SlimPajama and StarCoder).
Mixing Modes
iterate_over_all=True(default): Iterates until all datasets are exhausted. Do not passweights(LitData derives them from dataset lengths; passing both raisesValueError).iterate_over_all=False: Stops when any dataset is exhausted. You must pass explicitweightsfor your mixture.
Batching Methods (batching_method)
stratified(default): Each batch contains a mix of samples from multiple datasets according to the provided weights.per_stream: Each batch comes from only one randomly selected dataset. Use this if datasets have different shapes or dtypes.
Other Options
seed: Random seed (default42).force_override_state_dict=True: Allows local constructor arguments to override a loaded checkpoint.
from litdata import StreamingDataset, CombinedStreamingDataset, StreamingDataLoader, TokensLoader
import os
train_datasets = [
StreamingDataset(
input_dir="s3://tinyllama-template/slimpajama/train/",
item_loader=TokensLoader(block_size=2048 + 1),
shuffle=True,
drop_last=True,
),
StreamingDataset(
input_dir="s3://tinyllama-template/starcoder/",
item_loader=TokensLoader(block_size=2048 + 1),
shuffle=True,
drop_last=True,
),
]
weights = (0.693584, 0.306416)
combined_dataset = CombinedStreamingDataset(
datasets=train_datasets,
seed=42,
weights=weights,
iterate_over_all=False,
)
train_dataloader = StreamingDataLoader(combined_dataset, batch_size=8, pin_memory=True, num_workers=os.cpu_count())