Data Preparation
Preparing your data correctly is essential for successful training with Megatron Core.
Data Format
Megatron Core expects training data in JSONL (JSON Lines) format, where each line is a JSON object:
Preprocessing Data
Use the preprocess_data.py tool to convert your JSONL data into Megatron’s binary format:
Key Arguments
The following table summarizes the main preprocessor arguments:
Finding Optimal Number of Workers
Use the --find-optimal-num-workers flag to find the number of workers that gives the best performance in terms of preprocessed documents per second.
The script launches a few short data preprocessing runs with different worker counts and identifies the fastest run using the collected performance data.
Required arguments
The following table lists the arguments required for worker optimization:
Output example
The command prints performance results similar to the following:
Fast Preprocessing with GigaToken
For large corpora, tools/preprocess_data_fast.py offers a faster alternative to
preprocess_data.py. Instead of splitting documents across --workers processes and adding
them one at a time, it tokenizes whole JSONL files at once with
GigaToken and writes the result in a single batched
call via IndexedDatasetBuilder.add_documents().
Requires the gigatoken package (pip install gigatoken).
Key Differences from preprocess_data.py
Key Arguments
Performance
Benchmarked with the Qwen/Qwen3-8B HuggingFace tokenizer, preprocessing whole JSONL files:
preprocess_data_fast.py was consistently ~8.5x faster across both input sizes, driven by
whole-file GigaToken tokenization and IndexedDatasetBuilder.add_documents().
Output Files
The preprocessing tool generates two files:
processed_data.bin- Binary file containing tokenized sequencesprocessed_data.idx- Index file for fast random access
Using Preprocessed Data
Reference your preprocessed data in training scripts: