Skip to main content

Overview

ChemLactica provides utilities for loading and preparing datasets for both pretraining and supervised fine-tuning. The dataset system supports streaming JSONL files for efficient memory usage during pretraining and standard HuggingFace datasets for SFT.

get_dataset()

Main function for loading and preparing datasets based on training type.

Function Signature

Parameters

str
required
Type of training. Options: "pretrain" or "sft"
list[str]
required
List of directories containing training data files. For pretrain: directories with JSONL files. For SFT: path to HuggingFace dataset
str
required
Directory containing validation data files (JSONL format for pretrain)
list[str]
required
List of data types corresponding to each training directory. Must match length of training_data_dirs. Supported types defined in DIR_DATA_TYPES
dict
required
Training configuration object containing training hyperparameters
dict
required
Model configuration object containing model architecture parameters and tokenizer path
multiprocessing.Manager.dict
required
Shared dictionary for tracking JSONL file reading positions across processes (pretrain only). Pass None for SFT
bool
required
If True, only load validation dataset
bool
required
If True and not evaluate_only, skip loading validation dataset (evaluation runs separately via SLURM)
int
required
Size of shuffle buffer for assay datasets during pretraining

Returns

dict
Dictionary containing "train" and "validation" datasets. For pretrain, returns iterable datasets. For SFT, returns standard HuggingFace dataset dict

Pretrain Mode

When train_type="pretrain", the function:
  1. Validates that data types are supported
  2. Loads JSONL files from each training directory
  3. Creates iterable datasets using samples_generator
  4. Processes each dataset with tokenization and formatting
  5. Shuffles assay-type datasets with specified buffer size
  6. Interleaves multiple datasets if provided
  7. Loads validation dataset (unless evaluate_only=True or slurm_eval=True)

SFT Mode

When train_type="sft", the function loads a standard HuggingFace dataset:

Data Types

Supported data types are defined in DIR_DATA_TYPES. Common types include:
  • "molecules": Molecular structure data
  • "assay_split": Assay data that should be shuffled
  • Other domain-specific types
Datasets with “assay” in the type name are automatically shuffled using the specified shuffle_buffer_size.

samples_generator()

Generator function for streaming JSONL files in a distributed manner.

Function Signature

Parameters

list[str]
required
List of JSONL file paths to read
multiprocessing.Manager.dict
required
Shared dictionary for tracking file positions across processes, enabling checkpoint resumption
int
default:"25000"
Size of chunks for reading files (currently not used in line-by-line reading)
bool
default:"False"
Whether to return line position information with samples

Yields

dict
Dictionary with "text" key containing the line content from the JSONL file

Features

Distributed Reading

The generator distributes samples across multiple processes:
Each process only yields samples at indices matching its rank, ensuring no duplicate processing.

Checkpoint Resumption

The generator tracks file positions in shared_jsonl_files:
When resuming from a checkpoint, the generator seeks to the saved position in each file.

Sample Format

Each line is formatted as:

Usage Example

Dataset Processing

All datasets loaded by get_dataset() are processed using process_dataset from chemlactica.utils.dataset_utils, which handles:
  • Tokenization with the specified tokenizer
  • Sequence formatting and truncation
  • Batching and padding
  • Special handling for assay vs. non-assay data
Processing parameters:

Source Reference

  • get_dataset(): chemlactica/get_dataset.py:10
  • samples_generator(): chemlactica/jsonl_dataset.py:37