M5-018M5: NLP & Large Language ModelsScaling Laws & Compute AllocationHard
⚡Flashcard Drill➔Mastery:

Guiding Hyperparameter and Architecture Choices via Scaling Laws

📐 Mathematical Definition
L(N,D) fit at small scale→predict at large;μP: transfer hyperparams\mathcal{L}(N,D)\ \text{fit at small scale}\to\text{predict at large};\qquad \mu\text{P}:\ \text{transfer hyperparams}
⚡ One-Sentence Core Answer
Scaling laws guide pre-training hyperparameter tuning by using Maximal Update Parametrization (μ\muP) to transfer optimal learning rates from tiny proxy models directly to hundred-billion-parameter models without expensive hyperparameter sweeps.

📌 Key Takeaways

  • •
    The hyperparameter scaling challenge: running grid searches for learning rate, batch size, and initialization on a 70B+ model costs millions of dollars and is practically impossible
  • •
    Maximal Update Parametrization (μ\muP, Yang et al.): rescales layer initializations and learning rates by width dd, guaranteeing that feature representations update at identical rates regardless of model width
  • •
    Predictable zero-shot transfer: optimal hyperparameters (learning rate, weight decay, Adam ϵ\epsilon) found on a 10M proxy model transfer directly to a 100B model without modification

📐 Mathematical Derivations

Mathematical Mechanism: 1. Standard Parametrization (SP) Breakdown: In standard PyTorch initialization: weights are initialized as W∼N(0,1/din)W \sim \mathcal{N}(0, 1/d_{\text{in}}), and learning rate η\eta is constant across all layers. As width d→∞d \to \infty: - Activations h=Wxh = W x have variance Var(h)=d⋅(1/d)=1\text{Var}(h) = d \cdot (1/d) = 1 (stable). - However, weight updates ΔW=−η∇WL\Delta W = -\eta \nabla_W \mathcal{L} scale as Δh=ΔWx∝ηd\Delta h = \Delta W x \propto \eta d, causing activation updates to explode with width dd. Consequently, the optimal learning rate shrinks as dd grows: η∗(d)∝1/d\eta^*(d) \propto 1/d, preventing hyperparameter transfer across model sizes. 2. Maximal Update Parametrization ($\mu$P) Rules: Rescales parameters and learning rates by width multiplier m=d/dbasem = d / d_{\text{base}}: - Hidden-to-hidden weights WhiddenW_{\text{hidden}}: Init∝1d\text{Init} \propto \frac{1}{\sqrt{d}}, Learning Rate ηhidden=ηbasem\eta_{\text{hidden}} = \frac{\eta_{\text{base}}}{m}. - Output projection WheadW_{\text{head}}: Init∝1d\text{Init} \propto \frac{1}{d}, Learning Rate ηhead=ηbasem2\eta_{\text{head}} = \frac{\eta_{\text{base}}}{m^2}. - Attention logits: scaled by 1d\frac{1}{d} rather than 1d\frac{1}{\sqrt{d}}. Under μ\muP, both forward activation norms and backward update norms remain constant O(1)O(1) as width d→∞d \to \infty, ensuring that the optimal learning rate η∗\eta^* is strictly invariant to model width.

🏭 Production Trade-offs

Deep Dive & Engineering Trade-offs: ① Batch Size Scaling Law: Critical batch size Bcrit(L)B_{\text{crit}}(L) scales inversely with loss: Bcrit∝1/LB_{\text{crit}} \propto 1 / L. Early in training, batch size should be small; as training progresses and loss drops, batch size can expand to thousands of sequences without gradient noise saturation. ② Width vs Depth Allocations: Empirical scaling laws prove that scaling width dmodeld_{\text{model}} and depth NlayersN_{\text{layers}} together (aspect ratio N/d≈constantN / d \approx \text{constant}) is compute-optimal. Extremely deep, narrow models suffer from gradient propagation delay; extremely wide, shallow models suffer from memory bandwidth inefficiencies. ③ Learning Rate Decay Schedules: Cosine decay is standard; WSD (Warmup-Stable-Decay) has emerged as the modern alternative, maintaining a constant high learning rate for 90%90\% of training and decaying only during annealing, enabling continuous training runs without committing to a fixed token horizon. ④ $\mu$P in Production: Adopted by Microsoft (Cerebras-GPT, Phi-1/2) and modern foundation labs, saving millions of dollars in compute by tuning learning rates exclusively on 100M parameter models. ⑤ Interview Strategy: Explain why Standard Parametrization fails as width expands (Δh∝d\Delta h \propto d), write down the μ\muP scaling rules for hidden and output layers, and explain how it enables zero-shot hyperparameter transfer.
⚠️ Common Interview Pitfalls
  • ✕
    Attempting to transfer standard PyTorch learning rates from small models to large models without μ\muP (causes gradient explosion or divergence)
  • ✕
    Scaling depth aggressively without scaling width proportionally
  • ✕
    Locking in a fixed cosine learning rate schedule before knowing the final pre-training token budget (use WSD instead)
🎯 Interviewer Follow-up Inquiries
  • ?
    Why do attention logits in μ\muP require 1/d1/d scaling instead of standard 1/d1/\sqrt{d} scaling as width approaches infinity?
  • ?
    What is the Warmup-Stable-Decay (WSD) schedule, and why does it outperform cosine decay for continuous pre-training?
⚡
Test muscle memory on this topic via 3-Layer Flashcards
Active Recall: Mentally formulate Prompt ➔ Math Derivation ➔ Benchmark Implementation in 3 minutes.
🎯 Drill This Card Now➔
📚

Associated Knowledge Base Guides & Mindmaps

Explore the comprehensive technical article, exam cards, and global architecture tree.

← PreviousM5-017: Scaling Strategies Under Data-Constrained Regimes📋Back to BankNext →M5-019: Post-Training Scaling (RL and Test-Time Compute) vs. Pre-Training Scaling
中文速览与面试要点

解释 scaling law 对超参与架构选择的指导意义。

用小型实验拟合幂律预测大规模表现,指导 N/D 配比与超参(μP 使超参可迁移);但不能外推到新机制。

核心要点

  • 数学机理: 指导意义 有三层。 (1) 预测与规划 ——用 小规模实验 (如多个小模型、不同 N/D)拟合幂律 L=L_∞+AN^−α+BD^−β,外推预测大规模模型的损失。用途:(a) 判断'扩大规模是否值得'(预测收益);(b) 给定预算算最优 N/D 配比;(c) 比较架构(在同一实验框架下拟合各自的幂律,比较常数)。 (2) 超参迁移(μP/μTransfer) ——标准参数化下,不同宽度的最优超参(学习率、初始化、warmup)不同,故'扩大规模需重新调参'(昂贵)。 μP(Maximal Update Parameterization) 给出'随宽度一致'的初始化与 lr 缩放规则,使 窄模型上调出的超参可直接用于宽模型 (μTransfer);这把'大规模调参'变成'小模型调参 + 直接迁移',极大降低成本。 (3) 架构选择 ——在同一实验框架下,用幂律的 常数项与指数 比较架构(如'哪个架构在小规模上损失更低、且斜率更优')。 局限 ——(a) 不能预测'新能力' (scaling law 只拟合 损失 ,不拟合'某任务的表现';涌现现象说明能力可能与损失脱钩);(b) 不能跨机制外推 (幂律是'经验拟合',引入新机制如 MoE、新的注意力、新数据分布后,常数与指数会变,需重新拟合);(c) 不能预测数据受限的行为 (幂律假设数据无限);(d) 对超参/调度敏感 (Kaplan 的偏差即源于此);(e) 不能保证'损失低 → 任务好' (对齐、安全性等不由损失决定)。 实践建议 ——(a) 用幂律做 趋势判断 而非 精确预测 ;(b) 在 多个规模 上验证幂律的稳定性(若拟合不一致,说明机制变了);(c) 结合 任务指标 (而非只看损失);(d) 用 μP 迁移超参。
  • 深度剖析与工程权衡:① '预测损失 ≠ 预测能力'是核心局限 ——scaling law 拟合的是 交叉熵损失 ;但下游任务表现可能与损失脱钩(涌现、以及'损失相近但能力差异大'的情况)。故不能'用损失外推能力'。② 幂律的'验证'方法 ——应在 多个规模 上拟合,检查幂律是否成立(若不同规模区间的指数不同,说明中间发生了机制变化);这是'scaling law 可信度'的自检。③ μP 的实际价值 ——对算力有限的团队,μTransfer 是'用 1% 成本获得大模型最优超参'的关键手段;工业界已广泛采用(超参搜索在小模型上做)。④ 架构比较的正确方法 ——不能'小规模 A 好就断定大规模 A 好'(斜率可能不同);应在多个规模上比较,看'损失-规模'曲线的 位置与斜率 。⑤ 与 MoE/稀疏架构的关系 ——MoE 的 scaling law 需考虑'激活参数 vs 总参数'两个维度(不是单一 N);故标准幂律需扩展。⑥ 面试要点 ——被问'scaling law 怎么用',应给出' 预测/规划(小规模拟合外推)+ 超参迁移(μP)+ 架构比较(多规模看斜率) '三层用途与' 不能预测新能力/不能跨机制外推/损失≠能力 '三条局限;能提到'多规模验证幂律稳定性'是深度理解的标志。
  • 用途:预测损失、规划预算、选择架构
  • μP/μTransfer 让超参从窄模型迁移到宽模型
  • 局限:不能预测'新能力'、不能跨架构外推

常见陷阱

  • 用小规模损失外推'某任务的能力'
  • 只在单一规模上比较架构优劣