From d1338b7ff1bbeb5e8dac3d8d2a7f25b9a31a4a90 Mon Sep 17 00:00:00 2001 From: Hyunsu Cho Date: Mon, 22 Jan 2024 22:04:09 -0800 Subject: [PATCH 1/5] [CI] Inject test failure --- tests/python/test_basic.py | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/tests/python/test_basic.py b/tests/python/test_basic.py index cdc571a916df..828be9f4564d 100644 --- a/tests/python/test_basic.py +++ b/tests/python/test_basic.py @@ -23,42 +23,7 @@ def test_compat(self): assert not lazy_isinstance(a, "numpy", "dataframe") def test_basic(self): - dtrain, dtest = tm.load_agaricus(__file__) - param = {"max_depth": 2, "eta": 1, "objective": "binary:logistic"} - # specify validations set to watch performance - watchlist = [(dtrain, "train")] - num_round = 2 - bst = xgb.train(param, dtrain, num_round, evals=watchlist, verbose_eval=True) - - preds = bst.predict(dtrain) - labels = dtrain.get_label() - err = sum( - 1 for i in range(len(preds)) if int(preds[i] > 0.5) != labels[i] - ) / float(len(preds)) - # error must be smaller than 10% - assert err < 0.1 - - preds = bst.predict(dtest) - labels = dtest.get_label() - err = sum( - 1 for i in range(len(preds)) if int(preds[i] > 0.5) != labels[i] - ) / float(len(preds)) - # error must be smaller than 10% - assert err < 0.1 - - with tempfile.TemporaryDirectory() as tmpdir: - dtest_path = os.path.join(tmpdir, "dtest.dmatrix") - # save dmatrix into binary buffer - dtest.save_binary(dtest_path) - # save model - model_path = os.path.join(tmpdir, "model.ubj") - bst.save_model(model_path) - # load model and data in - bst2 = xgb.Booster(model_file=model_path) - dtest2 = xgb.DMatrix(dtest_path) - preds2 = bst2.predict(dtest2) - # assert they are the same - assert np.sum(np.abs(preds2 - preds)) == 0 + assert False def test_metric_config(self): # Make sure that the metric configuration happens in booster so the string From b04ce437a59592d839b0bfb3d6f8b3eb7382db98 Mon Sep 17 00:00:00 2001 From: Hyunsu Cho Date: Tue, 23 Jan 2024 14:12:41 -0800 Subject: [PATCH 2/5] Explicitly check error code from pytest --- tests/buildkite/test-win64-gpu.ps1 | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/buildkite/test-win64-gpu.ps1 b/tests/buildkite/test-win64-gpu.ps1 index fcc6e8436d47..95a51b50228d 100644 --- a/tests/buildkite/test-win64-gpu.ps1 +++ b/tests/buildkite/test-win64-gpu.ps1 @@ -32,6 +32,8 @@ Foreach-Object { Write-Host "--- Run Python tests" python -X faulthandler -m pytest -v -s -rxXs --fulltrace tests/python +if ($LASTEXITCODE -ne 0) { throw "Last command failed" } Write-Host "--- Run Python tests with GPU" python -X faulthandler -m pytest -v -s -rxXs --fulltrace -m "(not slow) and (not mgpu)"` tests/python-gpu +if ($LASTEXITCODE -ne 0) { throw "Last command failed" } From 4feedb8ccddeda636699781a810ae168f32989be Mon Sep 17 00:00:00 2001 From: Hyunsu Cho Date: Tue, 23 Jan 2024 15:41:02 -0800 Subject: [PATCH 3/5] Revert "[CI] Inject test failure" This reverts commit d1338b7ff1bbeb5e8dac3d8d2a7f25b9a31a4a90. --- tests/python/test_basic.py | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/tests/python/test_basic.py b/tests/python/test_basic.py index 828be9f4564d..cdc571a916df 100644 --- a/tests/python/test_basic.py +++ b/tests/python/test_basic.py @@ -23,7 +23,42 @@ def test_compat(self): assert not lazy_isinstance(a, "numpy", "dataframe") def test_basic(self): - assert False + dtrain, dtest = tm.load_agaricus(__file__) + param = {"max_depth": 2, "eta": 1, "objective": "binary:logistic"} + # specify validations set to watch performance + watchlist = [(dtrain, "train")] + num_round = 2 + bst = xgb.train(param, dtrain, num_round, evals=watchlist, verbose_eval=True) + + preds = bst.predict(dtrain) + labels = dtrain.get_label() + err = sum( + 1 for i in range(len(preds)) if int(preds[i] > 0.5) != labels[i] + ) / float(len(preds)) + # error must be smaller than 10% + assert err < 0.1 + + preds = bst.predict(dtest) + labels = dtest.get_label() + err = sum( + 1 for i in range(len(preds)) if int(preds[i] > 0.5) != labels[i] + ) / float(len(preds)) + # error must be smaller than 10% + assert err < 0.1 + + with tempfile.TemporaryDirectory() as tmpdir: + dtest_path = os.path.join(tmpdir, "dtest.dmatrix") + # save dmatrix into binary buffer + dtest.save_binary(dtest_path) + # save model + model_path = os.path.join(tmpdir, "model.ubj") + bst.save_model(model_path) + # load model and data in + bst2 = xgb.Booster(model_file=model_path) + dtest2 = xgb.DMatrix(dtest_path) + preds2 = bst2.predict(dtest2) + # assert they are the same + assert np.sum(np.abs(preds2 - preds)) == 0 def test_metric_config(self): # Make sure that the metric configuration happens in booster so the string From 12cbf77ae72cf85f589552a7b990342dde6dc1c6 Mon Sep 17 00:00:00 2001 From: Hyunsu Cho Date: Tue, 23 Jan 2024 19:12:07 -0800 Subject: [PATCH 4/5] Add missing skip markers --- tests/python-gpu/test_gpu_prediction.py | 1 + tests/python-gpu/test_gpu_with_sklearn.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/python-gpu/test_gpu_prediction.py b/tests/python-gpu/test_gpu_prediction.py index ec7c45ca248a..a1bc13cb8ec8 100644 --- a/tests/python-gpu/test_gpu_prediction.py +++ b/tests/python-gpu/test_gpu_prediction.py @@ -152,6 +152,7 @@ def test_sklearn(self): @pytest.mark.parametrize("device", ["cpu", "cuda"]) @pytest.mark.skipif(**tm.no_cupy()) + @pytest.mark.skipif(**tm.no_cudf()) def test_inplace_predict_device_type(self, device: str) -> None: """Test inplace predict with different device and data types. diff --git a/tests/python-gpu/test_gpu_with_sklearn.py b/tests/python-gpu/test_gpu_with_sklearn.py index 650c0a0470d1..a01e79ccc88a 100644 --- a/tests/python-gpu/test_gpu_with_sklearn.py +++ b/tests/python-gpu/test_gpu_with_sklearn.py @@ -249,7 +249,7 @@ def wrong_shape_3(labels, predt): clf.fit(X, y) -@pytest.mark.skipif(**tm.no_pandas()) +@pytest.mark.skipif(**tm.no_cudf()) def test_ranking_qid_df(): import cudf From 5f0c87eb8db94b68da94acece90b8bb1d619a086 Mon Sep 17 00:00:00 2001 From: Jiaming Yuan Date: Thu, 25 Jan 2024 13:53:12 +0800 Subject: [PATCH 5/5] Windows build. --- src/data/device_adapter.cuh | 8 +++----- src/data/ellpack_page.cu | 4 ++-- src/data/simple_dmatrix.cuh | 4 ++-- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/data/device_adapter.cuh b/src/data/device_adapter.cuh index 67ceb92f2163..a5156f585441 100644 --- a/src/data/device_adapter.cuh +++ b/src/data/device_adapter.cuh @@ -260,12 +260,10 @@ bool NoInfInData(AdapterBatchT const& batch, IsValidFunctor is_valid) { auto counting = thrust::make_counting_iterator(0llu); auto value_iter = dh::MakeTransformIterator(counting, [=] XGBOOST_DEVICE(std::size_t idx) { auto v = batch.GetElement(idx).value; - if (!is_valid(v)) { - // discard the invalid elements. - return true; + if (is_valid(v) && isinf(v)) { + return false; } - // check that there's no inf in data. - return !std::isinf(v); + return true; }); dh::XGBCachingDeviceAllocator alloc; // The default implementation in thrust optimizes any_of/none_of/all_of by using small diff --git a/src/data/ellpack_page.cu b/src/data/ellpack_page.cu index 44b9c8dd6c0b..c60fe83893bb 100644 --- a/src/data/ellpack_page.cu +++ b/src/data/ellpack_page.cu @@ -1,5 +1,5 @@ /** - * Copyright 2019-2023 by XGBoost contributors + * Copyright 2019-2024, XGBoost contributors */ #include #include @@ -13,7 +13,7 @@ #include "../common/hist_util.cuh" #include "../common/transform_iterator.h" // MakeIndexTransformIter #include "./ellpack_page.cuh" -#include "device_adapter.cuh" // for HasInfInData +#include "device_adapter.cuh" // for NoInfInData #include "ellpack_page.h" #include "gradient_index.h" #include "xgboost/data.h" diff --git a/src/data/simple_dmatrix.cuh b/src/data/simple_dmatrix.cuh index 47d736050930..528bea8be80a 100644 --- a/src/data/simple_dmatrix.cuh +++ b/src/data/simple_dmatrix.cuh @@ -1,5 +1,5 @@ /** - * Copyright 2019-2023 by XGBoost Contributors + * Copyright 2019-2024, XGBoost Contributors * \file simple_dmatrix.cuh */ #ifndef XGBOOST_DATA_SIMPLE_DMATRIX_CUH_ @@ -11,7 +11,7 @@ #include "../common/device_helpers.cuh" #include "../common/error_msg.h" // for InfInData -#include "device_adapter.cuh" // for HasInfInData +#include "device_adapter.cuh" // for NoInfInData namespace xgboost::data {