• About Me
  • Blogs
  • Projects
  • 100 PwC
  • Learning Notes
    • Stanford CS336: LLM from Scratch
    • DLFaC
    • LLM Model Series

CS336: LLM from Scratch Lecture Notes and Assignments

CS336: LLM from Scratch Lecture Notes and Assignments

Note

Due to the time constraint, these notes may contain errors or omissions. And to speed up the writing process, I only wrote the notes in CHINESES. If you are interested in collaborating to improve these notes,or transalting to different languages, please feel free to contact me.

Related Resources:

  • Lecture Website: CS336 LLM from Scratch
  • Lecture Recordings: YouTube Playlist
  • My Solution Repo: GitHub

About this Course:

  • This course has 17 Lectures and 5 Assignments in total.
  • It might take around 200 hours to finish all the lectures and assignments.

Lecture Notes for CS336

Lecture 01: Introduction & Tokenization

Lecture01介绍了课程的大纲以及LLM的现状和基本概念。在课程的后半段介绍了Language Modeling的第一步,即Tokenization的基本概念和常用方法。着重介绍了Byte Pair Encoding (BPE)算法的原理和实现。在学习完Lecture 01后,我们可以开始尝试Assignment 01的第一部分,即BPE-Tokenization的实现

Yuyang Zhang

Lecture 02: PyTorch Basics & Resource Accounts

Lecture02 介绍了PyTorch的基本概念和使用方法。可以将这节课当作一个review,复习一下之前学过的PyTorch知识点。同时,课程中介绍了一个 einops 的库,可以简化张量操作的代码编写。这节课也介绍了不同数据类型(如FP32, FP16, BF16等)在深度学习中的应用和优缺点。并且通过计算这些数据类型在内存中的占用,帮助我们理解为什么有些数据类型更适合在有限资源下进行训练, 并且在什么情况下需要应用混合精度训练(Mixed Precision Training),什么情况下需要用高精度的数据类型。在课程的最后,还介绍了不同的Optimizer(如SGD, Adam等)的基本原理和使用场景

Yuyang Zhang

Lecture 03: LM Model Architecture & Hyperparameters

Lecture03 介绍了现代大语言模型的核心架构与超参数设计。课程对比了原始 Transformer 与主流 LLaMA-like 架构,总结了 pre-norm、RMSNorm、SwiGLU、RoPE 等关键设计的经验共识,并结合大量近期模型实践,讲解了 MLP 宽度比例、注意力头配置、模型深宽比与词表规模等超参数选择原则。同时还介绍了 z-loss、QK-Norm、MQA/GQA 等用于提升训练稳定性和推理效率的关键技巧。

Yuyang Zhang
No matching items

Assignments

 

Assignment 01: Tokenization & Language Modeling

Assignment 01 要求我们实现一个简单的语言模型训练流程,涵盖数据预处理、模型定义、训练和评估等步骤。通过这个作业,我们将巩固对自然语言处理基础概念的理解,并掌握使用PyTorch进行深度学习模型开发的基本技能

Yuyang Zhang
No matching items
Back to top

© CC-By Yuyang, 2025

 

This page is built with ❤️ and Quarto.