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


Channel: Stanford Online
Uploaded by Stanford Online on 20240827
Categories: Education
Tags: Stanford, Stanford Online
For more information about Stanford's Artificial Intelligence programs visit: https://stanford.io/ai This lecture provides a concise overview of building a ChatGPT-like model, covering both pretraining (language modeling) and post-training (SFT/RLHF). For each component, it explores common practices in data collection, algorithms,

This video, titled "Stanford CS229 I Machine Learning I Building Large Language Models (LLMs)," is a lecture from Stanford Online. The speaker provides an overview of the components required to build and train Large Language Models (LLMs), shifting the focus from arc

Image for chunk 1

hitecture (which he notes is heavily covered in academia) to the more practical, industry-focused areas of data, evaluation, and systems.

The lecture is structured around the lifecycle of building an LLM:

1. Pre-training

The speaker defines pre-training as the "class

Image for chunk 2

ical language modeling paradigm," aimed at training a model to capture a probability distribution over sequences of tokens (modeling the internet).

Auto-regressive Models: LLMs are described as auto-regressive, predicting the next word based on the context of previou

Image for chunk 3

s words [05:16].

Tokenization: A crucial step to handle diverse text, including handling typos and non-Latin languages. He explains "Byte Pair Encoding" (BPE) as a common method where frequent character sequences are merged into tokens [12:31].

Data Challenges: The i

Image for chunk 4

nternet is "dirty." Pipelines involve:

Extraction: Converting HTML to plain text.

Filtering: Removing undesirable content (e.g., toxic, PII).

Deduplication: Removing boilerplate text like headers and footers.

Quality Filtering: Using rules or classifier models to pri

Image for chunk 5

oritize high-quality data (e.g., referencing Wikipedia).

2. Scaling Laws

Scaling laws demonstrate that larger models trained on more data result in predictably better performance [41:01].

Predictability: These laws allow developers to predict how much compute is need

Image for chunk 6

ed to achieve a certain level of performance.

Chinchilla Scaling: A famous finding that the optimal training compute involves a specific ratio—approximately 20 tokens per model parameter [51:36].

The Bitter Lesson: A concept suggesting that because scaling works so r

Image for chunk 7

eliably, "simple" architectures that can effectively leverage compute (combined with high-quality data and systems) outperform over-complicated models [54:03].

3. Post-training (Alignment)

This recent paradigm involves turning pre-trained models into AI assistants.

S

Image for chunk 8

upervised Fine-Tuning (SFT): Fine-tuning the pre-trained model on high-quality, human-labeled question-answer pairs to help the model learn the desired interaction format [01:02:26].

Reinforcement Learning from Human Feedback (RLHF): Used to overcome limitations of S

Image for chunk 9

FT (e.g., human ability constraints and hallucination). It involves:

Collecting human preferences (which answer is better).

Training a reward model to predict those preferences.

Optimizing the LLM policy using algorithms like PPO (Proximal Policy Optimization) or the

Image for chunk 10

simpler DPO (Direct Preference Optimization) [01:19:50].

4. Systems for LLMs

Because compute is the primary bottleneck and expensive, system optimization is critical.

GPU Optimization: GPUs are optimized for high-throughput matrix multiplication rather than latency.

Image for chunk 11

Low Precision: Using 16-bit (or mixed precision) instead of 32-bit floats to reduce memory consumption and speed up communication [01:40:01].

Operator Fusion: A technique (e.g., torch.compile in PyTorch) that rewrites code to perform multiple operations in one step,

Image for chunk 12

minimizing the need to move data between the GPU's global memory and its processors [01:42:34].

Summary of Key Takeaways

Component Focus Area

Architecture Transformer-based (assumed/stable)

Data Quality, cleaning, and filtering matter more than raw size

Scaling Comp

Image for chunk 13

ute-to-parameter ratio is predictable

Alignment SFT and RLHF/DPO are essential for assistant behavior

Systems Low precision and kernel fusion are key for efficiency

The lecture concludes with a recommendation for further learning, specifically pointing to courses lik

Image for chunk 14

e Stanford's CS336 (LLMs from scratch) for those interested in a deeper, more hands-on approach [01:44:05].

YouTube URL: https://www.youtube.com/watch?v=9vM4p9NN0Ts

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

Stanford Online · 2.4M views

Image for chunk 15

Viewer Discussion & Comments

@CG-hj1cu
I'm a student for life....approaching 40.....never had the privilege of attending a university like Stanford. To get access to these quality lectures is amazing. Thank you
@sagemantaena
i’d never skip his class.
@NuriddinUsmonov-m1z
I love how Yann breaks down the complexity of LLMs. AICarma's been great for keeping us visible in AI conversations. Can't recommend it enough!
@thedelicatehand
Suddenly I am interested in LLMS
@magorzatakomorowska1795
I come here to learn about LLMs, I come here to learn about LLMs, I come here to learn about LLMs 😌