Repository navigation
Conversation
…ss-validation BaseRClassifier.fit() and XGBRRegressor.fit() called cross_val_predict() with n_jobs=-1, ignoring the inherited cv_n_jobs attribute, so setting it did not limit cross-validation parallelism. Pass self.cv_n_jobs, as the BaseRLearner path already does through compute_r_residuals().
5 tasks done
This branch has not been deployed
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.
Proposed changes
Fixes #1059.
BaseRClassifier.fit()calledcross_val_predict(..., n_jobs=-1)unconditionally, ignoring thecv_n_jobsattribute it inherits fromBaseRLearner. Settingcv_n_jobstherefore didn't limit cross-validation parallelism, which matters when fits are themselves dispatched in parallel and each outer worker starts its own joblib pool.XGBRRegressor.fit()had the same hard-codedn_jobs=-1. Those are the only two directcross_val_predictcalls inrlearner.py. Both now passn_jobs=self.cv_n_jobs, matching theBaseRLearnerpath, which already forwardscv_n_jobstocompute_r_residuals()(#714). The default stays-1, so behavior is unchanged unlesscv_n_jobsis set.Note: the R-learner subclasses don't take
cv_n_jobsas a constructor argument, so it can only be set as an attribute after construction (as in the issue's repro). I've left that as is to keep this fix focused; happy to add it in a follow-up if you'd like.Types of changes
Checklist
Further comments
Tests:
test_r_learner_cross_val_predict_respects_cv_n_jobsintests/test_meta_learners.pyis parametrized overBaseRClassifierandXGBRRegressor. It setscv_n_jobs = 1, wrapscross_val_predict, and checks the value reaches it. Onmasterboth cases fail withassert -1 == 1; with this change they pass. Full suite locally (pytest tests/ --cov causalml/): 568 passed, 18 skipped, 4 failed. The 4 failures are the uplift tree visualization tests, which need Graphviz'sdotbinary that isn't installed on my machine; they fail the same way onmaster.blackreports no changes.