Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Curvature-aware steps with a safety limit
Newton’s method divides the gradient by the curvature: it takes big steps where the loss is flat and small steps where it is steep. Computing the full curvature of a large network is impossible, but its diagonal can be estimated cheaply now and then. Sophia divides its momentum by that estimate. Because estimates can be wrong (even negative), it caps every coordinate’s step at a fixed size.
Pre-training large language models costs millions of dollars in compute, so an optimiser that halves the number of steps is valuable. Sophia claimed that on GPT-2-scale models. Later independent benchmarks found smaller or no gains once Adam was carefully tuned, which is a reminder to test such claims on your own workload.
- 1. Sophia divides the momentum by…
- 2. Clipping in Sophia guards against…
- 3. Sophia's curvature estimate is refreshed…
Level 1: Beginner
★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.By hand
- Momentum: m ← β₁m + (1 − β₁)g (β₁ = 0.96).
- Curvature: every k steps (k = 10), h ← β₂h + (1 − β₂)ĥ (β₂ = 0.99), with ĥ an estimate of diag(H).
- Update: w ← w − η·clip(m/max(γh, ε), −1, 1), with γ around 0.01–0.1.
- Hutchinson estimate: ĥ = u ⊙ (Hu) for a random ±1 vector u; it needs one Hessian-vector product. Example: H = [[2, 1], [1, 3]], u = (1, −1): Hu = (1, −2), so ĥ = (1, 2), while the true diagonal is (2, 3). Averaging many samples converges to it.
- Newton-like: on a 1-D quadratic, m ≈ hx, so the unclipped step is η·x/γ. With η = γ it is exactly Newton’s step.
- Clipped steps: if h is tiny or negative, the ratio is huge, so the step is ±η, as in Lion.
- 1. Hutchinson's estimate uses…
- 2. With η = γ and no clipping, Sophia on a quadratic takes…
- 3. For negative curvature estimates, Sophia's step is…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.Sophia in code
Exercise 1.
- Averaging 20 000 Hutchinson samples recovered the diagonal of a random 6 × 6 symmetric Hessian to within sampling error.
- One sample’s standard deviation for entry i matched √(Σⱼ≠ᵢ Hᵢⱼ²), for example 1.129 measured against 1.122 predicted.
- For a diagonal Hessian a single sample is exact.
Practice.
- Hessian-vector products cost about one extra backward pass, using automatic differentiation or finite differences of gradients. Refreshing every 10 steps keeps the overhead small (the paper reports about 5% for Sophia-G, which also uses part of the batch for the estimate).
- The paper’s second variant, Sophia-G, uses a Gauss–Newton–Bartlett estimate built from sampled labels; it is always non-negative.
- Tune η and γ together. Watch the fraction of clipped coordinates: if nearly all are clipped, Sophia is effectively a sign-of-momentum method.
# github.com/Liuhong99/Sophia : SophiaG(params, lr=2e-4, betas=(0.965, 0.99), rho=0.01, weight_decay=0.1)- 1. Hutchinson noise for entry i comes from…
- 2. Refreshing the estimate every 10 steps makes its cost…
- 3. Sophia-G's estimate is always…
Level 3: Advanced
★★★★☆ Advanced⏱ 30 minGraduate level, with full derivations and proofs.Theory
Unbiasedness. For Rademacher u, E[uᵢuⱼ] = δᵢⱼ, so E[uᵢ(Hu)ᵢ] = Σⱼ HᵢⱼE[uᵢuⱼ] = Hᵢᵢ. The variance of one sample is Σⱼ≠ᵢ Hᵢⱼ², so the estimate is noisy when the Hessian is far from diagonal.
Why divide by curvature. In a direction with curvature h, a step of size g/h reaches the minimum of the local quadratic. Adam divides by √(E[g²]), which scales with the gradient, not the curvature. Liu et al. argue this makes Adam’s steps poorly sized when curvature varies strongly across directions, as in language models.
Why clip. Non-convex losses have negative and near-zero curvature, where g/h is huge or points uphill. Clipping caps each coordinate’s move at η, which bounds the step even when the estimate is bad. Liu et al. prove a convergence rate that does not depend on the condition number for a class of convex functions.
In exercise 2 75–97% of coordinates were clipped. Sophia then behaves like Lion with a different momentum, and its curvature information is mostly unused.
- 1. E[uᵢuⱼ] for Rademacher u is…
- 2. Adam's denominator scales with…
- 3. When almost all coordinates are clipped, Sophia behaves like…
Level 4: Expert
★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.Sophia on a small network
History.
- M. Hutchinson (1989) introduced the randomised trace estimator.
- Z. Yao et al. (2021) used Hutchinson’s diagonal in AdaHessian.
- H. Liu, Z. Li, D. Hall, P. Liang and T. Ma (2023) introduced Sophia and reported 2× fewer steps than Adam on GPT-2-scale pre-training.
- Later benchmarks (for example Kaddour et al., 2023) found much smaller gains for Sophia and similar methods once baselines were tuned.
Exercise 2. The 2–32–32–3 tanh network on spirals: mini-batches of 32, 400 steps, mean full-data loss over the last 50 steps, two seeds. Sophia uses a finite-difference Hessian-vector product every 10 steps.
| η | Adam | Sophia γ = 0.01 | Sophia γ = 0.1 |
|---|---|---|---|
| 0.001 | 0.457 | 0.126 | 0.127 |
| 0.003 | 0.076 | 0.020 | 0.011 |
| 0.01 | 0.013 | 0.051 | 0.023 |
| 0.03 | 0.0021 | 0.312 | 0.219 |
| 0.1 | 0.0006 | 3.42 | 2.91 |
- Tuned Adam reached a loss about 20× lower than tuned Sophia (0.0006 against 0.011).
- Sophia clipped most coordinates: 97% at γ = 0.01 and 75% at γ = 0.1. The curvature estimates on this small, noisy problem were often tiny or negative, so the clipping safeguard took over.
- Lesson: this does not test Sophia’s claim, which concerns language-model pre-training at scale. But it shows how to diagnose it: if the clip fraction is near 1, Sophia is not using curvature.
Sophia in AI, robotics and aerospace
- Language-model pre-training is where Sophia was proposed and evaluated.
- Hessian-vector products (the same tool) are used for sensitivity analysis and uncertainty estimates in safety-critical models.
- When adopting a new optimiser, measure on your own workload with tuned baselines, as exercise 2 does.
References
- H. Liu, Z. Li, D. Hall, P. Liang, T. Ma (2023). “Sophia: a scalable stochastic second-order optimizer for language model pre-training.” arXiv:2305.14342 (ICLR 2024).
- M. F. Hutchinson (1989). “A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines.” Communications in Statistics – Simulation and Computation 18(3).
- Z. Yao, A. Gholami, S. Shen, M. Mustafa, K. Keutzer, M. Mahoney (2021). “AdaHessian: an adaptive second order optimizer for machine learning.” Proc. AAAI.
- J. Kaddour, O. Key, P. Nawrot, P. Minervini, M. Kusner (2023). “No train no gain: revisiting efficient training algorithms for transformer-based language models.” Advances in NeurIPS.