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

[dask] Improve documents. #6687

Merged
merged 3 commits into from
Feb 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 28 additions & 7 deletions doc/python/python_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,43 @@ Dask API
--------
.. automodule:: xgboost.dask

.. autofunction:: xgboost.dask.DaskDMatrix
.. autoclass:: xgboost.dask.DaskDMatrix
:members:
:inherited-members:
:show-inheritance:

.. autofunction:: xgboost.dask.DaskDeviceQuantileDMatrix
.. autoclass:: xgboost.dask.DaskDeviceQuantileDMatrix
:members:
:inherited-members:
:show-inheritance:

.. autofunction:: xgboost.dask.train

.. autofunction:: xgboost.dask.predict

.. autofunction:: xgboost.dask.inplace_predict

.. autofunction:: xgboost.dask.DaskXGBClassifier
.. autoclass:: xgboost.dask.DaskXGBClassifier
:members:
:inherited-members:
:show-inheritance:

.. autofunction:: xgboost.dask.DaskXGBRegressor
.. autoclass:: xgboost.dask.DaskXGBRegressor
:members:
:inherited-members:
:show-inheritance:

.. autofunction:: xgboost.dask.DaskXGBRanker
.. autoclass:: xgboost.dask.DaskXGBRanker
:members:
:inherited-members:
:show-inheritance:

.. autofunction:: xgboost.dask.DaskXGBRFRegressor
.. autoclass:: xgboost.dask.DaskXGBRFRegressor
:members:
:inherited-members:
:show-inheritance:

.. autofunction:: xgboost.dask.DaskXGBRFClassifier
.. autoclass:: xgboost.dask.DaskXGBRFClassifier
:members:
:inherited-members:
:show-inheritance:
51 changes: 34 additions & 17 deletions python-package/xgboost/dask.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# pylint: disable=too-many-arguments, too-many-locals, no-name-in-module
# pylint: disable=missing-class-docstring, invalid-name
# pylint: disable=too-many-lines, fixme
# pylint: disable=too-few-public-methods
# pylint: disable=import-error
"""Dask extensions for distributed training. See
https://xgboost.readthedocs.io/en/latest/tutorials/dask.html for simple
Expand Down Expand Up @@ -259,7 +260,7 @@ def __init__(
self.is_quantile: bool = False

self._init = client.sync(
self.map_local_data,
self._map_local_data,
client,
data,
label=label,
Expand All @@ -274,7 +275,7 @@ def __init__(
def __await__(self) -> Generator:
return self._init.__await__()

async def map_local_data(
async def _map_local_data(
self,
client: "distributed.Client",
data: _DaskCollection,
Expand Down Expand Up @@ -393,7 +394,7 @@ def append_meta(

return self

def create_fn_args(self, worker_addr: str) -> Dict[str, Any]:
def _create_fn_args(self, worker_addr: str) -> Dict[str, Any]:
'''Create a dictionary of objects that can be pickled for function
arguments.

Expand Down Expand Up @@ -627,8 +628,8 @@ def __init__(
self.max_bin = max_bin
self.is_quantile = True

def create_fn_args(self, worker_addr: str) -> Dict[str, Any]:
args = super().create_fn_args(worker_addr)
def _create_fn_args(self, worker_addr: str) -> Dict[str, Any]:
args = super()._create_fn_args(worker_addr)
args["max_bin"] = self.max_bin
return args

Expand Down Expand Up @@ -864,18 +865,22 @@ def dispatched_train(
futures = []
for i, worker_addr in enumerate(workers):
if evals:
evals_per_worker = [(e.create_fn_args(worker_addr), name, id(e))
# pylint: disable=protected-access
evals_per_worker = [(e._create_fn_args(worker_addr), name, id(e))
for e, name in evals]
else:
evals_per_worker = []
f = client.submit(dispatched_train,
worker_addr,
_rabit_args,
dtrain.create_fn_args(workers[i]),
id(dtrain),
evals_per_worker,
pure=False,
workers=[worker_addr])
f = client.submit(
dispatched_train,
worker_addr,
_rabit_args,
# pylint: disable=protected-access
dtrain._create_fn_args(workers[i]),
id(dtrain),
evals_per_worker,
pure=False,
workers=[worker_addr]
)
futures.append(f)

results = await client.gather(futures)
Expand Down Expand Up @@ -1755,7 +1760,11 @@ def _argmax(x: Any) -> Any:


@xgboost_model_doc(
"Implementation of the Scikit-Learn API for XGBoost Ranking.",
"""Implementation of the Scikit-Learn API for XGBoost Ranking.

.. versionadded:: 1.4.0

""",
["estimators", "model"],
end_note="""
Note
Expand Down Expand Up @@ -1868,7 +1877,11 @@ def fit(


@xgboost_model_doc(
"Implementation of the Scikit-Learn API for XGBoost Random Forest Regressor.",
"""Implementation of the Scikit-Learn API for XGBoost Random Forest Regressor.

.. versionadded:: 1.4.0

""",
["model", "objective"],
extra_parameters="""
n_estimators : int
Expand Down Expand Up @@ -1904,7 +1917,11 @@ def get_num_boosting_rounds(self) -> int:


@xgboost_model_doc(
"Implementation of the Scikit-Learn API for XGBoost Random Forest Classifier.",
"""Implementation of the Scikit-Learn API for XGBoost Random Forest Classifier.

.. versionadded:: 1.4.0

""",
["model", "objective"],
extra_parameters="""
n_estimators : int
Expand Down
12 changes: 9 additions & 3 deletions tests/python-gpu/test_gpu_with_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,15 @@ def worker_fn(worker_addr: str, data_ref: Dict) -> None:

futures = []
for i in range(len(workers)):
futures.append(client.submit(worker_fn, workers[i],
m.create_fn_args(workers[i]), pure=False,
workers=[workers[i]]))
futures.append(
client.submit(
worker_fn,
workers[i],
m._create_fn_args(workers[i]),
pure=False,
workers=[workers[i]]
)
)
client.gather(futures)

def test_interface_consistency(self) -> None:
Expand Down
9 changes: 6 additions & 3 deletions tests/python/test_with_dask.py
Original file line number Diff line number Diff line change
Expand Up @@ -1046,9 +1046,12 @@ def worker_fn(worker_addr: str, data_ref: Dict) -> None:

futures = []
for i in range(len(workers)):
futures.append(client.submit(worker_fn, workers[i],
m.create_fn_args(workers[i]), pure=False,
workers=[workers[i]]))
futures.append(
client.submit(
worker_fn, workers[i],
m._create_fn_args(workers[i]), pure=False,
workers=[workers[i]])
)
client.gather(futures)

has_what = client.has_what()
Expand Down