feat(train): SPEC §82 P2-B — warn on corpus wrap-around to expose data starvation#1707
Merged
Conversation
…a starvation ShardBatchIter::with_warn_on_wrap_around(true) prints a stderr line each time the corpus cycles. apr pretrain enables it by default so operators can detect when --num-steps exceeds the corpus capacity (per Chinchilla scaling: train tokens D ≈ 20·N). Without this warning, a small corpus silently cycles 5-10× per run and the model memorizes instead of generalizing. The §49 from-scratch pivot empirically observed this on a 9.75 val_loss floor that turned out to be 4× corpus memorization (see project_2026_04_27_4x_corpus_ memorization_disproof.md). Empirical example: 18M-token corpus, 5K-step run, batch=16 seq=512 = 41M training tokens needed → 2.3× wrap-around. The new warning fires twice during the run, alerting the operator before val_loss plateaus. Backward compatible: default OFF. Tests/library users see no change unless they opt in via .with_warn_on_wrap_around(true). Test plan: - 2 new unit tests in shard_reader (with-wrap + without-wrap inert) - 5 prior tests unaffected - 7/7 shard_reader::tests pass Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
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.
Summary
ShardBatchIter::with_warn_on_wrap_around(true)opt-in flag that prints a stderr line each time the corpus cycles past its last shard.apr pretrainenables it by default so operators can detect when--num-stepsexceeds corpus capacity (per ChinchillaD ≈ 20·N).Motivation
Methodology lesson #29 (Class 3 packaging defects come in waves) and lesson #18 (predict-then-verify) both surface data starvation as a recurring class of MODEL-2 convergence failure. The 9.75 val_loss floor in §49 was eventually traced to 4× corpus memorization (
project_2026_04_27_4x_corpus_memorization_disproof.md) — silent wrap-around masked the cause for weeks.Now: 18M-token corpus + 5K steps × batch=16 × seq=512 = 41M tokens needed → wrap-around fires 2.3× during the run, with an explicit stderr line each time.
Test plan
cargo test -p aprender-train --lib shard_reader→ 7/7 PASSwarn_on_wrap_around_does_not_break_iteration+warn_without_wrap_is_inertcargo build -p apr-cli --bin aprsucceedsBackward compatibility
Default OFF. Tests and library users see no change unless they opt in via
.with_warn_on_wrap_around(true). Onlyapr pretrainenables it.🤖 Generated with Claude Code