Skip to content
Merged
Show file tree
Hide file tree
Changes from 13 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
1 change: 1 addition & 0 deletions R-package/src/Makevars.in
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ OBJECTS= \
$(PKGROOT)/src/data/iterative_dmatrix.o \
$(PKGROOT)/src/predictor/predictor.o \
$(PKGROOT)/src/predictor/cpu_predictor.o \
$(PKGROOT)/src/predictor/interpretability/shap.o \
$(PKGROOT)/src/predictor/treeshap.o \
$(PKGROOT)/src/tree/constraints.o \
$(PKGROOT)/src/tree/param.o \
Expand Down
1 change: 1 addition & 0 deletions R-package/src/Makevars.win.in
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ OBJECTS= \
$(PKGROOT)/src/data/iterative_dmatrix.o \
$(PKGROOT)/src/predictor/predictor.o \
$(PKGROOT)/src/predictor/cpu_predictor.o \
$(PKGROOT)/src/predictor/interpretability/shap.o \
$(PKGROOT)/src/predictor/treeshap.o \
$(PKGROOT)/src/tree/constraints.o \
$(PKGROOT)/src/tree/param.o \
Expand Down
7 changes: 3 additions & 4 deletions include/xgboost/predictor.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,7 @@ class Predictor {
struct PredictorReg
: public dmlc::FunctionRegEntryBase<PredictorReg, std::function<Predictor*(Context const*)>> {};

#define XGBOOST_REGISTER_PREDICTOR(UniqueId, Name) \
static DMLC_ATTRIBUTE_UNUSED ::xgboost::PredictorReg& \
__make_##PredictorReg##_##UniqueId##__ = \
::dmlc::Registry<::xgboost::PredictorReg>::Get()->__REGISTER__(Name)
#define XGBOOST_REGISTER_PREDICTOR(UniqueId, Name) \
static DMLC_ATTRIBUTE_UNUSED ::xgboost::PredictorReg& __make_##PredictorReg##_##UniqueId##__ = \
::dmlc::Registry<::xgboost::PredictorReg>::Get()->__REGISTER__(Name)
} // namespace xgboost
31 changes: 13 additions & 18 deletions src/gbm/gbtree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,7 @@ void GBTree::Configure(Args const& cfg) {

#if defined(XGBOOST_USE_SYCL)
if (!sycl_predictor_) {
sycl_predictor_ =
std::unique_ptr<Predictor>(Predictor::Create("sycl_predictor", this->ctx_));
sycl_predictor_ = std::unique_ptr<Predictor>(Predictor::Create("sycl_predictor", this->ctx_));
}
sycl_predictor_->Configure(cfg);
#endif // defined(XGBOOST_USE_SYCL)
Expand Down Expand Up @@ -639,9 +638,9 @@ void GBTree::InplacePredict(std::shared_ptr<DMatrix> p_m, float missing,
return gpu_predictor_;
} else {
#if defined(XGBOOST_USE_SYCL)
common::AssertSYCLSupport();
CHECK(sycl_predictor_);
return sycl_predictor_;
common::AssertSYCLSupport();
CHECK(sycl_predictor_);
return sycl_predictor_;
#endif // defined(XGBOOST_USE_SYCL)
}

Expand Down Expand Up @@ -676,7 +675,6 @@ void GPUDartInplacePredictInc(common::Span<float> /*out_predts*/, common::Span<f
}
#endif


class Dart : public GBTree {
public:
explicit Dart(LearnerModelParam const* booster_config, Context const* ctx)
Expand All @@ -687,8 +685,8 @@ class Dart : public GBTree {
dparam_.UpdateAllowUnknown(cfg);
}

void Slice(int32_t layer_begin, int32_t layer_end, int32_t step,
GradientBooster *out, bool* out_of_bound) const final {
void Slice(int32_t layer_begin, int32_t layer_end, int32_t step, GradientBooster* out,
bool* out_of_bound) const final {
GBTree::Slice(layer_begin, layer_end, step, out, out_of_bound);
if (*out_of_bound) {
return;
Expand All @@ -701,8 +699,8 @@ class Dart : public GBTree {
});
}

void SaveModel(Json *p_out) const override {
auto &out = *p_out;
void SaveModel(Json* p_out) const override {
auto& out = *p_out;
out["name"] = String("dart");
out["gbtree"] = Object();
GBTree::SaveModel(&(out["gbtree"]));
Expand Down Expand Up @@ -746,8 +744,7 @@ class Dart : public GBTree {
CHECK(!this->model_.learner_model_param->IsVectorLeaf()) << "dart" << MTNotImplemented();
auto& predictor = this->GetPredictor(training, &p_out_preds->predictions, p_fmat);
CHECK(predictor);
predictor->InitOutPredictions(p_fmat->Info(), &p_out_preds->predictions,
model_);
predictor->InitOutPredictions(p_fmat->Info(), &p_out_preds->predictions, model_);
p_out_preds->version = 0;
auto [tree_begin, tree_end] = detail::LayerToTree(model_, layer_begin, layer_end);
auto n_groups = model_.learner_model_param->num_output_group;
Expand Down Expand Up @@ -784,8 +781,8 @@ class Dart : public GBTree {
GPUDartPredictInc(p_out_preds->predictions.DeviceSpan(), predts.predictions.DeviceSpan(), w,
n_rows, n_groups, grp_idx);
} else {
auto &h_out_predts = p_out_preds->predictions.HostVector();
auto &h_predts = predts.predictions.ConstHostVector();
auto& h_out_predts = p_out_preds->predictions.HostVector();
auto& h_predts = predts.predictions.ConstHostVector();
common::ParallelFor(p_fmat->Info().num_row_, ctx_->Threads(), [&](auto ridx) {
const size_t offset = ridx * n_groups + grp_idx;
h_out_predts[offset] += (h_predts[offset] * w);
Expand Down Expand Up @@ -942,10 +939,8 @@ class Dart : public GBTree {
// size_t i = std::discrete_distribution<size_t>(weight_drop.begin(),
// weight_drop.end())(rnd);
size_t i = std::discrete_distribution<size_t>(
weight_drop_.size(), 0., static_cast<double>(weight_drop_.size()),
[this](double x) -> double {
return weight_drop_[static_cast<size_t>(x)];
})(rnd);
weight_drop_.size(), 0., static_cast<double>(weight_drop_.size()),
[this](double x) -> double { return weight_drop_[static_cast<size_t>(x)]; })(rnd);
idx_drop_.push_back(i);
}
} else {
Expand Down
32 changes: 14 additions & 18 deletions src/gbm/gbtree.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ enum class TreeMethod : int {
};

// boosting process types
enum class TreeProcessType : int {
kDefault = 0,
kUpdate = 1
};
enum class TreeProcessType : int { kDefault = 0, kUpdate = 1 };

// Sampling type for dart weights.
enum class DartSampleType : std::int32_t {
Expand Down Expand Up @@ -72,15 +69,16 @@ struct GBTreeTrainParam : public XGBoostParameter<GBTreeTrainParam> {
.set_default(TreeProcessType::kDefault)
.add_enum("default", TreeProcessType::kDefault)
.add_enum("update", TreeProcessType::kUpdate)
.describe("Whether to run the normal boosting process that creates new trees,"\
" or to update the trees in an existing model.");
.describe(
"Whether to run the normal boosting process that creates new trees,"
" or to update the trees in an existing model.");
DMLC_DECLARE_ALIAS(updater_seq, updater);
DMLC_DECLARE_FIELD(tree_method)
.set_default(TreeMethod::kAuto)
.add_enum("auto", TreeMethod::kAuto)
.add_enum("approx", TreeMethod::kApprox)
.add_enum("exact", TreeMethod::kExact)
.add_enum("hist", TreeMethod::kHist)
.add_enum("auto", TreeMethod::kAuto)
.add_enum("approx", TreeMethod::kApprox)
.add_enum("exact", TreeMethod::kExact)
.add_enum("hist", TreeMethod::kHist)
.describe("Choice of tree construction method.");
}
};
Expand Down Expand Up @@ -268,10 +266,9 @@ class GBTree : public GradientBooster {
}
});
} else {
LOG(FATAL)
<< "Unknown feature importance type, expected one of: "
<< R"({"weight", "total_gain", "total_cover", "gain", "cover"}, got: )"
<< importance_type;
LOG(FATAL) << "Unknown feature importance type, expected one of: "
<< R"({"weight", "total_gain", "total_cover", "gain", "cover"}, got: )"
<< importance_type;
}
if (importance_type == "gain" || importance_type == "cover") {
for (size_t i = 0; i < gain_map.size(); ++i) {
Expand All @@ -291,9 +288,8 @@ class GBTree : public GradientBooster {

[[nodiscard]] CatContainer const* Cats() const override { return this->model_.Cats(); }

void PredictLeaf(DMatrix* p_fmat,
HostDeviceVector<bst_float>* out_preds,
uint32_t layer_begin, uint32_t layer_end) override {
void PredictLeaf(DMatrix* p_fmat, HostDeviceVector<bst_float>* out_preds, uint32_t layer_begin,
uint32_t layer_end) override {
auto [tree_begin, tree_end] = detail::LayerToTree(model_, layer_begin, layer_end);
CHECK_EQ(tree_begin, 0) << "Predict leaf supports only iteration end: [0, "
"n_iteration), use model slicing instead.";
Expand Down Expand Up @@ -345,7 +341,7 @@ class GBTree : public GradientBooster {
GBTreeTrainParam tparam_;
// Tree training parameter
tree::TrainParam tree_param_;
bool specified_updater_ {false};
bool specified_updater_{false};
// the updaters that can be applied to each of tree
std::vector<std::unique_ptr<TreeUpdater>> updaters_;
// Predictors
Expand Down
Loading
Loading