Skip to content

fix: Record each update's LR at its HF step in log_history.json - #567

Merged
luciaquirke merged 1 commit into
EleutherAI:mainfrom
flyingdoubleG:fix/lr-history-step-index
Oct 26, 2026
Merged

luciaquirke merged 1 commit into
EleutherAI:mainfrom
flyingdoubleG:fix/lr-history-step-index

Conversation

@flyingdoubleG

Copy link
Copy Markdown
Contributor

SOURCE's compute_lr_times_steps_per_segment reads the run's log_history.json and, for the segment between checkpoints a and b, sums the LRs at steps a+1 .. b. That is HF's log_history convention, where entry s holds the LR of the s-th update counting from one.

write_lr_history, which the MAGIC trainer uses to write that file, recorded update i (schedule(i)) at step = i. The trainer's step_i checkpoint is the state before update i, so:

  • each segment summed the LRs of updates a+1 .. b instead of a .. b-1;
  • the last segment of an n-step run looked up step n, which was never written (only 0 .. n-1), and counted it as 0.

Example: 4 updates, checkpoints step_2 and step_4, two segments, via compute_lr_times_steps_per_segment:

schedule before expected
constant 1e-3 [2e-3, 1e-3] [2e-3, 2e-3]
linear decay, 1e-3 · (4 - i) / 4 [1.25e-3, 0.25e-3] [1.75e-3, 0.75e-3]

With a constant LR, only the last segment is off: it is one update short, which is half of its lr · K for two-step segments. With a decaying schedule, every segment is shifted by one update.

The fix records update i at step = i + 1, so the bergson history follows the HF convention the reader assumes.

The existing test_lr_times_steps_reads_bergson_history and test_lr_history_read_from_the_run_not_the_export passed only because they wrote a 5-step history for checkpoints that end at step 4, with a constant LR.

Tests:

  • test_write_lr_history_matches_hf_log_history_shape now expects steps from 1.
  • New test_lr_times_steps_sums_the_updates_between_checkpoints uses a decaying schedule and a final checkpoint at step_n. It fails on main and passes with this change.
  • tests/test_source_trainer_integration.py, test_approx_unrolling_checkpoint_parse.py, test_source_optimizer_variants.py, test_magic.py and test_source_resume_polarity.py pass (73 passed, 2 skipped).
  • black, ruff and pyright are clean.

SOURCE's reader sums log_history steps (a, b] for the segment between
checkpoints a and b, HF's convention that entry s holds the LR of the s-th
update counting from one. write_lr_history recorded update i at step i, so
each segment summed the LRs of updates a+1 .. b instead of a .. b-1, and the
last segment of an n-step run looked up step n, which was never written.
With a constant LR the last segment's lr * K came out one step short (half
of it for two-step segments); with a decaying schedule every segment was
shifted. Record update i at step i + 1.
@luciaquirke

Copy link
Copy Markdown
Collaborator

Amazing, thank you very much!!

@luciaquirke
luciaquirke merged commit 87f6442 into EleutherAI:main Oct 26, 2026
7 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.

2 participants