Copy data from Ellpack to GHist. (#8215)
This commit is contained in:
@@ -32,32 +32,41 @@ class TestDeviceQuantileDMatrix:
|
||||
xgb.DeviceQuantileDMatrix(data, cp.ones(5, dtype=np.float64))
|
||||
|
||||
@pytest.mark.skipif(**tm.no_cupy())
|
||||
def test_from_host(self) -> None:
|
||||
@pytest.mark.parametrize(
|
||||
"tree_method,max_bin", [
|
||||
("hist", 16), ("gpu_hist", 16), ("hist", 64), ("gpu_hist", 64)
|
||||
]
|
||||
)
|
||||
def test_interoperability(self, tree_method: str, max_bin: int) -> None:
|
||||
import cupy as cp
|
||||
n_samples = 64
|
||||
n_features = 3
|
||||
X, y, w = tm.make_batches(
|
||||
n_samples, n_features=n_features, n_batches=1, use_cupy=False
|
||||
)
|
||||
Xy = xgb.QuantileDMatrix(X[0], y[0], weight=w[0])
|
||||
booster_0 = xgb.train({"tree_method": "gpu_hist"}, Xy, num_boost_round=4)
|
||||
# from CPU
|
||||
Xy = xgb.QuantileDMatrix(X[0], y[0], weight=w[0], max_bin=max_bin)
|
||||
booster_0 = xgb.train(
|
||||
{"tree_method": tree_method, "max_bin": max_bin}, Xy, num_boost_round=4
|
||||
)
|
||||
|
||||
X[0] = cp.array(X[0])
|
||||
y[0] = cp.array(y[0])
|
||||
w[0] = cp.array(w[0])
|
||||
|
||||
Xy = xgb.QuantileDMatrix(X[0], y[0], weight=w[0])
|
||||
booster_1 = xgb.train({"tree_method": "gpu_hist"}, Xy, num_boost_round=4)
|
||||
# from GPU
|
||||
Xy = xgb.QuantileDMatrix(X[0], y[0], weight=w[0], max_bin=max_bin)
|
||||
booster_1 = xgb.train(
|
||||
{"tree_method": tree_method, "max_bin": max_bin}, Xy, num_boost_round=4
|
||||
)
|
||||
cp.testing.assert_allclose(
|
||||
booster_0.inplace_predict(X[0]), booster_1.inplace_predict(X[0])
|
||||
)
|
||||
|
||||
with pytest.raises(ValueError, match="not initialized with CPU"):
|
||||
# Training on CPU with GPU data is not supported.
|
||||
xgb.train({"tree_method": "hist"}, Xy, num_boost_round=4)
|
||||
|
||||
with pytest.raises(ValueError, match=r"Only.*hist.*"):
|
||||
xgb.train({"tree_method": "approx"}, Xy, num_boost_round=4)
|
||||
xgb.train(
|
||||
{"tree_method": "approx", "max_bin": max_bin}, Xy, num_boost_round=4
|
||||
)
|
||||
|
||||
@pytest.mark.skipif(**tm.no_cupy())
|
||||
def test_metainfo(self) -> None:
|
||||
|
||||
Reference in New Issue
Block a user