Skip to content

FIX Deep copy criterion in trees to fix concurrency bug #19580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2021

Conversation

samdbrice
Copy link
Contributor

Reference Issues/PRs

Fixes #12623
Adds a smoke test as requested in #12690
Implements deep copy within tree.BaseDecisionTree.fit as requested in #18985

What does this implement/fix? Explain your changes.

The issue is that when trees are created by the base ensemble class, the parameters are not copied. This is problematic in the case of the criterion parameter if a Criterion object is passed in. When this happens, all the trees share the same object and mutate it. If n_jobs > 1 (or -1, and we have more than one core available), they are mutating the same object concurrently.

Any other comments?

The functional changes of this PR are the same as those in #18985. The deep copy has been moved to within. BaseDecisionTree.fit as to be more targeted and prevent possibly costly object deep copies within BaseEnsemble._make_estimator.

@samdbrice samdbrice changed the title Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. FIX Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. Feb 28, 2021
@samdbrice samdbrice changed the title FIX Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. [MRG] FIX Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. Feb 28, 2021
@samdbrice
Copy link
Contributor Author

ping @thomasjpfan @glemaitre

Copy link
Member

@ogrisel ogrisel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@samdbrice samdbrice force-pushed the criterion-segfault branch from fc7ce52 to 9157002 Compare March 1, 2021 17:42
@ogrisel ogrisel added this to the 0.24.2 milestone Mar 1, 2021
@samdbrice samdbrice force-pushed the criterion-segfault branch from 9157002 to 75429ea Compare March 1, 2021 17:44
@ogrisel
Copy link
Member

ogrisel commented Mar 1, 2021

Could you please add a changelog entry in doc/whats_new/v0.24.rst targeting 0.24.2?

@samdbrice samdbrice force-pushed the criterion-segfault branch 2 times, most recently from 66491e9 to 3ff8dc2 Compare March 1, 2021 17:57
@samdbrice
Copy link
Contributor Author

Ok, moved changelog entry from v1.0 to v0.24.2

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the PR @samdbrice.

Minor suggestion, otherwise LGTM!

@samdbrice samdbrice force-pushed the criterion-segfault branch from 3ff8dc2 to 1abb39d Compare March 1, 2021 19:40
@samdbrice
Copy link
Contributor Author

Reused the pre-generated data but had to reshape y_reg

@thomasjpfan thomasjpfan changed the title [MRG] FIX Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. FIX Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. Mar 1, 2021
…nt segfault caused by concurrent accesses.
@samdbrice samdbrice force-pushed the criterion-segfault branch from 1abb39d to 48c45c5 Compare March 1, 2021 23:16
@samdbrice
Copy link
Contributor Author

Ok, all set. Let me know if there's anything else

Copy link
Member

@thomasjpfan thomasjpfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@thomasjpfan thomasjpfan changed the title FIX Deep copy the Criterion instance within BaseDecisionTree.fit to prevent concurrent accesses. FIX Deep copy criterion in trees to fix concurrency bug Mar 2, 2021
@thomasjpfan thomasjpfan merged commit 192952a into scikit-learn:main Mar 2, 2021
@cmarmo cmarmo added the To backport PR merged in master that need a backport to a release branch defined based on the milestone. label Apr 6, 2021
@glemaitre glemaitre mentioned this pull request Apr 22, 2021
12 tasks
glemaitre pushed a commit to glemaitre/scikit-learn that referenced this pull request Apr 22, 2021
…#19580)

Co-authored-by: Samuel Brice <samuel.brice@twosigma.com>
glemaitre pushed a commit that referenced this pull request Apr 28, 2021
Co-authored-by: Samuel Brice <samuel.brice@twosigma.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module:ensemble module:tree To backport PR merged in master that need a backport to a release branch defined based on the milestone.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault when passing Criterion object to Forest ensembles with n_jobs>1
4 participants