Data Preparation Fundamentals
Effective LLM training depends critically on data quality and preparation. Pre-training data typically comprises hundreds of billions of tokens from diverse sources: web crawls (Common Crawl), books (Project Gutenberg), academic papers, code repositories, and specialized corpora. For fine-tuning, the data requirements are more modest but quality becomes paramount.
Data Collection and Curation: Pre-training data collection involves crawling the internet, filtering low-quality content, and deduplicating. Quality metrics include language identification (filtering non-English or non-target language content), toxicity filtering, and removal of personal information. For fine-tuning datasets, the process is more deliberateācarefully selecting examples that represent target task distributions.
Tokenization and Preprocessing: Raw text must be converted to tokens through tokenization. Modern LLMs use subword tokenization schemes like Byte-Pair Encoding (BPE) or SentencePiece, which balance vocabulary size and compression efficiency. A typical vocabulary contains 50,000-100,000 tokens. Preprocessing involves:
- Normalizing text (lowercasing, removing special characters)
- Handling special tokens ([CLS], [SEP], [PAD], [UNK])
- Creating token sequences of fixed length (typically 512-4096 tokens)
- Handling sequences longer than maximum length through truncation or sliding windows
Practical Example: For a medical fine-tuning dataset, raw clinical notes are collected, de-identified (removing patient names, medical record numbers), tokenized, and paired with desired outputs (diagnoses, treatment recommendations). Quality assurance involves medical professionals reviewing a sample of examples to ensure accuracy and appropriateness.
Data Filtering and Deduplication: Duplicate data inflates apparent dataset size while reducing learning efficiency. Deduplication at document or sequence level is standard practice. Filtering removes:
- Low-quality text (excessive misspellings, gibberish)
- Toxic or harmful content
- Personally identifiable information
- Non-text content (metadata, markup)
Studies show that removing the lowest-quality 10% of pre-training data can improve model quality as much as adding 10% more data, emphasizing quality over quantity.
Balancing and Stratification: For fine-tuning, ensuring balanced representation of different task categories prevents models from developing spurious correlations. If a classification dataset has 90% positive examples and 10% negative, the model might learn to predict "positive" by default. Stratification ensures training, validation, and test sets have similar distributions.
Understanding Scaling Laws
Scaling Laws describe how model performance improves with increases in model size (parameters), training data size (tokens), and compute budget. These relationships, empirically discovered and theoretically motivated, are fundamental to understanding LLM development.
The Power-Law Relationship: Empirical research by OpenAI, DeepMind, and others demonstrates that performance follows power-law scaling: Performance ā N^α, where N is model size (parameters) and α ā -0.07 (meaning roughly 10x more parameters yields ~15-20% performance improvement on benchmarks). Similar relationships hold for data size and compute.
Chinchilla Scaling: Original scaling laws suggested compute should be allocated primarily to model size, with less emphasis on data. Chinchilla scaling (from DeepMind) demonstrated that optimal performance allocates compute more evenly between model size and data size. For a given compute budget C, optimal model size N and data size D satisfy: N ā D and C ā 6ND, meaning compute is roughly 6 times the number of parameters.
Practical Implications: A team with a compute budget equivalent to training 10 billion parameters should allocate roughly 10 billion tokens of data, not 100 billion. This insight fundamentally changed LLM development, leading to models like Chinchilla and subsequent architectures that prioritize data efficiency.
Compute-Optimal Training: The relationship between compute (C), parameters (N), and tokens (D) can be expressed as: C = 6ND. Given a fixed compute budget, organizations must choose how to allocate resources. Underfitting (too little data for model size) wastes model capacity. Overfitting (too much data for model size) wastes data. Optimal allocation balances these concerns.
Benchmark Performance Scaling: On standard benchmarks like MMLU (multiple choice questions) or HellaSwag (commonsense reasoning), performance improvements follow predictable curves. A model with 1 billion parameters might achieve 25% accuracy on MMLU, while a 70-billion parameter model achieves 65%. These curves enable prediction of performance for models not yet trained, informing investment decisions.
Limitations and Nuances: Scaling laws apply to average performance on benchmark tasks but don't capture emergent capabilities that appear suddenly at certain scale thresholds. Few-shot learning, in-context learning, and reasoning abilities show non-monotonic improvements. Scaling laws also don't account for architectural innovations or training techniques that can yield disproportionate improvements.
Training Optimization Techniques
Learning Rate Scheduling: The learning rate controls step size during gradient descent. Starting with high learning rates enables rapid initial progress but risks instability. Schedules typically:
- Begin with a warmup phase (linearly increasing learning rate from 0)
- Maintain peak learning rate for the majority of training
- Decay learning rate in the final phase (cosine annealing common)
For a 1 trillion token training run, a typical schedule might warm up for 5 billion tokens, maintain peak rate for 990 billion tokens, then decay over the final 5 billion tokens.
Gradient Accumulation: Memory constraints often prevent using desired batch sizes. Gradient accumulation computes gradients on smaller batches, accumulating them before weight updates. Training with effective batch size 4096 might use gradient accumulation over 4 batches of 1024 examples, achieving similar convergence to full-batch training while fitting in memory.
Mixed Precision Training: Modern GPUs accelerate float16 (half-precision) operations while float32 (full-precision) provides numerical stability. Mixed precision training uses float16 for most computations but maintains float32 copies of weights and master weights, combining efficiency and stability. This technique reduces memory usage by ~50% and accelerates training by 2-3x with minimal accuracy loss.
Distributed Training: Pre-training LLMs requires distributed training across many GPUs or TPUs. Strategies include:
- Data Parallelism: Different devices process different data batches, aggregating gradients
- Model Parallelism: Different devices hold different model layers
- Pipeline Parallelism: Devices process different stages of the pipeline sequentially
Modern large-scale training uses combinations of these approaches. Synchronization overhead becomes significant with many devices, so techniques like gradient compression and asynchronous updates are employed.
Checkpointing and Recovery: Training large models for weeks requires handling failures. Regular checkpointing saves model weights, optimizer states, and random number generator states. Upon failure, training resumes from the most recent checkpoint. Advanced systems implement incremental checkpointing, saving only changed parameters to reduce I/O overhead.
Validation and Early Stopping: During training, models are periodically evaluated on held-out validation data. If validation loss plateaus or increases, training can be stopped early to prevent overfitting. For pre-training, validation typically uses perplexity (inverse probability of held-out text). For fine-tuning, task-specific metrics (accuracy, F1, BLEU) are monitored.
Optimization Algorithms: While standard SGD works, adaptive optimizers like Adam or AdamW are standard for LLM training. These maintain per-parameter learning rates that adapt based on gradient history, often providing faster convergence. Weight decay (L2 regularization) prevents overfitting and is critical for generalization.
Practical Example of Optimization: Training a 70-billion parameter model might use:
- 2,000 GPUs with data parallelism
- Batch size 4,096 (effective), achieved through gradient accumulation
- Learning rate warmup over 5,000 steps, then cosine decay
- Mixed precision training (float16 computations, float32 weights)
- Checkpointing every 1,000 steps
- Validation on 10,000 examples every 10,000 steps
- Training for 300 billion tokens over approximately 2 months
Monitoring and Debugging: Training loss should decrease smoothly. Sudden spikes indicate numerical instabilities or data issues. Validation metrics should track training loss closely; large gaps suggest overfitting. Gradient norms and activation statistics are monitored to detect vanishing/exploding gradients or pathological behavior.
The intersection of data preparation quality, understanding scaling laws, and implementing sophisticated training optimizations determines whether LLM training succeeds efficiently or fails expensivelyāmaking these technical details central to practical LLM development.