Skip to content

Add YAMLs for Adam WikiText SOURCE + EK-FAC replications - #369

Merged
luciaquirke merged 11 commits into
source-damp-optionsfrom
source-wikitext-replication
Jul 31, 2026
Merged

Add YAMLs for Adam WikiText SOURCE + EK-FAC replications#369
luciaquirke merged 11 commits into
source-damp-optionsfrom
source-wikitext-replication

Conversation

@luciaquirke

@luciaquirke luciaquirke commented Jul 31, 2026

Copy link
Copy Markdown
Collaborator

For EK-FAC, replication refers to kronfluence's masks.pt (100 x 4656 alpha=0.5 keep-masks) and losses.pt
(100 x 481 five-seed-averaged subset losses). We replicate the relevant run with --train_mode. For SOURCE the results come from the paper, which doesn't specify an exact number but it looks right from the figure sketch.

method this branch reference
EK-FAC IF 0.4451 0.44 (kronfluence reported)
SOURCE (AdamW, L=3) 0.4506 Fig. 6: slightly >= IF

Configs

examples/replication/:

  • wikitext_gpt2_train.yaml: the paper's App. B.1 model training recipe
  • wikitext_gpt2_ekfac.yaml: EK-FAC influence functions at the final checkpoint.
  • wikitext_gpt2_source.yaml: SOURCE, L=3 segments over C=6 checkpoints.
    experiments/wikitext_replication/run_chain.py: runs export -> IF -> SOURCE
    -> LDS.

Code changes

Trainer. add save_mode: interval for SOURCE-style runs that want a few evenly spaced checkpoints, and per-snapshot optimizer.pt so the AdamW SOURCE variant can read the second moments at each checkpoint.

Eq-43 hybrid. The paper's App. D says to "use the diagonal Hessian approximation for computing the matrix exponential in Equation 39 and Equation 43. Note that we still use the EK-FAC factors to compute H^-1 g in Equation 43." adam_segment_hybrid implements exactly that: the elementwise 1 - exp(-lr*K*sigma) mask on the diagonal, then the standard EK-FAC inverse, rather than approximating the whole segment operator diagonally.

Fisher normalization. The segment eigenvalues are now means rather than sums, which matters for SOURCE where eigenfunctions are not scale-invariant.

Fixes.

  • load_training_config never read a real run directory: save_run_config wraps the step list in a {steps, metadata} document, and the loader only handled a bare list. Its test hand-rolled the shape it expected instead of
    calling the writer, so this went unnoticed.
  • The end-of-training snapshot is now restricted to save_mode: interval; under sqrt it broke MAGIC's backward replay.
  • skip_metagradient was accepted but not honoured.

New. lds_from_precomputed_subsets scores attribution output against a published retrain bank.

Segment eigenvalues were unnormalized sums over (documents x checkpoints).
EK-FAC is unaffected -- every inversion is homogeneous of degree -1 in lambda
because damping is relative to mean(lambda) -- but SOURCE's eigenfunctions are
not scale-invariant, and sigma enters exp(-lr*K*sigma). Eq. 1 of Bae et al.
2024 defines the empirical risk as a mean over data points, so
fisher_normalization defaults to per-document; token units put the mask
argument in its dead-linear range.

Also makes precompute_checkpoints resumable rather than overwrite-only, and
lets resolve() fall back when a checkpoint's sibling config.yaml turns out to
belong to an attribution run.
…C trainer

(cherry picked from commit 16c29730ff6fdadd1c61ea72dc9dda43e6a85274)
The other save modes' backward replay indexes the data stream by checkpoint,
so an extra trailing snapshot runs it past the end (DataStream index out of
range in test_fsdp_ddp_scores_match).
The flag only toggled allow_compile; the backward still ran (and crashed on
interval-mode end-of-training snapshots). Port the dummy-zero-scores skip
path so bank-only builds go straight to validation.

(cherry picked from commit 13b631d3b030be312a881ceff6c31475cbceb4b5)
Companion to the cherry-picked gate: defines the MagicConfig field and the
do_metagradient condition it reads.
Bae et al. 2024 App. D: 'use the diagonal Hessian approximation for computing
the matrix exponential in Equation 39 and Equation 43. Note that we still use
the EK-FAC factors to compute H^-1 g in Equation 43.'

Evaluating the eigenfunction wholly on the diagonal drops that second half.
With adam_segment_hybrid the diagonal supplies only the exponential mask
(f_one_minus_exp) and a chained EK-FAC inverse supplies 1/x, applied to the
query as the adjoint H^-1 @ M_mask @ q.
Paper recipe from Bae et al. 2024 App. B.1 (AdamW, lr 3e-5, wd 1e-2, batch 8,
seq 512, 6 checkpoints) with train_mode enabled so GPT-2's 0.1 dropout is
active, matching kronfluence's train.py. SOURCE uses the App. C preconditioned
variant with the App. D Eq-43 hybrid, L=3, per-document Fisher units.
Scoring side of a published retrain bank (kronfluence ships masks.pt /
losses.pt for its WikiText-2 experiment): sum each subset's member scores,
Spearman against the measured subset losses, average over queries. Lets a
replication be checked against published numbers without retraining.
…ment

save_run_config has always wrapped the step list in a document with a
metadata block, so load_training_config rejected every real run directory;
its test hand-rolled the bare list it expected instead of calling
save_run_config. Have the test write configs the way the writer does, and
report an unparseable payload as ValueError so callers guessing at a run
dir still degrade to their fallback.
Export -> EK-FAC IF -> SOURCE -> LDS against kronfluence's shipped bank.
EK-FAC 0.4451 against their reported 0.44; SOURCE 0.4506, above IF as in
the paper's Figure 6.
@luciaquirke luciaquirke changed the title Replicate the Bae et al. WikiText-2 SOURCE and EK-FAC results Add YAMLs for Adam WikiText SOURCE + EK-FAC replications Jul 31, 2026
@luciaquirke
luciaquirke merged commit aae67d5 into source-damp-options Jul 31, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant