[Breaking] Rename Quantile DMatrix C API. (#7082)

The role of ProxyDMatrix is going beyond what it was designed.  Now it's used by both
QuantileDeviceDMatrix and inplace prediction.  After the refactoring of sparse DMatrix it
will also be used for external memory.  Renaming the C API to extract it from
QuantileDeviceDMatrix.
This commit is contained in:
Jiaming Yuan
2021-07-08 11:34:14 +08:00
committed by GitHub
parent c766f143ab
commit 5d7cdf2e36
5 changed files with 29 additions and 26 deletions

View File

@@ -322,6 +322,7 @@ class DataIter:
self._handle = _ProxyDMatrix()
self.exception = None
self.enable_categorical = False
self._allow_host = False
@property
def proxy(self):
@@ -349,12 +350,12 @@ class DataIter:
feature_types=None,
**kwargs
):
from .data import dispatch_device_quantile_dmatrix_set_data
from .data import _device_quantile_transform
data, feature_names, feature_types = _device_quantile_transform(
from .data import dispatch_proxy_set_data
from .data import _proxy_transform
data, feature_names, feature_types = _proxy_transform(
data, feature_names, feature_types, self.enable_categorical,
)
dispatch_device_quantile_dmatrix_set_data(self.proxy, data)
dispatch_proxy_set_data(self.proxy, data, self._allow_host)
self.proxy.set_info(
feature_names=feature_names,
feature_types=feature_types,
@@ -1009,18 +1010,18 @@ class _ProxyDMatrix(DMatrix):
interface = data.__cuda_array_interface__
interface_str = bytes(json.dumps(interface, indent=2), 'utf-8')
_check_call(
_LIB.XGDeviceQuantileDMatrixSetDataCudaArrayInterface(
_LIB.XGProxyDMatrixSetDataCudaArrayInterface(
self.handle,
interface_str
)
)
def _set_data_from_cuda_columnar(self, data):
'''Set data from CUDA columnar format.1'''
'''Set data from CUDA columnar format.'''
from .data import _cudf_array_interfaces
_, interfaces_str = _cudf_array_interfaces(data)
_check_call(
_LIB.XGDeviceQuantileDMatrixSetDataCudaColumnar(
_LIB.XGProxyDMatrixSetDataCudaColumnar(
self.handle,
interfaces_str
)

View File

@@ -775,7 +775,7 @@ class SingleBatchInternalIter(DataIter): # pylint: disable=R0902
self.it = 0
def _device_quantile_transform(data, feature_names, feature_types, enable_categorical):
def _proxy_transform(data, feature_names, feature_types, enable_categorical):
if _is_cudf_df(data) or _is_cudf_ser(data):
return _transform_cudf_df(
data, feature_names, feature_types, enable_categorical
@@ -788,8 +788,8 @@ def _device_quantile_transform(data, feature_names, feature_types, enable_catego
raise TypeError("Value type is not supported for data iterator:" + str(type(data)))
def dispatch_device_quantile_dmatrix_set_data(proxy: _ProxyDMatrix, data: Any) -> None:
'''Dispatch for DeviceQuantileDMatrix.'''
def dispatch_proxy_set_data(proxy: _ProxyDMatrix, data: Any, allow_host: bool) -> None:
"""Dispatch for DeviceQuantileDMatrix."""
if _is_cudf_df(data):
proxy._set_data_from_cuda_columnar(data) # pylint: disable=W0212
return
@@ -803,5 +803,7 @@ def dispatch_device_quantile_dmatrix_set_data(proxy: _ProxyDMatrix, data: Any) -
data = _transform_dlpack(data)
proxy._set_data_from_cuda_interface(data) # pylint: disable=W0212
return
# Part of https://github.com/dmlc/xgboost/pull/7070
assert allow_host is False, "host data is not yet supported."
raise TypeError('Value type is not supported for data iterator:' +
str(type(data)))