BurnyCoder's picture
Publish the verified TinyStories and Pythia comparisons with the hybrid controls
fa84ca1 verified
|
Raw History Blame
26.7 kB

Third derivatives in language-model training

Does a language model predict unseen tokens better when training penalizes rapid changes in loss curvature? We test this on a TinyStories decoder trained from scratch and on Pythia-410M attention adapters. A second TinyStories experiment compares a fixed late start with a schedule that increases the penalty as measured curvature falls. Study design

The research background includes flat minima, Hessian measurements and third derivatives in language modeling and other fields. Original flat-minima paper · Hessian regularization in GPT-2 · Hessians in image classification · Third derivatives in language-model training dynamics · Derivative penalties in splines

Results at a glance

Lower next-token loss (NLL) means a model assigned more probability to the words that actually came next. Training speed counts target tokens per second.

Model and split Matched evidence Third-order NLL vs AdamW Third-order NLL vs trace Speed vs AdamW
TinyStories pretraining · dev one development pilot seed 0.000045 lower 0.000338 lower 65.7% slower
Pythia-410M adapters · dev one development pilot seed 0.000300 higher 0.000273 higher 88.6% slower

Adaptive vs fixed-ramp hybrid · 2/8 paired seeds. Adaptive development NLL was 0.000174 lower. It retained 0.0554 less directional width after the switch.

Both primary test decisions are pending. Each stage requires eight paired test seeds and superiority over both baselines under Holm correction.

Side-by-side scores, accuracy, speed, memory and width · Live explorer · Paired tests and intervals

Sepp Hochreiter and Jürgen Schmidhuber proposed that among models that fit the training data equally well, those in flatter minima may generalize better to unseen data. In a flat minimum, many nearby weight settings still fit. If some weights can be rounded more coarsely without spoiling the fit, a good predictor can take fewer bits to describe under a fixed encoding. Their minimum-description-length argument links that shorter description to a lower risk of overfitting. Hochreiter and Schmidhuber, Flat Minima (1997), §1

Why did earlier papers use the Hessian? At a smooth minimum the gradient is zero, whether the valley is sharp or flat. The Hessian gives a quadratic approximation to how much training loss rises when the weights move. For small steps of equal size in uniformly random directions, the predicted average rise is proportional to the Hessian trace, the sum of second derivatives along the weight coordinates. The researchers penalized the trace to favor fits that tolerate small weight changes and tested whether those fits generalize better. Liu, Yu and Lin, §§3.2–3.3 · Zhang, Li and Ju, equation 4

Sankar et al. observed that layerwise traces fell during image-classifier training and tried penalizing them directly. Liu, Yu and Lin drew on a generalization bound for linear classifiers to motivate a stochastic trace penalty and reported WikiText-2 experiments with LSTMs and GRUs. Zhang, Li and Ju paired opposite weight perturbations so the first-order loss changes would cancel, giving them a way to target curvature during GPT-2 fine-tuning for question answering. Sankar et al., Figure 5 and Table 1 · Liu, Yu and Lin, §5.2 · Zhang, Li and Ju, Table 5

Why third derivatives? Two minima can have the same small curvature at the bottom, yet one can steepen much sooner. The third derivatives of next-token loss measure how its Hessian changes as the weights move. The training penalty estimates their sum of squares, so rapid changes of either sign carry a cost. If curvature starts small and changes slowly throughout a neighborhood, the weights can move farther while loss stays low. Worked examples and width bound · Taylor remainder, equation 22

Why add the third-derivative penalty late? Even a steep valley can have constant curvature. The registered TinyStories follow-up first trains with the Hessian-trace penalty to favor low average curvature. Its fixed-ramp arm keeps the trace active and gradually adds the third-derivative penalty after the midpoint. If curvature changes faster toward the edge of a flat region, the penalty can increase outward and oppose that movement. Delaying it also avoids early fourth-derivative computations. If the schedule preserves a wider region, its final weights should tolerate larger perturbations than the trace controls at the same allowed increase in unregularized loss. Timing controls and width measurement · Measured widths

Should the penalty get stronger as curvature falls? The TinyStories follow-up keeps the trace active and turns up the weight on the squared third derivatives once training loss is low and recent Hessian measurements are small. It retains the highest weight reached, up to a cap. Eight paired seeds compare this rule with a fixed late ramp, another seed’s schedule, trace alone, stronger trace and an always-on hybrid. The endpoints are directional width on fixed training windows and development next-token loss. Direct division can act in the opposite direction. For $L(w)=w^4$, the squared ratio $(L'''/L'')^2=4/w^2$ grows without bound as weights approach the flat bottom. Derivation · Hybrid preregistration and run matrix

Can the penalty favor a wider minimum?

A minimum is wide if the weights can move a long way before the loss rises by a chosen amount. Basin width, Definition 1

The penalty can help weights stay near a flat bottom. For $L(w)=w^4$, nudging the weight to either side makes the penalty rise, so a small descent step pulls it back. A steep quadratic such as $L(w)=100w^2$ has constant curvature and receives zero third-derivative penalty everywhere. Worked examples

In the language models, an active update measures curvature change for the next-token cross-entropy of two text windows, with respect to all decoder weights for TinyStories or only the adapter weights for Pythia. Differentiating this penalty gives AdamW a fourth-derivative contribution. The primary comparison tests prediction on held-out tokens at equal training-token counts. The hybrid follow-up measures changes in directional width in fixed weight coordinates, since rescaling weights can change measured sharpness while preserving predictions. Training update · Primary preregistration · Hybrid preregistration · Dinh et al.

One-weight loss and penalty curves. At the asymmetric minimum the trace pushes left and the third-derivative penalty pushes right. In the quartic both pull displaced weights back. In the steep quadratic both penalty curves are constant.

Analytic examples. The circles mark the ordinary loss minima. Arrows show downhill directions for the two penalties. Each panel has its own vertical scale.

Flat minima, Hessians and third derivatives in earlier work

Setting What the researchers used the derivatives for Original papers and projects
Origin of flat-minimum search Hochreiter and Schmidhuber searched for connected regions of weights where training error changes little. Their flatness penalty depends on the sensitivity of network outputs to the weights. Differentiating that penalty uses second derivatives of the outputs. Original NeurIPS paper, 1994 · Flat Minima (1997), equations 1–2
Hessian penalties in language models Zhang, Li and Ju approximate a Hessian-trace penalty with symmetric weight perturbations when fine-tuning GPT-2 on CommonsenseQA and StrategyQA. Liu, Yu and Lin propose a signed trace objective and report WikiText-2 LSTM and GRU experiments. GPT-2 experiments, Table 5 · Noise stability optimization code · Recurrent LM penalty, §5.2
Other uses of Hessians in LLMs Sophia uses stochastic curvature estimates to precondition GPT training updates. Liu et al. measure Hessian trace and study the downstream behavior of pretrained language models. Sophia paper · Sophia code · Language-model flatness study
Hessians outside language modeling Layerwise Hessian-trace penalties have been tested in image classification. Reparameterization studies explain why a curvature measurement alone cannot establish predictive generalization. Sankar et al. · Dinh et al.
Third derivatives in language models Yang et al. approximate third derivatives of the training loss with respect to weights to predict what happens when training batches are reordered. McGee et al. fit a cubic along a fine-tuning update to select a step size. Zhang and Wang test cubic corrections along hidden-activation interventions in a frozen model and report failures for large perturbations. FUT++, §5.1 and Appendix A.1 · Step selection, Appendix C.1.1 · Activation patching, §4 and supplement
Third derivatives outside LLMs Wolinski projects third derivatives of the weight-space loss to regularize a local optimization model. Lellmann et al. study third spatial derivatives of terrain surfaces. Duchon gives the general squared-derivative roughness formulation. Projected parameter derivatives · Third-order terrain reconstruction · Spline roughness
Third derivatives in image classifiers Grad-CAM++ uses diagonal third derivatives of a class score with respect to convolutional feature activations to locate image regions that contribute to a prediction. Chattopadhyay et al., equation 10 · Authors’ implementation

Two independent random sign vectors estimate the squared Frobenius norm of the minibatch third derivative, including mixed partials between different weights. Estimator derivation · Duchon · Bujanović and Kressner

The protocol and run matrix were published before model execution. The scores, comparisons and continuations below are regenerated from each run’s raw records. Preregistration · Run matrix · Literature · State of the art · Progress

A same-probe check on pretrained Pythia found that single-precision arithmetic materially changed the third-order training gradient. The first adapter pilot is archived as a numerical diagnostic. The corrected adapter arms evaluate derivatives in double precision while ordinary training and prediction use the GPU. Pre-test precision amendment · Full-model numerical checks

Side-by-side comparisons

↓ means lower is preferred. ↑ means higher is preferred. Bold highlights the best observed value when methods differ at the displayed precision. A tie means the paired difference rounds to zero. NLL is negative log-likelihood in nats per target. Accuracy differences use percentage points (pp).

TinyStories pretraining

Full development split · one development pilot seed · 2,097,152 training targets per run. Method columns show medians over the same seeds. The two right columns give the median paired change for third order against each baseline. The pilot also selected the derivative strengths. Strength selection · Experiment ledger

Metric AdamW Hessian trace Third order vs AdamW vs Hessian trace
Development NLL ↓ 3.876976 3.877269 3.876931 0.000045 lower 0.000338 lower
Dev top-1 accuracy ↑ 32.337% 32.329% 32.326% 0.011 pp lower 0.003 pp lower
Equal-time probe NLL ↓ 3.82905 4.04765 4.95277 1.12372 higher 0.90512 higher
Training speed ↑ (targets/s) 123,871 73,185 42,481 65.7% slower 42.0% slower
Peak GPU allocation ↓ (MiB) 608.2 608.2 608.2 Tie Tie

These early TinyStories pilots share the initialization seed and identical first-update token count, loss, accuracy and gradient norm. Initial weight digests were first recorded in later runs. First-update records

The common training-time cutoff had a median of 16.9 seconds. The furthest checkpoint used for this row was 2.3 seconds before its cutoff.

Awaiting paired test results (0 of 8 full-horizon training triplets).

Pythia-410M adapters

Full development split · one development pilot seed · 65,536 training targets per run. Method columns show medians over the same seeds. The two right columns give the median paired change for third order against each baseline. The pilot also selected the derivative strengths. Strength selection · Experiment ledger

Metric AdamW Hessian trace Third order vs AdamW vs Hessian trace
Development NLL ↓ 3.113948 3.113974 3.114247 0.000300 higher 0.000273 higher
Dev top-1 accuracy ↑ 41.321% 41.321% 41.315% 0.006 pp lower 0.006 pp lower
Training speed ↑ (targets/s) 1,659 435 189 88.6% slower 56.5% slower
Peak GPU allocation ↓ (MiB) 2,346.3 2,346.3 2,346.3 Tie Tie

An equal-time NLL comparison is pending because at least one arm lacks a recorded development checkpoint at or before the shared cutoff.

Observed host-process memory high-water marks were AdamW 3.78 GiB, Hessian trace 10.28 GiB, Third order 13.09 GiB. This measure includes earlier work in each interpreter.

Awaiting paired test results (0 of 8 full-horizon training triplets).

The equal-time row uses the last available fixed-window development score at or before the fastest run’s finish time in each seed. Full-split NLL uses every development target. Training speed includes regularizer probes. Adapter derivatives use CPU float64 with one GPU reserved. Timing definitions and checkpoint lags

TinyStories hybrid schedules

Adaptive vs fixed ramp · 2/8 paired seeds · 16,777,216 targets per run. Both arms resume the same trace-trained checkpoint. Width change is final width minus width at the switch. A larger change means more width retained at the fixed loss tolerance.

Metric Adaptive Fixed ramp vs Fixed ramp
Development NLL ↓ 2.546107 2.546281 0.000174 lower
Dev top-1 accuracy ↑ 46.205% 46.208% 0.002 pp lower
Width change after switch ↑ -2.0865 -2.0311 0.0554 less retained
Training speed ↑ (targets/s) 40,983 40,328 1.5% faster
Peak GPU allocation ↓ (MiB) 617.3 617.3 Tie

The remaining controls are paired independently. Each row uses only seeds that finished both arms. The always-on arm has its own measured width at the switch.

Adaptive versus Paired seeds Adaptive NLL Adaptive width change Adaptive speed
Cross-seed replay 0/8 Pending — —
Hessian trace 2/8 0.000002 higher 0.0015 more retained 35.0% slower
Stronger trace 2/8 0.000092 lower 0.0178 less retained 35.5% slower
Always-on hybrid 2/8 0.000161 higher 0.0111 less retained 48.0% faster

Registered width decision · Awaiting eight paired width measurements. Width probes use fixed training windows. Every width, training-fit flag, replay and paired difference

Squared-Hessian, scrambled-gradient, combined and untrained controls

TinyStories pretraining · Pilot seed, 2,097,152 training targets.

Metric Third order Squared Hessian Scrambled signs Trace + third
Development NLL ↓ 3.876931 3.878680 3.877253 3.877172
Dev top-1 accuracy ↑ 32.326% 32.299% 32.331% 32.317%
Training speed ↑ (targets/s) 42,481 83,790 50,914 41,030
Peak GPU allocation ↓ (MiB) 608.2 608.2 608.6 619.3

Pythia-410M adapters · Secondary pilot comparisons are pending.

Untrained references · zero training targets

Stage Initial NLL ↓ Unigram NLL ↓ Initial accuracy ↑ Unigram accuracy ↑
TinyStories pretraining 8.343680 6.003555 0.312% 7.151%
Pythia-410M adapters 3.251674 7.330611 39.911% 6.023%

Same-prompt continuations

Each panel shows the first saved prompt and full continuations from the lowest matched seed. The method names link to the raw generations.

TinyStories pretraining · same prompt, seed 0

Prompt Once upon a time, there was a clever little dog named Max. Max loved

AdamW Hessian trace Third order
to play on the cat. to play on the cat. to play on the cat.
Pythia-410M adapters · same prompt, seed 0

Prompt One of the central objectives of contemporary neuroimaging research is to
create predictive models

AdamW Hessian trace Third order
that will accurately predict the behavior of
patient-specific neurological disorders such as epilepsy. In this paper, we
present a novel dataset of EEG data recorded from children with focal
subcortical epilepsy
that will be used to assess the cognitive
performance of neurological disorders. We will focus on three major areas:
(1) the nervous system as a whole, (2) the brain regions that
that will accurately predict the behavior of
patient-specific neurological disorders such as epilepsy. In this paper, we
present a novel dataset of EEG data recorded from children with focal
subcortical epilepsy
TinyStories hybrid schedules · same prompt, seed 21

Prompt Once upon a time, there was a clever little dog named Max. Max loved

Adaptive Fixed ramp
to play on the swings and slide. His owner liked to run and play outside. Lily was happy to see his dog and play.

One day, Max found a big hole in his house
to play on the swings and slide. His owner liked to run and play outside. Lily was happy to see his dog and play.

One day, Max found a big hole in his mail

Explore the results · Hugging Face explorer · Hugging Face collection · Paper · Run ledger

Recorded 36 runs, including 34 with a completed summary.

TinyStories hybrid follow-up: 10 of 48 full runs and 2 of 8 shared checkpoints complete. Geometric decision: awaiting eight paired width measurements. Width measurements, scores and controls

Full score table, strength search and per-seed test differences

Directional width by TinyStories arm and seed

Parameter-space computation graph

Development NLL

Full generations by method

TinyStories · Initial checkpoint · Unigram · Curvature-dependent hybrid · Always-on hybrid · Fixed late hybrid · Stronger trace · Hessian trace · Ordinary AdamW · Trace + third derivative · Squared Hessian norm · Randomized gradient signs · Third derivative

Research abstracts · Initial checkpoint · Unigram · Ordinary AdamW · Third derivative · Hessian trace

Reproduce the study

Use Python 3.12, uv, and an NVIDIA GPU. Install with uv sync --locked and check the implementation with uv run --locked thirdloss verify. Run the original experiments and the six-arm follow-up with uv run --locked thirdloss study --with-hybrid. Once the TinyStories calibration and pilot selection exist, uv run --locked thirdloss hybrid runs the follow-up on its own. In another terminal run uv run thirdloss dashboard --port 18765 for live accuracy, loss and curvature. Regenerate the paper, plots and tables with uv run thirdloss report. Setup, checkpoints and CLI · Document splits · Model collection

The pipeline pins the source texts, splits by document, learns the stories tokenizer using training documents, and freezes the evaluation definition. Identical initializations and document orders pair the competing objectives. The smaller model trains all weights. The pretrained model trains only attention adapters. Examine both improvement and deterioration across seeds and both computational budgets. TinyStories · Pythia · Common Pile · LoRA

Milestones

  • Publish the protocol, references and analysis decisions.
  • Verify the scalar objective and its training gradient on analytical functions and a small Transformer.
  • Train the pilot, publish throughput and establish feasibility on the local GPU.
  • Complete controls, development selection, paired confirmations and a reproducible report.
  • Test whether adding the third-derivative penalty late in Hessian-trace training helps the model stay in a wider low-loss region. Exploratory plan and rationale
  • Compare a capped third-derivative penalty weight that rises as measured curvature falls with the fixed-token schedule. Test whether it preserves directional width at comparable training fit and whether it improves held-out token prediction. Curvature-dependent schedule and controls