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

[jvm-packages] [pyspark] Make QDM optional based on cuDF check #8471

Merged
merged 6 commits into from Nov 27, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 5 additions & 0 deletions python-package/xgboost/compat.py
Expand Up @@ -43,6 +43,11 @@ def lazy_isinstance(instance: Any, module: str, name: str) -> bool:
pandas_concat = None
PANDAS_INSTALLED = False


# cuDF
CUDF_INSTALLED = importlib.util.find_spec("cudf") is not None
WeichenXu123 marked this conversation as resolved.
Show resolved Hide resolved


# sklearn
try:
from sklearn.base import BaseEstimator as XGBModelBase
Expand Down
8 changes: 7 additions & 1 deletion python-package/xgboost/spark/core.py
Expand Up @@ -37,6 +37,7 @@

import xgboost
from xgboost import XGBClassifier, XGBRanker, XGBRegressor
from xgboost.compat import CUDF_INSTALLED

from .data import (
_read_csr_matrix_from_unwrapped_spark_vec,
Expand All @@ -56,6 +57,7 @@
HasEnableSparseDataOptim,
HasFeaturesCols,
HasQueryIdCol,
UseQuantileDMatrix,
WeichenXu123 marked this conversation as resolved.
Show resolved Hide resolved
)
from .utils import (
CommunicatorContext,
Expand Down Expand Up @@ -755,7 +757,11 @@ def _fit(self, dataset):
k: v for k, v in train_call_kwargs_params.items() if v is not None
}
dmatrix_kwargs = {k: v for k, v in dmatrix_kwargs.items() if v is not None}
use_qdm = booster_params.get("tree_method", None) in ("hist", "gpu_hist")

# If cuDF is not installed, then using DMatrix instead of QDM,
# because without cuDF, DMatrix performs better than QDM.
use_qdm = CUDF_INSTALLED and \
WeichenXu123 marked this conversation as resolved.
Show resolved Hide resolved
booster_params.get("tree_method", None) in ("hist", "gpu_hist")

def _train_booster(pandas_df_iter):
"""Takes in an RDD partition and outputs a booster for that partition after
Expand Down
4 changes: 2 additions & 2 deletions python-package/xgboost/spark/data.py
Expand Up @@ -5,7 +5,7 @@
import numpy as np
import pandas as pd
from scipy.sparse import csr_matrix
from xgboost.compat import concat
from xgboost.compat import CUDF_INSTALLED, concat
WeichenXu123 marked this conversation as resolved.
Show resolved Hide resolved

from xgboost import DataIter, DMatrix, QuantileDMatrix

Expand Down Expand Up @@ -81,7 +81,7 @@ def _fetch(self, data: Optional[Sequence[pd.DataFrame]]) -> Optional[pd.DataFram
if not data:
return None

if self._device_id is not None:
if self._device_id is not None and CUDF_INSTALLED:
import cudf # pylint: disable=import-error
import cupy as cp # pylint: disable=import-error

Expand Down