Skip to content

Commit

Permalink
fix comments, and reduced memory for all reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
SHVETS, KIRILL committed Apr 29, 2020
1 parent fb1f58f commit 77734fe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
20 changes: 11 additions & 9 deletions src/tree/updater_quantile_hist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ void QuantileHistMaker::Update(HostDeviceVector<GradientPair> *gpair,
DMatrix *dmat,
const std::vector<RegTree *> &trees) {
if (dmat != p_last_dmat_ || is_gmat_initialized_ == false) {
updater_monitor_.Start("GmatInitialization");
gmat_.Init(dmat, static_cast<uint32_t>(param_.max_bin));
column_matrix_.Init(gmat_, param_.sparse_threshold);
if (param_.enable_feature_grouping > 0) {
gmatb_.Init(gmat_, column_matrix_, param_);
}
updater_monitor_.Stop("GmatInitialization");
// A proper solution is puting cut matrix in DMatrix, see:
// https://github.com/dmlc/xgboost/issues/5143
is_gmat_initialized_ = true;
Expand Down Expand Up @@ -145,9 +147,9 @@ void QuantileHistMaker::Builder::SyncHistograms(
}
});

builder_monitor_.Start("SyncHistograms:histred_.Allreduce");
builder_monitor_.Start("SyncHistogramsAllreduce");
this->histred_.Allreduce(hist_[starting_index].data(), hist_builder_.GetNumBins() * sync_count);
builder_monitor_.Stop("SyncHistograms:histred_.Allreduce");
builder_monitor_.Stop("SyncHistogramsAllreduce");

common::ParallelFor2d(space, this->nthread_, [&](size_t node, common::Range1d r) {
const auto entry = nodes_for_explicit_hist_build_[node];
Expand Down Expand Up @@ -389,12 +391,12 @@ void QuantileHistMaker::Builder::SplitSiblings(const std::vector<ExpandEntry>& n
} else {
const int32_t left_id = (*p_tree)[node.Parent()].LeftChild();
const int32_t right_id = (*p_tree)[node.Parent()].RightChild();
size_t node_sizes[2] = { row_set_collection_[left_id ].Size(),
row_set_collection_[right_id].Size() };

if (nid == left_id && node_sizes[0] < node_sizes[1]) {
if (nid == left_id && row_set_collection_[left_id ].Size() <
row_set_collection_[right_id].Size()) {
small_siblings->push_back(entry);
} else if (nid == right_id && node_sizes[1] <= node_sizes[0]) {
} else if (nid == right_id && row_set_collection_[right_id].Size() <=
row_set_collection_[left_id ].Size()) {
small_siblings->push_back(entry);
} else {
big_siblings->push_back(entry);
Expand Down Expand Up @@ -496,9 +498,7 @@ void QuantileHistMaker::Builder::ExpandWithLossGuide(
ExpandEntry right_node(cright, cleft, p_tree->GetDepth(cright),
0.0f, timestamp++);

size_t node_sizes[2] = { row_set_collection_[cleft].Size(),
row_set_collection_[cright].Size() };
if (node_sizes[0] < node_sizes[1]) {
if (row_set_collection_[cleft].Size() < row_set_collection_[cright].Size()) {
BuildHistogramsLossGuide(left_node, gmat, gmatb, p_tree, gpair_h);
} else {
BuildHistogramsLossGuide(right_node, gmat, gmatb, p_tree, gpair_h);
Expand Down Expand Up @@ -549,7 +549,9 @@ void QuantileHistMaker::Builder::Update(const GHistIndexMatrix& gmat,
p_tree->Stat(nid).base_weight = snode_[nid].weight;
p_tree->Stat(nid).sum_hess = static_cast<float>(snode_[nid].stats.sum_hess);
}
builder_monitor_.Start("PrunerUpdate");
pruner_->Update(gpair, p_fmat, std::vector<RegTree*>{p_tree});
builder_monitor_.Stop("PrunerUpdate");

builder_monitor_.Stop("Update");
}
Expand Down
6 changes: 4 additions & 2 deletions src/tree/updater_quantile_hist.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ using xgboost::common::Column;
/*! \brief construct a tree using quantized feature values */
class QuantileHistMaker: public TreeUpdater {
public:
QuantileHistMaker() = default;
QuantileHistMaker() {
updater_monitor_.Init("Quantile");
}
void Configure(const Args& args) override;

void Update(HostDeviceVector<GradientPair>* gpair,
Expand Down Expand Up @@ -371,7 +373,7 @@ class QuantileHistMaker: public TreeUpdater {
common::ParallelGHistBuilder hist_buffer_;
rabit::Reducer<GradStats, GradStats::Reduce> histred_;
};

common::Monitor updater_monitor_;
std::unique_ptr<Builder> builder_;
std::unique_ptr<TreeUpdater> pruner_;
std::unique_ptr<SplitEvaluator> spliteval_;
Expand Down

0 comments on commit 77734fe

Please sign in to comment.