Skip to content

Commit

Permalink
Rewrite approx.
Browse files Browse the repository at this point in the history
Save cuts.

Prototype on fetching.

Copy the code.

Simple test.

Add gpair to batch parameter.

Add hessian to batch parameter.

Move.

Pass hessian into sketching.

Extract a push page function.

Make private.

Lint.

Revert debug.

Simple DMatrix.

Regenerate the index.

ama.

Clang tidy.

Retain page.

Fix.

Lint.

Tidy.

Integer backed enum.

Convert to uint32_t.

Prototype for saving gidx.

Save cuts.

Prototype on fetching.

Copy the code.

Simple test.

Add gpair to batch parameter.

Add hessian to batch parameter.

Move.

Pass hessian into sketching.

Extract a push page function.

Make private.

Lint.

Revert debug.

Simple DMatrix.

Initial port.

Pass in hessian.

Init column sampler.

Unused code.

Use ctx.

Merge sampling.

Use ctx in partition.

Fix init root.

Force regenerate the sketch.

Create a ctx.

Get it compile.

Don't use const method.

Use page id.

Pass in base row id.

Pass the cut instead.

Small fixes.

Debug.

Fix bin size.

Debug.

Fixes.

Debug.

Fix empty partition.

Remove comment.

Lint.

Fix tests compilation.

Remove check.

Merge some fixes.

fix.

Fix fetching.

lint.

Extract expand entry.

Lint.

Fix unittests.

Fix windows build.

Fix comparison.

Make const.

Note.

const.

Fix reduce hist.

Fix sparse data.

Avoid implicit conversion.

private.

mem leak.

Remove skip initialization.

Use maximum space.

demo.

lint.

File link tags.

ama.

Fix redefinition.

Fix ranking.

use npy.

Comment.

Tune it down.

Specify the tree method.

Get rid of the duplicated partitioner.

Allocate task.

Tests.

make batches.

Log.

Remove span.

Revert "make batches."

This reverts commit 33f7072.

small cleanup.

Lint.

Revert demo.

Better make batches.

Demo.

Test for grow policy.

Test feature weights.

small cleanup.

Remove iterator in evaluation.

Fix dask test.

Pass n_threads.

Start implementation for categorical data.

Fix.

Add apply split.

Enumerate splits.

Enable sklearn.

Works.

d_step.

update.

Pass feature types into index.

Search cut.

Add test.

As cat.

Fix cut.

Extract some tests.

Fix.

Interesting case.

Add Python tests.

Cleanup.

Revert "Interesting case."

This reverts commit 6bbaac2.

Bin.

Fix.

Dispatch.

Remove subtraction trick.

Lint

Use multiple buffers.

Revert "Use multiple buffers."

This reverts commit 2849f57.

Test for external memory.

Format.

Partition based categorical split.

Remove debug code.

Fix.

Lint.

Fix test.

Fix demo.

Fix.

Add test.

Remove use of omp func.

name.

Fix.

test.

Make LCG impl compliant to std.

Fix test.

Constexpr.

Use unsigned type.

osx

More test.

Rebase error.

Rebase error.

Rebase error.

Reverse unused changes.

Config.

Remove weird set thread.
  • Loading branch information
trivialfis committed Nov 27, 2021
1 parent eee527d commit 904b787
Show file tree
Hide file tree
Showing 20 changed files with 525 additions and 63 deletions.
1 change: 1 addition & 0 deletions amalgamation/xgboost-all0.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
#include "../src/tree/updater_refresh.cc"
#include "../src/tree/updater_sync.cc"
#include "../src/tree/updater_histmaker.cc"
#include "../src/tree/updater_approx.cc"
#include "../src/tree/constraints.cc"

// linear
Expand Down
3 changes: 2 additions & 1 deletion demo/guide-python/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
=====================================
Experimental support for categorical data. After 1.5 XGBoost `gpu_hist` tree method has
experimental support for one-hot encoding based tree split.
experimental support for one-hot encoding based tree split, and in 1.6 `approx` supported
was added.
In before, users need to run an encoder themselves before passing the data into XGBoost,
which creates a sparse matrix and potentially increase memory usage. This demo showcases
Expand Down
16 changes: 13 additions & 3 deletions doc/parameter.rst
Original file line number Diff line number Diff line change
Expand Up @@ -232,15 +232,25 @@ Parameters for Tree Booster
- Constraints for interaction representing permitted interactions. The constraints must
be specified in the form of a nest list, e.g. ``[[0, 1], [2, 3, 4]]``, where each inner
list is a group of indices of features that are allowed to interact with each other.
See tutorial for more information
See tutorial for more information.

Additional parameters for ``hist`` and ``gpu_hist`` tree method
================================================================
Additional parameters for ``hist`` and ``gpu_hist`` and ``approx`` tree method
==============================================================================

* ``single_precision_histogram``, [default=``false``]

- Use single precision to build histograms instead of double precision.

Additional parameters for ``approx`` tree method
================================================

* ``max_cat_to_onehot``

- A threshold for deciding whether XGBoost should use one-hot encoding based split for
categorical data. When number of categories is lesser than the threshold then one-hot
encoding is chosen, otherwise the categories will be partitioned into children nodes.
Only relevant for regression and binary classification and `approx` tree method.

Additional parameters for Dart Booster (``booster=dart``)
=========================================================

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,12 @@ abstract class XGBoostRegressorSuiteBase extends FunSuite with PerTest {
}
}

class XGBoostCpuRegressorSuite extends XGBoostRegressorSuiteBase {
class XGBoostCpuRegressorSuiteApprox extends XGBoostRegressorSuiteBase {
override protected val treeMethod: String = "approx"
}

class XGBoostCpuRegressorSuiteHist extends XGBoostRegressorSuiteBase {
override protected val treeMethod: String = "hist"
}

@GpuTestSuite
Expand Down
16 changes: 14 additions & 2 deletions python-package/xgboost/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,16 @@ def inner(y_score: np.ndarray, dmatrix: DMatrix) -> Tuple[str, float]:
callbacks = [xgb.callback.EarlyStopping(rounds=early_stopping_rounds,
save_best=True)]
max_cat_to_onehot : bool
.. versionadded:: 1.6.0
A threshold for deciding whether XGBoost should use one-hot encoding based split
for categorical data. When number of categories is lesser than the threshold then
one-hot encoding is chosen, otherwise the categories will be partitioned into
children nodes. Only relevant for regression and binary classification and
`approx` tree method.
kwargs : dict, optional
Keyword arguments for XGBoost Booster object. Full documentation of
parameters can be found here:
Expand Down Expand Up @@ -484,6 +494,7 @@ def __init__(
eval_metric: Optional[Union[str, List[str], Callable]] = None,
early_stopping_rounds: Optional[int] = None,
callbacks: Optional[List[TrainingCallback]] = None,
max_cat_to_onehot: Optional[int] = None,
**kwargs: Any
) -> None:
if not SKLEARN_INSTALLED:
Expand Down Expand Up @@ -523,6 +534,7 @@ def __init__(
self.eval_metric = eval_metric
self.early_stopping_rounds = early_stopping_rounds
self.callbacks = callbacks
self.max_cat_to_onehot = max_cat_to_onehot
if kwargs:
self.kwargs = kwargs

Expand Down Expand Up @@ -801,8 +813,8 @@ def _duplicated(parameter: str) -> None:
_duplicated("callbacks")
callbacks = self.callbacks if self.callbacks is not None else callbacks

# lastly check categorical data support.
if self.enable_categorical and params.get("tree_method", None) != "gpu_hist":
tree_method = params.get("tree_method", None)
if self.enable_categorical and tree_method not in ("gpu_hist", "approx"):
raise ValueError(
"Experimental support for categorical data is not implemented for"
" current tree method yet."
Expand Down
1 change: 0 additions & 1 deletion src/common/hist_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
#include "random.h"
#include "column_matrix.h"
#include "quantile.h"
#include "./../tree/updater_quantile_hist.h"
#include "../data/gradient_index.h"

#if defined(XGBOOST_MM_PREFETCH_PRESENT)
Expand Down
6 changes: 3 additions & 3 deletions src/common/threading_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ class BlockedSpace2d {
template <typename Func>
void ParallelFor2d(const BlockedSpace2d& space, int nthreads, Func func) {
const size_t num_blocks_in_space = space.Size();
nthreads = std::min(nthreads, omp_get_max_threads());
nthreads = std::max(nthreads, 1);
CHECK_GE(nthreads, 1);

dmlc::OMPException exc;
#pragma omp parallel num_threads(nthreads)
Expand Down Expand Up @@ -277,9 +276,10 @@ inline int32_t OmpSetNumThreadsWithoutHT(int32_t* p_threads) {

inline int32_t OmpGetNumThreads(int32_t n_threads) {
if (n_threads <= 0) {
n_threads = omp_get_num_procs();
n_threads = std::min(omp_get_num_procs(), omp_get_max_threads());
}
n_threads = std::min(n_threads, OmpGetThreadLimit());
n_threads = std::max(n_threads, 1);
return n_threads;
}
} // namespace common
Expand Down
3 changes: 2 additions & 1 deletion src/gbm/gbtree.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ void GBTree::ConfigureUpdaters() {
// calling this function.
break;
case TreeMethod::kApprox:
tparam_.updater_seq = "grow_histmaker,prune";
// grow_histmaker,prune
tparam_.updater_seq = "grow_global_approx_histmaker";
break;
case TreeMethod::kExact:
tparam_.updater_seq = "grow_colmaker,prune";
Expand Down
2 changes: 1 addition & 1 deletion src/tree/param.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ struct TrainParam : public XGBoostParameter<TrainParam> {
enum TreeGrowPolicy { kDepthWise = 0, kLossGuide = 1 };
int grow_policy;

uint32_t max_cat_to_onehot{1};
uint32_t max_cat_to_onehot{4};

//----- the rest parameters are less important ----
// minimum amount of hessian(weight) allowed in a child
Expand Down
1 change: 1 addition & 0 deletions src/tree/tree_model.cc
Original file line number Diff line number Diff line change
Expand Up @@ -973,6 +973,7 @@ void RegTree::SaveCategoricalSplit(Json* p_out) const {
}
size_t size = categories.size() - begin;
categories_sizes.emplace_back(static_cast<Integer::Int>(size));
CHECK_NE(size, 0);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/tree/tree_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ DMLC_REGISTRY_LINK_TAG(updater_refresh);
DMLC_REGISTRY_LINK_TAG(updater_prune);
DMLC_REGISTRY_LINK_TAG(updater_quantile_hist);
DMLC_REGISTRY_LINK_TAG(updater_histmaker);
DMLC_REGISTRY_LINK_TAG(updater_approx);
DMLC_REGISTRY_LINK_TAG(updater_sync);
#ifdef XGBOOST_USE_CUDA
DMLC_REGISTRY_LINK_TAG(updater_gpu_hist);
Expand Down
Loading

0 comments on commit 904b787

Please sign in to comment.