[python] Apply LearningRateScheduler rates to the tree of the same round #12791
All Vouch review confidence checks passed
Residual risk 0.17 = Change Risk (0.42) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.42 · 344 lines diff across 4 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.350
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12791"
general
weight: 0.35
RAMitchell
LearningRateSchedulersets the learning rate inafter_iteration, so a rate only takes effect from the next round. Roundiis built withlearning_rates(i - 1): the first tree uses the booster's defaulteta, and the last entry of the schedule is never used. The docstring says the callable getsepochand "returns the corresponding learning rate", and that a sequence has "the same size of boosting rounds".Largest absolute leaf value per tree:
| tree | rate |
master| this PR | built by hand ||---|---|---|---|---|
| 0 | 0.01 | 1.4499 | 0.0483 | 0.0483 |
| 1 | 0.5 | 0.0417 | 2.3926 | 2.3926 |
| 2 | 0.1 | 2.0622 | 0.389 | 0.389 |
| 3 | 0.9 | 0.2636 | 3.0153 | 3.0153 |
On
masterthe script printsFalse, with this PRTrue. The first row onmasteris what the defaulteta=0.3gives.The fix moves the update to
before_iteration, which is also where the R package'sxgb.cb.reset.parameterssets it (f_before_iter), so the two interfaces now agree.xgb.cvgoes through the same callback: with rates[0, 0, 0.5]the test RMSE stays flat for two rounds and then drops.This changes results for existing users of the callback, as each tree now gets the rate one position earlier in the schedule, so I added a
versionchangednote to the docstring. If you would rather handle the behaviour change differently, let me know.Tests: the two helpers in
xgboost/testing/callbacks.pyencoded the old timing, so they are updated.run_eta_decayasserted that a schedule leaves the first round's error untouched. It now asserts the first round differs. The last round is left out of the comparison because the large rates in that test bring it back to the error of a constant prediction.run_eta_decay_leaf_outputchanges the schedule fromi > 2, so tree 2 stays equal and tree 3 differs, as before.master.tests/python/test_callback.pyandtests/python/test_early_stopping.pypass on macOS with CPU tree methods. The GPU variants of these helpers (tests/python-gpu/test_gpu_callbacks.py) were not run, as I have no NVIDIA GPU.