Concept notebookChecking saved investigationReading browser-local route memory before showing a continuation.

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.

published · difficulty 3/5 · 16 min read

01

01

Intuition

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

PredictName the object in plain language, then predict what should change.Leave with one reusable mental picture before notation appears.

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.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

02

02

Math

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

InspectTrack the same object through the notation and check each symbol.Leave with the invariant the equations preserve.

Let L(w)L(w)L(w) be the training loss for parameters www. Near a point www, 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,L(w+ϵ)L(w)+ϵL(w)+21ϵH(w)ϵ,

where H(w)=2L(w)H(w) = \nabla^2 L(w)H(w)=2L(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}Δρ(w)LSAM(w)ϵ^(w):=ϵ2ρmax(L(w+ϵ)L(w)),:=ϵ2ρmaxL(w+ϵ),wminLSAM(w),ρ∥∇L(w)2L(w).

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))L(w+ϵ^(w)).

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

03

03

Code

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

TraceMatch variables to symbols before reading the implementation.Leave with a runnable witness for the math.
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")
Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

04

04

Interactive Demo

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

ManipulateChange one control and predict the visible response before reveal.Leave with the observed invariant or a repaired model.

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 inquiry checkpoint

Manipulate one control and predict the visible change.

01Choose lensTrace a quantity
02ObserveDemo state pending
03GroundName the equation, invariant, or control that explains it.
04CarryNext: Overparameterization & Generalization (Double Descent)

Choose what to inspect in Loss Landscapes, Sharpness & Flat Minima. This shared fallback is an observation guide, not evidence of learning.

Loading interactive demo...

This notebook page now has two focused stages:

  • Stage 1: a 2D loss slice with local Hessian curvature through a λmax\lambda_{\max}λ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/\eta2/η, 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.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

4/4 sections ready

Concept: Loss Landscapes, Sharpness & Flat Minima

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

BeforeAdam OptimizerNow4/4 sections readyTryManipulate one control and predict the visible change.NextOverparameterization & Generalization (Double Descent)
Object contextOptimization
ConceptLearner lens

Loss Landscapes, Sharpness & Flat Minima

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

Mode questionCan I say the mechanism back in one sentence before I reveal anything?

Start with the prediction checkpoint, then compare the reveal to the mental model.

Take this move

Study modes

Keep the object fixed; change the lens.

Route back through the notebook

Carry the same object through intuition, math, code, and demo.

4/4 sections ready
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).

After The First Pass

Turn the concept into an inspected object.

The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.
ConceptLoss Landscapes, Sharpness & Flat MinimaOptimization

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.

Demo notes 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 readyDemo notes 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.

Object - ConceptLoss Landscapes, Sharpness & Flat MinimaQuestion

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

concept:optimization/loss-landscapes
Boundary

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

Check

Open the closest source note before trusting the local explanation.

Evidence

3 selected-object sources shown first; 3 references total.

Next move

Audit the claim boundary, then ask from the same selected object.

selected object source · paper · 2017Visualizing the Loss Landscape of Neural NetsLi et al.
Located CF editorial boundary

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

Used here as

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...

Caveat

Does 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, pa...

Open source
selected object source · paper · 2016On Large-Batch Training for Deep Learning: Generalization Gap and Sharp MinimaKeskar et al.
Located CF editorial boundary

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

Used here as

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...

Caveat

Does 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, pa...

Open source
selected object source · paper · 2020Sharpness-Aware Minimization for Efficiently Improving GeneralizationForet et al.
Located CF editorial boundary

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

Used here as

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...

Caveat

Does 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, pa...

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.

Object - ConceptLoss Landscapes, Sharpness & Flat MinimaQuestion

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

concept:optimization/loss-landscapes
Boundary

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

Check

Treat every claim as provisional until source support and a local witness agree.

Evidence

1 structured claim check on this concept.

Next move

Run the prediction or practice transfer before asking for a grounded review.

1 CF editorial source-scope review recorded

Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 3 references and 3 local witnesses are available for inspection.

Loss-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.
Used here as

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-depend...

Local witness
Equation 1
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,
Equation 2
Δρ(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}
Caveat

Does 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-invar...

Review stateCF editorial source-scope reviewClaim metadata: source checkedPublisher-side editorial review only; not independent replication. 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 notebook

Use the idea, then test it somewhere new

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

AttemptNo learning claim inferred
Object - ConceptLoss Landscapes, Sharpness & Flat MinimaQuestion

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

concept:optimization/loss-landscapes
Boundary

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

Check

Use one state from Loss Landscapes, Sharpness & Flat Minima to explain what changes, why it changes, and which assumption the explanation needs.

Evidence

No learner move yet; no learning state is inferred.

Next move

Write first, use only the help you need, then try a new case without it.

Explain

Use one state from Loss Landscapes, Sharpness & Flat Minima to explain what changes, why it changes, and which assumption the explanation needs.

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.

Grounded object roomClose
Selected object routeAsk from this object; carry one invariant back.sources: li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam
  1. ObjectConceptLoss Landscapes, Sharpness & Flat Minima
  2. PredictBefore revealLoss Landscapes, Sharpness & Flat Minima prediction
  3. WitnessCompare codeLoss Landscapes, Sharpness & Flat Minima code witness 1
  4. RoomAsk groundedChecking local snapshot
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?

Source boundaryInspect source ids: li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-samStable content-object key attached
Role lenses for this object

These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.

Learner evidence requestAsk what would make "Loss Landscapes, Sharpness & Flat Minima" feel predictable rather than familiar.
Assumption

Source ids li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam must support the exact object, not just the surrounding topic.

Source-checking summary

Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.

Proposed experiment

Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.

Next action

The learner can state the mechanism in their own words

Evidence4 checks
PredictionChecking carried observation
ActionReady for one action
AILearner handoff ready
Open source object
01PredictionChecking browser-local route memory
02EvidenceChecking for a carried observation
03BoundaryInspect source ids: li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam
04Next moveSave one next action
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
Object-attached 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 Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Loss Landscapes, Sharpness & Flat Minima" feel predictable rather than familiar." | assumption: Source ids li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. 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. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Loss Landscapes, Sharpness & Flat Minima" feel predictable rather than familiar. - Assumption to keep visible: Source ids li-2017-loss-landscape-visualization, keskar-2016-sharp-minima, foret-2020-sam must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words

concept/concept-notebook/optimization/loss-landscapes concept:optimization/loss-landscapes