Stanford CS229 I Machine Learning I Building Large Language Models (LLMs)

Finished
Finished
Note
Status
Completed
Tags
Stanford Online
Total Videos
1
Video Duration
01:44:30
 
notion image
This slide, titled “What matters when training LLMs” (Large Language Models), highlights key components for effectively training large-scale AI models like GPT or similar systems. Here’s the breakdown:
1. Architecture (faded text)
While important, the architecture (e.g., transformer-based models) is somewhat standardized and less of a primary differentiator now compared to other factors.
2. Training algorithm/loss
• Refers to how models are trained, including optimization algorithms (like Adam) and loss functions (e.g., cross-entropy loss).
• Careful tuning of these methods can significantly impact performance and convergence speed.
3. Data
• High-quality, diverse, and large-scale datasets are critical for training LLMs.
• Data determines the model’s ability to generalize and perform across tasks.
4. Evaluation
• Methods and benchmarks used to test the model’s performance (e.g., accuracy, perplexity, real-world task success).
• Proper evaluation ensures the model works as intended and is not overfitted.
5. Systems
• Refers to the infrastructure, such as hardware (GPUs/TPUs), distributed computing frameworks, and optimization of training pipelines.
• Efficient systems reduce costs and speed up model training.
The “Model” box on the right indicates that these components collectively influence the quality and efficiency of the model being trained.
In summary, this slide emphasizes that training successful LLMs is not just about the model’s architecture but equally (or more) about training processes, data, evaluation strategies, and systems engineering.
 
notion image
 
notion image
 
notion image
This slide explains Loss in training language models, specifically focusing on cross-entropy loss and the goal of maximizing log-likelihood.
Key Points:
1. Classifying the Next Token’s Index
• The goal of the model is to predict the next token in a sequence.
• Example:
Training sentence: “I saw a cat on a mat <eos>”
• Given “I saw a”, the model should predict “cat”.
2. Cross-Entropy Loss
• The model outputs a probability distribution over all possible tokens.
• The target (correct token, “cat”) is assigned a label of 1.
• The loss is computed as:
• The closer is to 1, the smaller the loss.
• The model learns by minimizing this loss.
3. Loss Minimization Process (Visualization):
• The bar chart shows:
Decrease probabilities of incorrect tokens.
Increase probabilities of the correct token (“cat”).
4. Maximizing Log-Likelihood
• Minimizing cross-entropy loss is equivalent to maximizing the log-likelihood of the correct tokens.
• Mathematically:
• The rightmost expression represents the minimization of the loss function .
Takeaway:
The training objective is to maximize the probability of correct tokens appearing in a sequence (log-likelihood), which is equivalent to minimizing the cross-entropy loss. This ensures the model predicts accurate tokens based on prior context.
 
notion image
This slide discusses the Tokenizer, a key component in processing text for language models.
Key Points:
1. Why Use a Tokenizer?
More general than words: It can handle typos, unseen words, and variations better.
Shorter sequences than characters: Instead of processing each character, tokenizers group meaningful sequences into tokens, reducing the input size.
2. Idea:
Tokens represent common subsequences in text.
• They can be parts of words, entire words, or even sub-words, depending on the vocabulary size.
3. Example: Byte Pair Encoding (BPE)
• BPE is a widely used subword tokenization algorithm.
Steps to train BPE tokenizer:
1. Start with a large corpus of text.
2. Begin with one token per character (e.g., “t”, “o”, “k”, “e”, “n”).
3. Merge the most frequent pairs of tokens into a single token (e.g., “to”, “ken”).
4. Repeat the merging process until:
• The desired vocabulary size is reached, or
• All tokens are merged.
4. Visualization:
• Tokens like “tokenizer:”, “text to token”, and “index” are shown with color-coded subword parts.
• This highlights how tokens are broken into meaningful components.
Takeaway:
Tokenizers (like BPE) play a crucial role in converting text into sequences of tokens that models can process efficiently. By balancing between characters and full words, tokenizers allow language models to generalize better and handle unseen or rare text inputs effectively.
 
notion image
This slide explains LLM evaluation using Perplexity, a common metric for assessing the quality of language models.
Key Points:
1. Validation Loss
• The idea is to measure how well the model predicts unseen data using a loss function during validation.
2. Perplexity (PPL)
• Perplexity makes the validation loss more interpretable by converting it into an exponential form.
• Mathematically:
Where:
• is the average loss over tokens.
• is the probability of the current token given past context.
3. Interpretation of Perplexity
Average per token: Perplexity normalizes the loss, making it independent of the sequence length .
Exponentiation: This ensures the result is in units independent of the logarithm’s base, making it easier to interpret.
4. Range of Perplexity
Between 1 and :
1 indicates perfect prediction (low uncertainty).
|| means maximum uncertainty, where the model is equally uncertain across all tokens.
Intuition: Perplexity measures the number of tokens the model is “hesitating” between when predicting the next token.
Takeaway:
Perplexity is a measure of uncertainty in the model’s predictions. Lower perplexity means the model is better at predicting tokens, indicating higher performance.
 
notion image
 
notion image
notion image
notion image
 
notion image
This slide discusses the Data used for training large language models (LLMs), emphasizing practical strategies for curating clean, high-quality datasets.
Key Points:
1. Idea:
• Use all of the clean internet as the primary data source.
2. Challenges:
• The internet is “dirty” and not fully representative of ideal training data.
• Practical steps are needed to clean and process the data effectively.
Steps for Processing Internet Data:
1. Download all of the internet:
• Use sources like Common Crawl:
• Contains 250 billion pages with data size exceeding 1 petabyte (PB).
2. Text extraction from HTML:
• Remove irrelevant content like math expressions, boilerplate text, and code artifacts.
3. Filter undesirable content:
• Remove harmful, NSFW (not safe for work) content, and Personally Identifiable Information (PII).
4. Deduplication:
• Remove duplicate content (URLs, documents, or lines), such as recurring headers, footers, or forum menus.
5. Heuristic filtering:
• Remove low-quality documents based on:
• Word count
• Word length
• Outliers or “dirty” tokens.
6. Model-based filtering:
• Use models to predict whether a page is high-quality (e.g., can it be referenced by Wikipedia?).
7. Data mix:
• Classify data into categories (e.g., code, books, entertainment) and reweight the data domains.
• Use scaling laws to optimize performance across downstream tasks.
Additional Notes:
Learning Rate Annealing:
• Focus on high-quality data for better training.
• Use continual pretraining with longer context windows to further refine the model.
Takeaway:
Processing internet-scale data requires multiple filtering, deduplication, and reweighting strategies to ensure high-quality input. These steps significantly impact downstream model performance.
 
notion image
 
notion image
notion image
 
notion image
 
notion image
 
Here’s a timeline-based month-long plan to systematically train a large-scale model using 10,000 GPUs. The plan ensures efficient resource utilization and milestone tracking.
Week 1: Preparation and Preprocessing
Day 1–2: Infrastructure Setup
• Configure distributed training environment:
• Install frameworks: DeepSpeed, Megatron-LM, PyTorch FSDP.
• Optimize orchestration tools (SLURM/Kubernetes).
• Test GPU interconnect bandwidth and communication.
• Validate hardware utilization with a toy model.
Day 3–5: Dataset Curation and Preprocessing
Collect Data:
• Source text (Common Crawl, C4, Wikipedia, BooksCorpus).
• For multimodal: LAION-5B (images) or other paired datasets.
Preprocess:
• Tokenize data using SentencePiece or BPE.
• Filter duplicates and low-quality data.
• Shard and prepare for streaming.
• Perform a data throughput test to ensure GPUs won’t starve.
Day 6–7: Model Design and Parallelization Test
• Finalize architecture (e.g., GPT-style transformer or multimodal integration).
• Implement:
Tensor Parallelism (split model layers across GPUs).
Pipeline Parallelism (split computation across GPUs).
• Run a small-scale trial to verify scaling efficiency.
Week 2: Scaling Up Training
Day 8–9: Warmup Run
• Start training on a subset of the data with a smaller model size.
• Monitor:
• GPU utilization and communication overhead.
• Training loss curve and gradients.
• Memory usage.
Day 10–14: Full-Scale Training
• Launch full-scale training with 10,000 GPUs.
• Apply:
Mixed Precision (FP16/BF16) for speed.
• Gradient checkpointing to save memory.
• Learning rate warmup and decay scheduler.
• Continuous Monitoring:
• Track loss convergence, throughput, and hardware health.
• Log metrics in TensorBoard or WandB.
Week 3: Training and Validation
Day 15–21: Stable Training
• Maintain long training runs with:
• Regular checkpointing every few hours.
• Periodic validation on unseen data.
• Implement gradient clipping to avoid instability.
• Track:
Training loss vs validation loss.
• Performance metrics (e.g., perplexity).
Week 4: Evaluation, Fine-Tuning, and Deployment
Day 22–24: Final Model Checkpoint
• Evaluate model performance on benchmarks:
• LAMBADA, MMLU, or SuperGLUE for LLMs.
• COCO or VQA for multimodal tasks.
Day 25–27: Optional Fine-Tuning
• Fine-tune the model using:
Domain-specific datasets.
Reinforcement Learning with Human Feedback (RLHF) for alignment.
Day 28–30: Optimization and Deployment
Quantize the model (e.g., 4-bit/8-bit) for faster inference.
• Deploy with optimized frameworks:
Triton, vLLM, or TensorRT.
• Validate inference throughput across multiple GPUs.
Daily Milestone Tracking
Day Task Deliverable
1–2 Infrastructure setup Tested GPU cluster
3–5 Data preprocessing Ready-to-use dataset shards
6–7 Model architecture and trial runs Scalable model setup
8–14 Large-scale training Early checkpoints and loss curves
15–21 Stable training with monitoring Checkpointed trained model
22–24 Benchmark evaluation Metrics on standard benchmarks
25–27 Fine-tuning Domain-aligned fine-tuned model
28–30 Optimization and deployment Deployed, optimized model
This 4-week pipeline guarantees that you efficiently complete a trillion-parameter model training task within the allocated month. 🚀
 
Here’s a step-by-step pipeline for training a state-of-the-art model with 10,000 GPUs for a month. I’ll assume you’re training a large-scale LLM or multimodal model.
1. Project Setup and Goal Definition
Model Type: LLM, Multimodal, or Scientific (choose one).
Objective: Define the purpose — e.g., general reasoning, code generation, multimodal tasks.
Scale: Decide the parameter size (e.g., 1T–10T) based on compute availability.
2. Infrastructure Planning
Frameworks: Use distributed training frameworks:
DeepSpeed (efficient memory, ZeRO optimization).
Megatron-LM (parallelized transformers for LLMs).
PyTorch FSDP (fully sharded data parallelism).
Hardware Utilization:
• Use data parallelism, tensor parallelism, and pipeline parallelism to efficiently scale across 10K GPUs.
Cluster Orchestration:
• Tools: SLURM, Kubernetes, or custom cloud orchestration.
• Monitor GPUs for health (e.g., through Prometheus or NVIDIA DCGM).
3. Data Pipeline
Data Curation:
• Text: Use diverse datasets (C4, Pile, Common Crawl, Code repositories).
• Images/Audio: Multimodal datasets (LAION-5B, COCO, ImageNet, WIT).
Preprocessing:
• Tokenization: Use SentencePiece or BPE (Byte Pair Encoding) for text.
• Chunking: Split data into sequences (e.g., 2048–8192 tokens).
• Filtering: Remove duplicates, low-quality, or noisy data.
Data Sharding:
• Partition the data for efficient GPU loading.
• Use tools like WebDataset or TFRecord.
Streaming:
• Load data on the fly during training to save storage bandwidth.
4. Model Architecture
Base Architecture: Transformer (e.g., GPT-like or GPT-NeoX).
Customization: Add features like FlashAttention, rotary embeddings, or sparse transformers.
Multimodal Extensions (if needed):
• Add ViT (Vision Transformer) for images.
• Add Wav2Vec or Whisper for audio.
Model Parallelism:
• Implement tensor and pipeline parallelism for large models.
5. Training Pipeline
1. Initialize Model:
• Load model with sharded parameters for memory efficiency.
2. Optimization:
• Use AdamW or Lion optimizer.
• Scheduler: Implement cosine decay with warmup steps.
3. Gradient Management:
• Mixed precision training (FP16/BF16) to maximize speed.
• Gradient checkpointing for memory savings.
4. Distributed Training:
• Use frameworks like DeepSpeed or FairScale to shard the model.
• Verify data-parallel synchronization across GPUs.
5. Monitoring:
• Use WandB, TensorBoard, or MLFlow to log metrics like loss, learning rate, and GPU utilization.
6. Validation and Checkpointing
• Run periodic validation on a held-out dataset (e.g., 10% of the training set).
• Implement automated checkpointing (every N iterations or epochs).
• Use EMA (Exponential Moving Average) for smoother model weights.
7. Post-Training Tasks
1. Evaluation:
• Evaluate performance on benchmarks:
• Text: LAMBADA, WikiText, or MMLU.
• Multimodal: COCO, VQA.
2. Fine-Tuning (Optional):
• Fine-tune the model on specialized domains using RLHF or domain-specific datasets.
3. Scaling Down and Deployment:
• Quantize the model using 4-bit quantization for deployment.
• Deploy using optimized inference engines like TensorRT, vLLM, or Triton.
Tools Checklist
Task Tool
Distributed Training DeepSpeed, Megatron-LM
Data Streaming WebDataset, TFRecord
Monitoring WandB, TensorBoard, Prometheus
Optimization AdamW, Cosine LR, Gradient FP16
Cluster Management SLURM, Kubernetes
Model Deployment vLLM, TensorRT, Triton
Pipeline Summary
1. Define model and dataset goals.
2. Set up distributed infrastructure.
3. Preprocess and shard the data.
4. Configure model architecture and optimizations.
5. Train the model using parallelization and monitoring.
6. Validate, checkpoint, and evaluate on benchmarks.
7. Optimize for deployment.
With 10K GPUs for a month, this pipeline will allow you to train a trillion-parameter model efficiently and scale to cutting-edge benchmarks. 🚀
 
If you have 10,000 GPUs for a month, you are in a position to train a large-scale language model or other advanced models while leveraging scaling laws. Here’s a structured plan:
Key Model Options to Train
1. Large Language Model (LLM)
Objective: Train a transformer-based LLM at the scale of GPT-4 or similar models.
Parameters: Aim for 1-10 trillion parameters depending on infrastructure and dataset.
Dataset: Use diverse web-scale corpora, including books, code repositories, and multilingual datasets.
2. Multimodal Model
Objective: Train a model capable of handling text, image, audio, or video inputs simultaneously (like GPT-4 Vision or Flamingo).
Architecture: Combine transformers with vision encoders (CLIP/ViT).
Dataset: High-quality multimodal datasets like LAION-5B, ImageNet, or audio-text pairs.
3. Scientific Models
Protein Folding: Use large-scale GPU power to train deep models like AlphaFold for protein structure prediction.
Climate Modeling: Train models on massive geospatial and atmospheric datasets for accurate climate predictions.
4. Reinforcement Learning for AI Agents
• Combine RLHF (Reinforcement Learning from Human Feedback) with advanced models to train autonomous agents for tasks like robotics, games, and real-world control.
Scaling Laws Considerations
Scaling laws indicate that:
• Larger datasets, models, and compute yield logarithmic performance improvements.
• Efficient usage of GPUs (through parallelization frameworks like ZeRO, FSDP, and Megatron-LM) will maximize throughput.
Frameworks and Tooling
• Use frameworks like PyTorch or JAX.
• Distributed training libraries: DeepSpeed, Horovod, or Ray Train.
 
 
notion image
 
notion image
 
notion image
notion image
 
notion image
 
notion image
 
 
notion image
 
notion image
 
notion image
 
Idea: finetune pretrained LLM on a little desired data => “post-”training
 
To align an LLM (Large Language Model) so that it follows user instructions and designer’s desires (e.g., moderation, safety), here’s a structured alignment pipeline using Reinforcement Learning with Human Feedback (RLHF) and associated steps:
LLM Alignment Pipeline
1. Define Alignment Goals
User Instructions: Ensure the model reliably responds to diverse user queries.
Designer Desires: Implement boundaries like content moderation, ethical behavior, and safety checks.
Trade-offs: Balance helpfulness, safety, and harmlessness.
2. Dataset Preparation for Alignment
Step 1: Collect instruction-following examples.
• Source data from prompts and outputs where human users provide instructions and ideal completions.
Step 2: Curate moderation and edge-case examples.
• Include examples of harmful, unethical, or misleading queries (red-teaming).
• Add safe, aligned outputs for each scenario.
Step 3: Annotation:
• Use human annotators to rank model completions based on:
Helpfulness (task completion).
Honesty (accuracy and truthfulness).
Safety (no harmful or unethical outputs).
• Tools: Use WandB, Scale AI, or similar tools for efficient annotation tracking.
3. Supervised Fine-Tuning (SFT)
• Train the base LLM on the collected instruction-tuning dataset.
• Objective: Adapt the pre-trained model to follow instructions and avoid misalignment.
Loss: Cross-entropy loss on human-preferred outputs.
4. Reinforcement Learning with Human Feedback (RLHF)
RLHF ensures alignment by optimizing model outputs based on human preferences.
1. Step 1: Reward Model Training
• Train a reward model to score outputs:
• Input: Model completions.
• Output: Preference score.
• Use pairwise comparisons (A vs. B) provided by human annotators.
• Loss: Binary cross-entropy to align scores with human rankings.
2. Step 2: Fine-Tuning with PPO (Proximal Policy Optimization)
• Fine-tune the LLM using PPO:
• Reward = Human preference scores (reward model outputs).
• Balance exploration (diverse responses) and exploitation (following alignment signals).
• Apply KL divergence penalties:
• Prevent the model from deviating too far from the original fine-tuned LLM.
3. Step 3: Safety Reinforcement
• Penalize completions that trigger unsafe outputs.
• Add custom constraints using additional safety reward signals.
5. Evaluation and Testing
• Use benchmarks to verify alignment:
Helpful Outputs: HELM, TruthfulQA.
Safety: Red-team tests for harmful or biased completions.
Instruction Following: Assess on custom tasks or user-defined prompts.
• Conduct iterative testing with:
• Human annotators.
• Automated moderation tools.
6. Deployment with Safeguards
• Use a moderation layer (pre-trained classifiers) to detect unsafe queries before forwarding them to the LLM.
• Monitor outputs post-deployment for real-world alignment failures.
Summary of Key Steps
1. Collect instruction-following and moderation datasets.
2. Supervised fine-tuning of the pre-trained model.
3. Train a reward model using human preferences.
4. Optimize the LLM with RLHF and PPO.
5. Evaluate alignment on instruction-following, safety, and helpfulness benchmarks.
6. Deploy with ongoing monitoring and safeguards.
This pipeline ensures your LLM reliably follows user instructions while adhering to the designer’s goals for moderation and safety. 🚀
 
notion image
 
notion image
 
notion image
 
notion image
 
 
1:09:22 Maybe it's the same question, but why would these 2000 examples have such a overweighted influence on fine tuning? So that's why we-- also that's another reason why we call it post-training is that we use different type of hyperparameters. So, I told you basically at the end of pretraining you essentially end up with a learning rate of 0. Here, you're going to increase your learning rate. So like 1e minus 5, 1e minus-- yeah.  
When a small dataset (e.g., 2,000 examples) is used for fine-tuning a Large Language Model (LLM), it can have a disproportionately large influence on the model’s behavior because:
1. Fine-Tuning Overwrites Pre-Trained Knowledge
Pre-trained models like GPT-3 or GPT-4 are trained on trillions of tokens. The original training embeds general knowledge, reasoning, and patterns.
• Fine-tuning adjusts model weights on a much smaller, specialized dataset. Since fine-tuning uses low learning rates and continues from the pre-trained model’s state, small datasets can shift model behavior significantly.
Why?
The optimizer focuses heavily on fitting the fine-tuning data, prioritizing these new examples over the vast, generic pre-trained data. This “new information” overwrites or biases previously learned behavior.
2. Overfitting on Small Fine-Tuning Data
• With only 2,000 examples, the model can easily memorize patterns or overfit specific instructions or outputs.
• Fine-tuning introduces “narrow alignment” with the small dataset, which leads to overweighting of these examples compared to the pre-trained diversity.
Impact:
The model starts to generalize its behavior based on the small fine-tuning dataset, even if the dataset doesn’t cover the full complexity of language or tasks.
3. Gradient Update Magnitude
• Fine-tuning on a small dataset focuses gradients only on the examples provided. If those 2,000 examples are not representative, they skew the weights disproportionately.
• During fine-tuning:
• Fewer updates → Fewer generalization checks.
• Model adapts strongly to the fine-tuning loss, even if it’s a poor proxy for general tasks.
Example:
If the dataset contains instruction-following examples that overuse specific phrases, the model might bias its completions toward those patterns.
4. Dataset Curation and Bias
• Fine-tuning datasets are often hand-picked and focused (e.g., alignment, moderation, or domain-specific tasks).
• The small size amplifies any bias or patterns in the dataset:
• Repeated instructions get reinforced.
• Underspecified tasks cause misgeneralization.
• The LLM “learns” these patterns quickly, assuming they are universally true.
5. Low Regularization in Fine-Tuning
• Fine-tuning often lacks regularization (e.g., dropout, weight decay) compared to large-scale pretraining.
• Without sufficient regularization, the model weights overfit to the fine-tuning data, resulting in disproportionate influence.
6. Fine-Tuning Targets Specific Layers
• Modern fine-tuning often targets specific layers or parameters (e.g., LoRA, adapters).
• A small dataset focuses on modifying localized parts of the model without retraining the entire parameter set.
• This focused modification means the fine-tuning data exerts a larger “pull” on model behavior.
Summary
A small dataset like 2,000 examples can have an overweighted influence during fine-tuning because:
1. Fine-tuning strongly overwrites pre-trained behavior.
2. The model overfits on small data due to its limited diversity.
3. Gradients and learning rates amplify the fine-tuning dataset’s patterns.
4. Dataset biases get magnified.
5. Insufficient regularization makes overfitting easier.
Solution:
• Use techniques like regularization, reward models, and larger, more diverse fine-tuning datasets to mitigate overweighted influence.
• Methods like RLHF (Reinforcement Learning from Human Feedback) help generalize alignment better beyond small datasets.
 
notion image
 
 
notion image
 
notion image
Let me help explain this concept from what appears to be a Stanford lecture slide about RLHF (Reinforcement Learning from Human Feedback) using PPO (Proximal Policy Optimization).
The slide outlines a sophisticated approach to training language models using reinforcement learning with human preferences. Let me break this down step by step:
First, there are two key questions being addressed:
  1. How to use reinforcement learning for language model training
  1. How to define an appropriate reward signal
The slide presents two options for handling the reward:
The first option is straightforward but limited: simply check if the model's output is preferred compared to a baseline. However, this creates a binary reward (essentially just "good" or "bad"), which doesn't provide much nuanced information for learning.
The second option, which is more sophisticated, introduces a reward model R that's trained using logistic regression to classify preferences. This uses the Bradley-Terry model (from 1952), which gives the probability that option i is preferred over option j using the formula:
This approach is more informative because it provides continuous values rather than just binary feedback. The logits (log-odds) from R give rich information about the strength of preferences.
The optimization objective shown in the formula uses PPO to maximize:
This formula has two main components:
  1. R(x,ŷ): The reward from the reward model
  1. A regularization term (the log ratio multiplied by β) that prevents the policy from deviating too far from a reference policy, helping avoid overoptimization
The final note about "LMs are policies not a model of some distribution" is important because it frames language models in reinforcement learning terms - they're making decisions about what tokens to output rather than just modeling probability distributions.
Would you like me to elaborate on any particular aspect of this approach? I can dive deeper into the PPO algorithm, the Bradley-Terry model, or how the reward modeling works in practice.
 
Let me explain PPO (Proximal Policy Optimization), which is one of the most popular and effective reinforcement learning algorithms. I'll break this down step by step to build a clear understanding.
First, let's understand the core challenge PPO tries to solve. In reinforcement learning, we want to improve a policy (which determines what actions to take), but we need to do this carefully. If we make changes that are too large, the policy might become worse instead of better. It's like trying to climb a hill in the fog - you want to take steps in the right direction, but not so large that you might accidentally fall off a cliff.
PPO introduces a brilliant solution to this challenge through what's called "trust region" policy optimization. Here's how it works:
  1. Data Collection Phase First, the algorithm collects experiences using the current policy. In the context of language models, this means generating text samples and getting rewards for them. The policy at this stage is called the "old policy" or "behavioral policy."
  1. Advantage Estimation For each action taken, PPO calculates how much better (or worse) it was compared to what we expected. This difference is called the "advantage." It's like keeping score of how surprisingly good or bad each decision turned out to be.
  1. Policy Update Phase This is where PPO's key innovation comes in. The algorithm updates the policy using a special objective function:
Where:
  • is the ratio of probabilities between the new and old policies
  • is the advantage estimate
  • is a small number (often 0.2) that limits how much the policy can change
The genius of this formula is the minimum operation combined with clipping. Here's what it does:
  • If an action was good (positive advantage), the policy is encouraged to make that action more likely, but not by too much (clipped at 1+ε)
  • If an action was bad (negative advantage), the policy is encouraged to make that action less likely, but again, not by too much (clipped at 1-ε)
  1. Multiple Optimization Steps PPO typically performs multiple optimization steps on the same batch of data, which is more computationally efficient than older algorithms. It can do this safely because of the clipping mechanism that prevents too large of changes.
In the context of RLHF (Reinforcement Learning from Human Feedback), PPO is particularly valuable because:
  • It's stable: The clipping mechanism prevents catastrophic policy changes that could make the language model suddenly perform much worse
  • It's sample efficient: It can learn effectively from a relatively small amount of human feedback
  • It's compatible with deep neural networks: The algorithm works well with the large neural networks used in modern language models
The implementation usually involves:
The regulatory term we saw in the RLHF slide (β log ratio) serves a similar purpose to PPO's clipping mechanism - both prevent the policy from changing too drastically. This helps maintain the language model's original capabilities while gradually improving it based on human preferences.
 
 
notion image
This slide illustrates the three-step process of RLHF (Reinforcement Learning from Human Feedback) as implemented in ChatGPT, based on the Ouyang+ 2022 paper. Let me walk you through each step and explain how they work together to create an AI assistant that learns from human preferences.
Step 1: Supervised Fine-Tuning (SFT) First, we start with demonstration data - this is like giving the AI examples of good behavior. Imagine a teacher showing students how to solve math problems before asking them to try on their own. In this step:
  • A prompt is selected from a dataset (like "Explain the moon landing to a 6-year-old")
  • A human labeler provides an example of a high-quality response
  • This demonstration data is used to fine-tune GPT-3 using supervised learning, teaching it to mimic these good examples
Step 2: Reward Model Training Next, we build a way to score how good different responses are. Think of this like creating a rubric for grading essays. Here's how it works:
  • The system takes a prompt and generates several different responses
  • Human labelers rank these outputs from best to worst
  • These rankings are used to train a reward model (RM) that can automatically score new responses
  • The reward model learns to predict which responses humans would prefer, based on the ranking patterns it observed
Step 3: Reinforcement Learning Optimization Finally, we use PPO (Proximal Policy Optimization) to actually improve the model's responses. This is like practicing and getting better through feedback. The process works by:
  • Taking a new prompt from the dataset
  • Having the AI generate a response
  • Using the reward model to score how good that response is
  • Using this reward signal to update the AI's policy (its decision-making process) through PPO
  • The model gradually learns to generate responses that will score higher according to the reward model
What makes this approach powerful is how it combines human guidance at multiple levels:
  • Direct examples of good behavior (Step 1)
  • Human judgment about what makes responses better or worse (Step 2)
  • Automated improvement based on these human preferences (Step 3)
It's worth noting that this process created significant improvements in model performance according to the Ouyang+ 2022 paper, particularly in areas like helpfulness and truthfulness. The system essentially learns to align its responses with human values and preferences through this iterative feedback process.
 
notion image
 
notion image
 
notion image
 
 
notion image
notion image
notion image
notion image
notion image
 
notion image
 
Let me explain how to express BF16 number representations using LaTeX formats. Here's how to express a floating-point number in BF16:
A general BF16 number has the form:
where:
  • s is the sign bit (0 or 1)
  • e is the 8-bit exponent (biased by 127)
  • m is the 7-bit mantissa
For example, let's express 13.375 in BF16:
  1. First, convert to binary: 13.375 = 1101.011₂
  1. Normalize to scientific notation: 1.101011₂ × 2³
  1. Express in BF16 format components:
      • Sign (s) = 0 (positive)
      • Exponent (e) = 3 + 127 = 130 (10000010₂)
      • Mantissa (m) = 1010110₂
  1. Put together in latex:
Special values in BF16 can be expressed as:
Zero:
Infinity:
NaN (Not a Number):
 
 
FP32 (32-bit floating point):
  • 1 bit for sign
  • 8 bits for exponent
  • 23 bits for mantissa
BF16 (16-bit brain floating point):
  • 1 bit for sign
  • 8 bits for exponent
  • 7 bits for mantissa
 
notion image
 
notion image
 
 
  • Giscus
quantum
literature base
video notes