Skip to content

HistGradientBoosting memory improvement #18163

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

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions sklearn/ensemble/_hist_gradient_boosting/gradient_boosting.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,14 @@ def fit(self, X, y, sample_weight=None):
sample_weight=sample_weight_train
)

def del_hists(node):
if node is None:
return
if getattr(node, 'histograms', None) is not None:
del node.histograms
del_hists(node.left_child)
del_hists(node.right_child)

for iteration in range(begin_at_stage, self.max_iter):

if self.verbose:
Expand Down Expand Up @@ -392,6 +400,9 @@ def fit(self, X, y, sample_weight=None):
toc_pred = time()
acc_prediction_time += toc_pred - tic_pred

del_hists(grower.root)
del grower

should_early_stop = False
if self.do_early_stopping_:
if self.scoring == 'loss':
Expand Down
6 changes: 6 additions & 0 deletions sklearn/ensemble/_hist_gradient_boosting/grower.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"""
# Author: Nicolas Hug


from heapq import heappush, heappop
import numpy as np
from timeit import default_timer as time
Expand Down Expand Up @@ -486,6 +487,11 @@ def split_next(self):
self._compute_best_split_and_push(right_child_node)
self.total_find_split_time += time() - tic

for child in [left_child_node, right_child_node]:
if child.is_leaf:
del child.histograms
del node.histograms

return left_child_node, right_child_node

def _finalize_leaf(self, node):
Expand Down