Skip to content

feat(train): add cosine LR scheduler with linear warmup - #13

Merged
tkgstrator merged 2 commits into
developfrom
feat/lr-scheduler
Jul 13, 2026
Merged

feat(train): add cosine LR scheduler with linear warmup#13
tkgstrator merged 2 commits into
developfrom
feat/lr-scheduler

Conversation

@tkgstrator

Copy link
Copy Markdown
Contributor

What

BoardOCR training gains a per-step LR scheduler (linear warmup → cosine anneal) plus three CLI flags:

  • --scheduler {none,cosine} (default cosine)
  • --warmup-epochs (default 5)
  • --min-lr-ratio (default 0.01, so min_lr = lr * 0.01)

Scheduler state persists in the checkpoint (scheduler key alongside optimizer / scaler) so resume continues on the same LR curve. The current LR is logged to W&B as step/lr each --log-every batch.

--scheduler=none recovers the previous constant-LR behavior for direct A/B against existing runs.

Why

Constant 3e-4 for the full 200 epoch budget was leaving standard image-classification headroom on the table — cosine+warmup is the modern default for this class of model. Also useful for the new 6-GPU DDP setup (effective batch 384), where warmup smooths the first few epochs at the higher effective LR.

Test plan

  • Unit-check: scheduler state resumes to the same LR after load_state_dict at step 10000 of a 20000-step schedule
  • CLI: --help surfaces the three new flags, defaults preserved
  • Kick off a 200-epoch run and confirm W&B step/lr shows the warmup + cosine curve

Version

Deferred here — PR #11 already bumps pyproject.toml to 0.3.2. Whichever of the two PRs merges second will need to re-bump.

🤖 Generated with Claude Code

@tkgstrator tkgstrator closed this Jul 13, 2026
@tkgstrator tkgstrator reopened this Jul 13, 2026
tkgstrator and others added 2 commits July 13, 2026 07:22
BoardOCR training previously ran with a constant LR (default 3e-4) for the
full epoch budget, leaving cheap image-classification gains on the table
especially for 200-epoch runs.

Add three CLI flags plumbed into a per-step SequentialLR of LinearLR +
CosineAnnealingLR:

  --scheduler {none,cosine}   default: cosine
  --warmup-epochs INT         default: 5
  --min-lr-ratio FLOAT        default: 0.01   (min_lr = lr * ratio)

The scheduler steps once per batch (all ranks share len(train_loader) shard
size, so DDP stays in lockstep), its state is persisted in the checkpoint,
and current LR is logged to W&B as step/lr each --log-every batch.

--scheduler=none reverts to the prior constant-LR behavior for
back-compat / A/B comparisons.

Note: version bump deferred; PR #11 already bumps to 0.3.2, so whichever
PR merges second will need to re-bump.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Companion bump for the LR scheduler feature. develop is at 0.3.2 after PR

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@tkgstrator
tkgstrator merged commit e1e3390 into develop Jul 13, 2026
3 checks passed
@tkgstrator
tkgstrator deleted the feat/lr-scheduler branch July 13, 2026 07:28
@tkgstrator tkgstrator mentioned this pull request Jul 13, 2026
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