Skip to content

Fix AttributeError when retraining rf/extra_tree without a search (max_iter 0 or 1) under a time budget - #1666

Open
Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
microsoft:mainfrom
sohailshk:fix/retrain-without-trial-budget
Open

Mohammad Sohail Shaikh (sohailshk) wants to merge 1 commit into
microsoft:mainfrom
sohailshk:fix/retrain-without-trial-budget

Conversation

@sohailshk

Copy link
Copy Markdown

Why are these changes needed?

LGBMEstimator.fit() (inherited by RandomForestEstimator and ExtraTreesEstimator) caps the iteration count by the remaining time budget using self._t1, which only exists after the timing fits of a search trial. max_iter < 2 skips the search and retrains the initial config on a fresh estimator with the time budget still set, so:

AutoML().fit(X, y, task="classification", time_budget=5, max_iter=1, estimator_list=["rf"])
# AttributeError: 'RandomForestEstimator' object has no attribute '_t1'

max_iter=0 fails the same way, including the documented zero-shot form max_iter=0, starting_points="data", estimator_list=["rf", "lgbm"], time_budget=60 (all run on main). extra_tree also fails; lgbm, xgboost, xgb_limitdepth, lrl1, sgd, kneighbor are fine. From code reading: the max_iter > 1 path already sets time_budget = -1 before retraining (automl.py), which is why searches never hit this. The fix keeps the configured iteration count when no timing exists.
Tests (rf/extra_tree x max_iter 0/1, plus the zero-shot form): 5 failed on main, 5 pass. test_training_log, test_multiclass, test_regression, test_resampler, test_classification, test_extra_models: 99 passed; failures/error are missing-catboost cases that also fail on main.

Related issue number

none.

Checks

Checks run: black (line length 120) and ruff on the changed files. The pinned pre-commit hook versions were not run. No doc changes are needed.

…er a time budget

LGBMEstimator.fit() (inherited by RandomForestEstimator and ExtraTreesEstimator)
used self._t1 to cap the number of iterations by the remaining budget, but _t1
is only set by the timing fits of a search trial. With max_iter 0 or 1 the search
is skipped and the initial config is retrained on a fresh estimator with the time
budget still set, which raised AttributeError. Fall back to the configured number
of iterations when no timing is available.

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.

1 participant