從零打造大型語言模型
從 tensors 與 gradients 開始,逐步實作 Transformer 元件、訓練與推論最佳化,最後完成 Tiny LLaMA。
學習目標
- 理解 LLM forward、backpropagation 與 autograd
- 實作 tokenization、position encoding、normalization 與 attention
- 使用 FlashAttention、MoE 與 LoRA
- 建立訓練 pipeline、KV cache 與 Tiny LLaMA
基礎
LLM01 — LLM 介紹與推論
載入預訓練模型、tokenize 文字並執行 autoregressive generation。
LLM02 — 前向傳播
理解 tensor operations、linear layers 與 activations。
LLM03 — 反向傳播與 Autograd
建立 computation graph、驗證 gradient 並完成訓練迴圈。
Transformer 元件
LLM04 — Tokenization 與位置編碼
實作 tokenizer、embedding、sinusoidal encoding 與 RoPE。
LLM05 — Normalization 與 FFN
比較 LayerNorm、RMSNorm、SwiGLU 與 Pre-LN/Post-LN。
LLM06 — Attention 機制
實作 scaled dot-product、causal mask、MHA 與 GQA。
效率與適應
LLM07 — FlashAttention
理解 GPU memory hierarchy、tiling 與 IO-aware attention。
LLM08 — MoE 與數值精度
學習 Mixture of Experts 與數值格式。
LLM09 — LoRA 微調
使用 Low-Rank Adaptation 進行參數高效率微調。
訓練與資料
LLM10 — 資料處理與模型封裝
處理 dataset、state_dict、safetensors 與 HuggingFace wrapper。
LLM11 — 模型訓練 Pipeline
建立 collate、loss、AMP、gradient accumulation 與 Trainer。
推論與服務
LLM12 — 推論與 KV Cache
理解 prefill/decode、decoding strategies 與 KV cache。
LLM13 — Sparse Attention 與 PagedAttention
學習 sliding window、attention sink 與 block-based KV memory。
總整專題
LLM14 — 從零打造 Tiny LLaMA
整合 RoPE、RMSNorm、MHA、SwiGLU、訓練與文字生成。
接著探索實體 AI或其他 AI 基礎課程。