Skip to content
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

[WIP][doc] Add document for the improved external memory support. #10817

Closed
wants to merge 1 commit into from
Closed
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
49 changes: 37 additions & 12 deletions demo/guide-python/external_memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

See :doc:`the tutorial </tutorials/external_memory>` for more details.

.. versionchanged:: 3.0.0

Added :py:class:`xgboost.ExtMemQuantileDMatrix`.

"""

import os
Expand Down Expand Up @@ -78,25 +82,46 @@ def reset(self) -> None:
self._it = 0


def main(tmpdir: str) -> xgboost.Booster:
# generate some random data for demo
files = make_batches(1024, 17, 31, tmpdir)
it = Iterator(files)
# For non-data arguments, specify it here once instead of passing them by the `next`
# method.
missing = np.nan
Xy = xgboost.DMatrix(it, missing=missing, enable_categorical=False)
def hist_train(it: Iterator) -> None:
"""The hist tree method can use a special data structure `ExtMemQuantileDMatrix` for
faster initialization and lower memory usage.

# ``approx`` is also supported, but less efficient due to sketching. GPU behaves
# differently than CPU tree methods as it uses a hybrid approach. See tutorial in
# doc for details.
.. versionadded:: 3.0.0

"""
Xy = xgboost.ExtMemQuantileDMatrix(it, missing=np.nan, enable_categorical=False)
booster = xgboost.train(
{"tree_method": "hist", "max_depth": 4},
Xy,
evals=[(Xy, "Train")],
num_boost_round=10,
)
return booster
booster.predict(Xy)


def approx_train(it: Iterator) -> None:
# For non-data arguments, specify it here once instead of passing them by the `next`
# method.
Xy = xgboost.DMatrix(it, missing=np.nan, enable_categorical=False)
# ``approx`` is also supported, but less efficient due to sketching.
booster = xgboost.train(
{"tree_method": "approx", "max_depth": 4},
Xy,
evals=[(Xy, "Train")],
num_boost_round=10,
)
booster.predict(Xy)


def main(tmpdir: str) -> None:
# generate some random data for demo
files = make_batches(
n_samples_per_batch=1024, n_features=17, n_batches=31, tmpdir=tmpdir
)
it = Iterator(files)

hist_train(it)
approx_train(it)


if __name__ == "__main__":
Expand Down
Loading