feat(recipes): add per-step learning rate support to all training recipes#359
Open
renfeichen-fw wants to merge 1 commit intomainfrom
Open
feat(recipes): add per-step learning rate support to all training recipes#359renfeichen-fw wants to merge 1 commit intomainfrom
renfeichen-fw wants to merge 1 commit intomainfrom
Conversation
…ipes Add `lr_per_step: list[float] | None` field to SFT, DPO, RL, and ORPO recipe Configs. When set, each optimizer step uses `lr_per_step[step]` instead of a flat `learning_rate`. Falls back to the last value if the list is shorter than the actual step count. Also adds `lr_schedule`, `warmup_ratio`, and `min_lr_ratio` convenience fields that auto-generate `lr_per_step` from schedule params after data loading (when the caller doesn't supply an explicit list). Shared utility `build_lr_per_step()` extracted from ORPO's `_compute_lr()` into `training/utils/lr_schedule.py` so all recipes and the managed orchestrator share the same schedule logic. All new fields default to backward-compatible values (None / "constant" / 0.0). No proto, Go, or trainer backend changes required. Made-with: Cursor
websterbei
reviewed
Apr 21, 2026
|
|
||
| beta: float = 0.1 | ||
| learning_rate: float = 1e-5 | ||
| lr_per_step: list[float] | None = None |
Contributor
There was a problem hiding this comment.
Why is this a list? I feel that nobody gives a list of LR precomputed per step as input...
6 tasks
xiaoyifan
approved these changes
Apr 21, 2026
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.
Description
Add per-step learning rate control to all cookbook training recipes (SFT, DPO, RL, ORPO).
The primary abstraction is
lr_per_step: list[float] | None— an explicit list of LR values, one per optimizer step. Customers pass this list to recipes (they compute it however they want). The managed service can auto-generate it from schedule params (lr_schedule,warmup_ratio,min_lr_ratio) after data loading.Architecture / Code Overview Diagram
flowchart TD subgraph customerPath["Customer Path"] CustCode["Customer Code"] -->|"lr_per_step=[...]"| Config["Recipe Config"] end subgraph managedPath["Managed / Schedule Path"] Params["lr_schedule + warmup_ratio + min_lr_ratio"] --> Builder["build_lr_per_step()"] Builder -->|"[0.0, 1e-6, ..., 1e-4, ..., 1e-5]"| Config end Config --> Loop["Recipe Training Loop"] Loop -->|"step i: AdamParams(lr=lr_per_step[i])"| Trainer["Tinker optim_step"]Type of Change
Testing
Unit tests: 18 tests in
test_lr_schedule.pycovering constant/cosine/linear schedules, warmup, min_lr_ratio, edge cases, and resolve_step_lr fallback.Smoke test: Verified E2E on 8xH200 with Qwen3.5-35B-A3B — 5 optimizer steps with different LRs (1e-5, 5e-5, 1e-4, 7e-5, 5e-6) and varying grad accumulation counts (1, 2, 3). All steps completed, reported LR metrics matched exactly.
Import smoke tests: All 80 tests pass including Config defaults and
__all__resolution.Surface Consistency
Deployment Notes
Change Size
Checklist
Files Changed
training/utils/lr_schedule.pybuild_lr_per_step()andresolve_step_lr()training/utils/__init__.pytraining/recipes/sft_loop.pylr_per_step+ schedule fields, per-step LR in looptraining/recipes/dpo_loop.pyadam_paramsfrom_train_looptraining/recipes/rl_loop.pytraining/recipes/orpo_loop.pylr_per_stepoverride; replaced inline_compute_lrwith shared utilitytraining/tests/unit/test_lr_schedule.pytraining/tests/unit/test_dpo_loop.py_train_loopsignatureMade with Cursor