Optimization

Loss Landscapes, Sharpness & Flat Minima

How 2D loss slices, Hessian curvature, SAM-style neighborhood loss, and a toy 2/eta stability line expose local sensitivity during optimization.

status: publishedimportance: importantdifficulty 3/5math: undergraduateread: 16mlive demo
Editorial optimization illustration of contour loss basins, sharp and flat minima, and descent trajectories.

Concept Structure

Loss Landscapes, Sharpness & Flat Minima

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
3next concepts
2related links

Learning map

Loss Landscapes, Sharpness & Flat Minima
BeforeAdam OptimizerNow4/4 sections readyTryManipulate one control and predict the visible change.NextOverparameterization & Generalization (Double Descent)

Object flow

4/4 sections readyAsk about thisResearch room
ConceptLoss Landscapes, Sharpness & Flat MinimaOptimization
3 sources attachedLocal snapshot ready
concept:optimization/loss-landscapes

Conceptual Bridge

What should feel connected as you move through this page.

Carry inAdam Optimizer

Bring the mental model from Adam Optimizer; this page will reuse it instead of restarting from zero.

Work hereLoss Landscapes, Sharpness & Flat Minima

How 2D loss slices, Hessian curvature, SAM-style neighborhood loss, and a toy 2/eta stability line expose local sensitivity during optimization.

Carry outOverparameterization & Generalization (Double Descent)

The next edge should feel earned: use the demo prediction here before following Overparameterization & Generalization (Double Descent).

Test the linkManipulate one control and predict the visible change.Then continue to Overparameterization & Generalization (Double Descent)
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

Training is "roll downhill on a surface", but for neural nets that surface lives in a space with millions (or billions) of dimensions.

So when people show a 2D loss landscape, it is not the landscape. It is a slice: a tiny window into how loss changes along a couple of directions in parameter space.

Even so, those slices teach something real:

  • Sharp minima: a tiny weight perturbation makes loss jump. These are useful local sensitivity diagnostics, but their meaning depends on the chosen perturbation scale and parameterization.
  • Flat minima: you can wiggle weights a bit and loss barely changes. Flatter regions are often studied as generalization correlates, not as universal guarantees.

SAM makes one version of this bias explicit: optimize for low loss in a small neighborhood, not just at one point. Other optimizer tricks are often discussed through similar flatness intuitions, but they need their own sources before becoming checked claims here.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let L(w)L(w) be the training loss for parameters ww. Near a point ww, a quadratic approximation is:

L(w+ϵ)L(w)+ϵL(w)+12ϵH(w)ϵ,L(w+\epsilon) \approx L(w) + \epsilon^\top \nabla L(w) + \tfrac12\,\epsilon^\top H(w)\,\epsilon,

where H(w)=2L(w)H(w) = \nabla^2 L(w) is the Hessian (curvature).

A common proxy for "sharpness" is how much loss can increase under a small perturbation. SAM turns that local-neighborhood idea into an objective:

Δρ(w):=maxϵ2ρ(L(w+ϵ)L(w)),LSAM(w):=maxϵ2ρL(w+ϵ),minwLSAM(w),ϵ^(w)ρL(w)L(w)2.\begin{aligned} \Delta_{\rho}(w) &:= \max_{\|\epsilon\|_2 \le \rho} \big(L(w+\epsilon) - L(w)\big),\\ L_{\mathrm{SAM}}(w) &:= \max_{\|\epsilon\|_2 \le \rho} L(w+\epsilon), \qquad \min_w L_{\mathrm{SAM}}(w),\\ \hat{\epsilon}(w) &\approx \rho\,\frac{\nabla L(w)}{\|\nabla L(w)\|_2}. \end{aligned}

Here Δρ\Delta_\rho is the local loss-increase proxy. SAM optimizes the worst-case training loss in the ρ\rho-neighborhood, and in practice approximates the inner maximizer with a single step in the gradient direction before updating from the perturbed weights L(w+ϵ^(w))\nabla L(w+\hat{\epsilon}(w)).

03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

# Anisotropic quadratic: sharp along x (large curvature), flat along y (small curvature).
a, b = 20.0, 1.0  # Hessian eigenvalues
lam_max = max(a, b)

def L(w): return 0.5 * (a * w[0] ** 2 + b * w[1] ** 2)
def grad(w): return np.array([a * w[0], b * w[1]])

print("stable if eta < 2/lambda_max =", round(2.0 / lam_max, 3))

for eta in [0.02, 0.08, 0.12]:
    w = np.array([1.0, 1.0])
    ok = True
    for _ in range(60):
        w = w - eta * grad(w)
        if not np.isfinite(L(w)) or np.linalg.norm(w) > 1e6:
            ok = False; break
    print("eta =", eta, "final L =", round(L(w), 6), "status =", "ok" if ok else "diverged")
04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

This notebook page now has two focused stages:

  • Stage 1: a 2D loss slice with local Hessian curvature through a λmax\lambda_{\max} sharpness proxy, SAM's perturbation ball, and a prediction check comparing SGD and SAM endpoint sharpness in the toy.
  • Stage 2: a toy stability-line demo that asks whether a sharpness trace stays safely below the local quadratic GD line 2/η2/\eta, hovers near this toy threshold, or crosses into divergence.

The 3D surface remains a separate legacy exploration and should receive its own rollout slice later.

Live Concept Demo

Explore Loss Landscapes, Sharpness & Flat Minima

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Loss Landscapes, Sharpness & Flat Minima should make visible before reading the result.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

How 2D loss slices, Hessian curvature, SAM-style neighborhood loss, and a toy 2/eta stability line expose local sensitivity during optimization.

Prediction open01 / Intuition
Editorial optimization illustration of contour loss basins, sharp and flat minima, and descent trajectories.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Loss Landscapes, Sharpness & Flat Minima should make visible.

Visual Inquiry

Make the image answer a mathematical question

How 2D loss slices, Hessian curvature, SAM-style neighborhood loss, and a toy 2/eta stability line expose local sensitivity during optimization.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Loss Landscapes, Sharpness & Flat Minima easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

paper · 2017Visualizing the Loss Landscape of Neural NetsLi et al.

Grounds 2D loss-slice visualization and filter-normalized landscape comparisons.

Open source
paper · 2016On Large-Batch Training for Deep Learning: Generalization Gap and Sharp MinimaKeskar et al.

Grounds the sharp-vs-flat minima discussion and its connection to generalization.

Open source
paper · 2020Sharpness-Aware Minimization for Efficiently Improving GeneralizationForet et al.

Grounds SAM-style neighborhood loss as an optimization objective that penalizes local sharpness.

Open source

Claim Review

How 2D loss slices, Hessian curvature, SAM-style neighborhood loss, and a toy 2/eta stability line expose local sensitivity during optimization.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources3 references

li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam

Witnesses4 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Substantively reviewedLoss-landscape visualizations are 1D/2D diagnostic slices through high-dimensional parameter space, not the full neural-network surface; sharpness/flatness depend on perturbation scale and network symmetries, and SAM minimizes worst-case training loss in a perturbation neighborhood.Claim metadata: source checked

Li supports 1D/2D slices and filter-wise normalization caveats. Keskar supports sharp/flat minima as perturbation-sensitivity diagnostics tied to generalization, while using an imperfect epsilon-scale-dependent metric. Foret supports SAM's neighborhood min-max objective and first-order perturbation approximation; local math anchors combine the quadratic, Delta_rho, SAM objective, and epsilon approximation.

Sources: Visualizing the Loss Landscape of Neural Nets, On Large-Batch Training for Deep Learning: Generalization Gap and Sharp Minima, Sharpness-Aware Minimization for Efficiently Improving GeneralizationDoes not source edge-of-stability theory, 2/eta stability code, Stage 2 EdgeOfStabilityViz wording, real-network Hessian spectra beyond cited context, universal flat-minima guarantees, parameterization-invariant sharpness, or 3D surface; #interactive-demo means Stage 1 only.A bounded review summary is present; still check caveats and exact source scope.

Li supports low-dimensional 1D/2D slices and filter-normalized comparisons. Keskar supports sharp/flat minima as perturbation-sensitivity diagnostics tied to generalization but with an imperfect epsilon-dependent metric. Foret supports SAM's worst-case neighborhood objective and first-order perturbation approximation. Reviewed scope excludes edge-of-stability, the 2/eta code, Stage 2, real-network Hessian spectra beyond cited context, universal flat-minima guarantees, and parameterization-invariant sharpness.

Reviewer: codex+oracle; reviewed 2026-05-07

Practice Loop

Try the idea before it explains itself

How 2D loss slices, Hessian curvature, SAM-style neighborhood loss, and a toy 2/eta stability line expose local sensitivity during optimization.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Loss Landscapes, Sharpness & Flat Minima.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptLoss Landscapes, Sharpness & Flat MinimaOptimization

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

Loss Landscapes, Sharpness & Flat Minima

Anchored question

What is the smallest example that makes Loss Landscapes, Sharpness & Flat Minima click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:optimization/loss-landscapes.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Loss Landscapes, Sharpness & Flat Minima Object key: concept:optimization/loss-landscapes Context: Optimization Anchor id: concept/concept-notebook/optimization/loss-landscapes Open question: What is the smallest example that makes Loss Landscapes, Sharpness & Flat Minima click without losing the math? Evidence to inspect: - Source ids to inspect: li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/optimization/loss-landscapes concept:optimization/loss-landscapes