Skip to content

[c++] Allow continued training for random forest - #7487

Open
Mike014 wants to merge 1 commit into
lightgbm-org:mainfrom
Mike014:fix/rf-init-model
Open

Mike014 wants to merge 1 commit into
lightgbm-org:mainfrom
Mike014:fix/rf-init-model

Conversation

@Mike014

@Mike014 Mike014 commented Oct 5, 2026

Copy link
Copy Markdown

Fixes #6143.

init_model currently fails when continuing training with boosting_type="rf".

When init_model is provided, the Python package creates an _InnerPredictor and uses its raw predictions as the new Dataset's init_score. The RF booster is then initialized before the previous model is merged into it.

At that point, RF::Init() sees a non-null init_score while num_init_iteration_ is still 0 and fails on the existing check. The previous trees would only be imported afterwards by LGBM_BoosterMerge().

This PR moves that check from RF::Init() to RF::TrainOneIter(). By then, an initial model has already been merged and num_init_iteration_ reflects the existing trees.

The existing behavior for manually-provided init_score is preserved: RF still rejects it when no initial model has been merged.

A regression test was added for continuing RF training from a saved model.

Tested with:

  • test_continue_train_rf: passes (10 initial + 10 additional trees = 20)
  • all continue_train tests: 5 passed
  • tests/python_package_test/test_engine.py: 181 passed, 4 skipped

This branch has not been deployed

No deployments
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.

init_model broken for boosting='rf'

2 participants