Skip to content

Add adjust_lr function for learning rate schedules #247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

corbt
Copy link
Contributor

@corbt corbt commented Jul 16, 2025

Summary

  • Added adjust_lr function to iterate_dataset.py to support learning rate schedules with warmup and cooldown phases
  • Updated DatasetBatch to include total_steps field needed for LR calculations
  • Simplified API design: constant LR by default, linear decay achievable via cooldown_length

Implementation Details

The adjust_lr function supports:

  • warmup_length: Linear ramp from 0 to base LR (can be int for steps or float for ratio)
  • cooldown_length: Linear decay from base LR to 0 (can be int for steps or float for ratio)
  • No explicit schedule type needed - linear schedule over entire training achievable by setting cooldown_length=1.0

Status

This is a DRAFT PR - we'll make it final once we've had a chance to test it on some real runs.

Context

We've had good success with a constant learning rate in our experiments, but there may be some benefit to warmup and cooldown phases that we need to investigate through empirical testing.

🤖 Generated with Claude Code

corbt and others added 2 commits July 15, 2025 17:41
- Add adjust_lr function to calculate learning rate with warmup and cooldown phases
- Update DatasetBatch to include total_steps field for LR calculations
- Support warmup_length and cooldown_length as either int (steps) or float (ratio)
- Simplified design: constant LR by default, linear decay via cooldown_length

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
- Negative cooldown_length now specifies when cooldown starts (e.g., -20 means start at step 20)
- This enables easy linear decay after warmup: warmup_length=20, cooldown_length=-20
- Ensures cooldown always starts after warmup phase completes

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@corbt
Copy link
Contributor Author

corbt commented Jul 16, 2025

Added support for negative cooldown_length values as discussed:

  • Negative values now specify the exact step where cooldown starts (e.g., cooldown_length=-20 means cooldown begins at step 20)
  • This makes it easy to implement linear decay after warmup: warmup_length=20, cooldown_length=-20
  • The implementation ensures cooldown always starts after warmup completes

Example usage for your case:

lr = adjust_lr(batch, learning_rate=1e-4, warmup_length=20, cooldown_length=-20)

This will:

  1. Warmup from 0 to 1e-4 over the first 20 steps
  2. Start cooldown at step 20 and linearly decay to 0 by the end of training

- Add warmup_length and cooldown_length fields to ProjectPolicyConfig
- Update train.py to use adjust_lr function with batch-specific learning rates
- Add experiment 228 with 20-step warmup and cooldown starting at step 20

This experiment will test whether warmup/cooldown improves training compared to
our baseline constant learning rate approach.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
@corbt corbt force-pushed the add-adjust-lr-function branch from b171eb3 to 4c4ed54 Compare July 16, 2025 01:12
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