Repository navigation
fix: Record each update's LR at its HF step in log_history.json - #567
Merged
luciaquirke merged 1 commit intoOct 26, 2026
Merged
Conversation
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.
Collaborator
|
Amazing, thank you very much!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SOURCE's
compute_lr_times_steps_per_segmentreads the run'slog_history.jsonand, for the segment between checkpointsaandb, sums the LRs at stepsa+1 .. b. That is HF'slog_historyconvention, where entrysholds the LR of thes-th update counting from one.write_lr_history, which the MAGIC trainer uses to write that file, recorded updatei(schedule(i)) atstep = i. The trainer'sstep_icheckpoint is the state before updatei, so:a+1 .. binstead ofa .. b-1;n-step run looked up stepn, which was never written (only0 .. n-1), and counted it as 0.Example: 4 updates, checkpoints
step_2andstep_4, two segments, viacompute_lr_times_steps_per_segment:1e-3[2e-3, 1e-3][2e-3, 2e-3]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 · Kfor two-step segments. With a decaying schedule, every segment is shifted by one update.The fix records update
iatstep = i + 1, so the bergson history follows the HF convention the reader assumes.The existing
test_lr_times_steps_reads_bergson_historyandtest_lr_history_read_from_the_run_not_the_exportpassed 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_shapenow expects steps from 1.test_lr_times_steps_sums_the_updates_between_checkpointsuses a decaying schedule and a final checkpoint atstep_n. It fails onmainand passes with this change.tests/test_source_trainer_integration.py,test_approx_unrolling_checkpoint_parse.py,test_source_optimizer_variants.py,test_magic.pyandtest_source_resume_polarity.pypass (73 passed, 2 skipped).