Skip to content

Commit ce0382d

Browse files
authored
[CI] Refactor tests to reduce CI time. (dmlc#8312)
1 parent 39afdac commit ce0382d

19 files changed

+95
-122
lines changed

demo/guide-python/sklearn_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@
5050
print("Parameter optimization")
5151
xgb_model = xgb.XGBRegressor(n_jobs=1)
5252
clf = GridSearchCV(xgb_model,
53-
{'max_depth': [2, 4, 6],
54-
'n_estimators': [50, 100, 200]}, verbose=1, n_jobs=1)
53+
{'max_depth': [2, 4],
54+
'n_estimators': [50, 100]}, verbose=1, n_jobs=1, cv=3)
5555
clf.fit(X, y)
5656
print(clf.best_score_)
5757
print(clf.best_params_)

tests/ci_build/Dockerfile.gpu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ RUN \
2424
mamba create -n gpu_test -c rapidsai-nightly -c rapidsai -c nvidia -c conda-forge -c defaults \
2525
python=3.9 cudf=$RAPIDS_VERSION_ARG* rmm=$RAPIDS_VERSION_ARG* cudatoolkit=$CUDA_VERSION_ARG \
2626
dask dask-cuda=$RAPIDS_VERSION_ARG* dask-cudf=$RAPIDS_VERSION_ARG* cupy \
27-
numpy pytest scipy scikit-learn pandas matplotlib wheel python-kubernetes urllib3 graphviz hypothesis \
27+
numpy pytest pytest-timeout scipy scikit-learn pandas matplotlib wheel python-kubernetes urllib3 graphviz hypothesis \
2828
pyspark cloudpickle cuda-python=11.7.0 && \
2929
mamba clean --all && \
3030
conda run --no-capture-output -n gpu_test pip install buildkite-test-collector

tests/ci_build/conda_env/cpu_test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ dependencies:
2222
- sh
2323
- mock
2424
- pytest
25+
- pytest-timeout
2526
- pytest-cov
2627
- python-kubernetes
2728
- urllib3

tests/python-gpu/test_gpu_data_iterator.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@
55
import sys
66

77
sys.path.append("tests/python")
8-
from test_data_iterator import SingleBatch, make_batches
98
from test_data_iterator import test_single_batch as cpu_single_batch
109
from test_data_iterator import run_data_iterator
11-
from testing import IteratorForTest, no_cupy
10+
from testing import no_cupy
1211

1312

1413
def test_gpu_single_batch() -> None:
@@ -21,16 +20,14 @@ def test_gpu_single_batch() -> None:
2120
strategies.integers(1, 7),
2221
strategies.integers(0, 8),
2322
strategies.booleans(),
23+
strategies.booleans(),
2424
)
25-
@settings(deadline=None, print_blob=True)
25+
@settings(deadline=None, max_examples=10, print_blob=True)
2626
def test_gpu_data_iterator(
27-
n_samples_per_batch: int, n_features: int, n_batches: int, subsample: bool
27+
n_samples_per_batch: int, n_features: int, n_batches: int, subsample: bool, use_cupy: bool
2828
) -> None:
2929
run_data_iterator(
30-
n_samples_per_batch, n_features, n_batches, "gpu_hist", subsample, True
31-
)
32-
run_data_iterator(
33-
n_samples_per_batch, n_features, n_batches, "gpu_hist", subsample, False
30+
n_samples_per_batch, n_features, n_batches, "gpu_hist", subsample, use_cupy
3431
)
3532

3633

tests/python-gpu/test_gpu_linear.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import testing as tm
77

88

9+
pytestmark = pytest.mark.timeout(10)
10+
911
parameter_strategy = strategies.fixed_dictionaries({
1012
'booster': strategies.just('gblinear'),
1113
'eta': strategies.floats(0.01, 0.25),
@@ -30,7 +32,7 @@ def train_result(param, dmat, num_rounds):
3032
class TestGPULinear:
3133
@given(parameter_strategy, strategies.integers(10, 50),
3234
tm.dataset_strategy)
33-
@settings(deadline=None, print_blob=True)
35+
@settings(deadline=None, max_examples=20, print_blob=True)
3436
def test_gpu_coordinate(self, param, num_rounds, dataset):
3537
assume(len(dataset.y) > 0)
3638
param['updater'] = 'gpu_coord_descent'
@@ -49,7 +51,7 @@ def test_gpu_coordinate(self, param, num_rounds, dataset):
4951
strategies.floats(1e-5, 0.8),
5052
strategies.floats(1e-5, 0.8)
5153
)
52-
@settings(deadline=None, print_blob=True)
54+
@settings(deadline=None, max_examples=20, print_blob=True)
5355
def test_gpu_coordinate_regularised(self, param, num_rounds, dataset, alpha, lambd):
5456
assume(len(dataset.y) > 0)
5557
param['updater'] = 'gpu_coord_descent'

tests/python-gpu/test_gpu_pickling.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
model_path = './model.pkl'
1616

1717

18+
pytestmark = pytest.mark.timeout(30)
19+
1820
def build_dataset():
1921
N = 10
2022
x = np.linspace(0, N*N, N*N)
@@ -65,6 +67,7 @@ def run_pickling(self, bst) -> None:
6567
assert status == 0
6668
os.remove(model_path)
6769

70+
# TODO: This test is too slow
6871
@pytest.mark.skipif(**tm.no_sklearn())
6972
def test_pickling(self):
7073
x, y = build_dataset()

tests/python-gpu/test_gpu_prediction.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def noop(*args, **kwargs):
3232
'num_parallel_tree': strategies.sampled_from([1, 4]),
3333
})
3434

35+
pytestmark = pytest.mark.timeout(20)
3536

3637
class TestGPUPredict:
3738
def test_predict(self):
@@ -264,7 +265,7 @@ def predict_df(x):
264265

265266
@given(strategies.integers(1, 10),
266267
tm.dataset_strategy, shap_parameter_strategy)
267-
@settings(deadline=None, print_blob=True)
268+
@settings(deadline=None, max_examples=20, print_blob=True)
268269
def test_shap(self, num_rounds, dataset, param):
269270
if dataset.name.endswith("-l1"): # not supported by the exact tree method
270271
return
@@ -280,7 +281,7 @@ def test_shap(self, num_rounds, dataset, param):
280281

281282
@given(strategies.integers(1, 10),
282283
tm.dataset_strategy, shap_parameter_strategy)
283-
@settings(deadline=None, max_examples=20, print_blob=True)
284+
@settings(deadline=None, max_examples=10, print_blob=True)
284285
def test_shap_interactions(self, num_rounds, dataset, param):
285286
if dataset.name.endswith("-l1"): # not supported by the exact tree method
286287
return
@@ -333,14 +334,14 @@ def run_predict_leaf_booster(self, param, num_rounds, dataset):
333334
np.testing.assert_equal(cpu_leaf, gpu_leaf)
334335

335336
@given(predict_parameter_strategy, tm.dataset_strategy)
336-
@settings(deadline=None, print_blob=True)
337+
@settings(deadline=None, max_examples=20, print_blob=True)
337338
def test_predict_leaf_gbtree(self, param, dataset):
338339
param['booster'] = 'gbtree'
339340
param['tree_method'] = 'gpu_hist'
340341
self.run_predict_leaf_booster(param, 10, dataset)
341342

342343
@given(predict_parameter_strategy, tm.dataset_strategy)
343-
@settings(deadline=None, print_blob=True)
344+
@settings(deadline=None, max_examples=20, print_blob=True)
344345
def test_predict_leaf_dart(self, param, dataset):
345346
param['booster'] = 'dart'
346347
param['tree_method'] = 'gpu_hist'
@@ -351,7 +352,7 @@ def test_predict_leaf_dart(self, param, dataset):
351352
@given(df=data_frames([column('x0', elements=strategies.integers(min_value=0, max_value=3)),
352353
column('x1', elements=strategies.integers(min_value=0, max_value=5))],
353354
index=range_indexes(min_size=20, max_size=50)))
354-
@settings(deadline=None, print_blob=True)
355+
@settings(deadline=None, max_examples=20, print_blob=True)
355356
def test_predict_categorical_split(self, df):
356357
from sklearn.metrics import mean_squared_error
357358

tests/python-gpu/test_gpu_ranking.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66
import urllib.request
77
import zipfile
88
import sys
9+
import pytest
910
sys.path.append("tests/python")
1011

1112
import testing as tm # noqa
1213

14+
pytestmark = pytest.mark.timeout(10)
1315

1416
class TestRanking:
1517
@classmethod
@@ -96,7 +98,7 @@ def __test_training_with_rank_objective(cls, rank_objective, metric_name, tolera
9698
# specify validations set to watch performance
9799
watchlist = [(cls.dtest, 'eval'), (cls.dtrain, 'train')]
98100

99-
num_trees = 2500
101+
num_trees = 100
100102
check_metric_improvement_rounds = 10
101103

102104
evals_result = {}

tests/python-gpu/test_gpu_spark/test_gpu_spark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
sys.path.append("tests/python")
88
import testing as tm
99

10-
if tm.no_dask()["condition"]:
10+
if tm.no_spark()["condition"]:
1111
pytest.skip(msg=tm.no_spark()["reason"], allow_module_level=True)
1212
if sys.platform.startswith("win"):
1313
pytest.skip("Skipping PySpark tests on Windows", allow_module_level=True)

tests/python-gpu/test_gpu_updaters.py

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from typing import Dict, Any
22
import numpy as np
33
import sys
4-
import gc
54
import pytest
65
import xgboost as xgb
76
from hypothesis import given, strategies, assume, settings, note
@@ -10,6 +9,7 @@
109
import testing as tm
1110
import test_updaters as test_up
1211

12+
pytestmark = pytest.mark.timeout(30)
1313

1414
parameter_strategy = strategies.fixed_dictionaries({
1515
'max_depth': strategies.integers(0, 11),
@@ -46,7 +46,7 @@ class TestGPUUpdaters:
4646
cputest = test_up.TestTreeMethod()
4747

4848
@given(parameter_strategy, strategies.integers(1, 20), tm.dataset_strategy)
49-
@settings(deadline=None, print_blob=True)
49+
@settings(deadline=None, max_examples=50, print_blob=True)
5050
def test_gpu_hist(self, param, num_rounds, dataset):
5151
param["tree_method"] = "gpu_hist"
5252
param = dataset.set_params(param)
@@ -73,7 +73,7 @@ def test_sparse(self, dataset):
7373

7474
@given(strategies.integers(10, 400), strategies.integers(3, 8),
7575
strategies.integers(1, 2), strategies.integers(4, 7))
76-
@settings(deadline=None, print_blob=True)
76+
@settings(deadline=None, max_examples=20, print_blob=True)
7777
@pytest.mark.skipif(**tm.no_pandas())
7878
def test_categorical_ohe(self, rows, cols, rounds, cats):
7979
self.cputest.run_categorical_ohe(rows, cols, rounds, cats, "gpu_hist")
@@ -85,7 +85,7 @@ def test_categorical_ohe(self, rows, cols, rounds, cats):
8585
test_up.cat_parameter_strategy,
8686
strategies.integers(4, 32),
8787
)
88-
@settings(deadline=None, print_blob=True)
88+
@settings(deadline=None, max_examples=20, print_blob=True)
8989
@pytest.mark.skipif(**tm.no_pandas())
9090
def test_categorical(
9191
self,
@@ -106,7 +106,7 @@ def test_categorical(
106106
test_up.hist_parameter_strategy,
107107
test_up.cat_parameter_strategy,
108108
)
109-
@settings(deadline=None, print_blob=True)
109+
@settings(deadline=None, max_examples=10, print_blob=True)
110110
def test_categorical_ames_housing(
111111
self,
112112
hist_parameters: Dict[str, Any],
@@ -125,7 +125,7 @@ def test_categorical_ames_housing(
125125
strategies.integers(3, 8),
126126
strategies.integers(4, 7)
127127
)
128-
@settings(deadline=None, print_blob=True)
128+
@settings(deadline=None, max_examples=20, print_blob=True)
129129
@pytest.mark.skipif(**tm.no_pandas())
130130
def test_categorical_missing(self, rows, cols, cats):
131131
self.cputest.run_categorical_missing(rows, cols, cats, "gpu_hist")
@@ -149,7 +149,7 @@ def test_invalid_category(self):
149149
@pytest.mark.skipif(**tm.no_cupy())
150150
@given(parameter_strategy, strategies.integers(1, 20),
151151
tm.dataset_strategy)
152-
@settings(deadline=None, print_blob=True)
152+
@settings(deadline=None, max_examples=20, print_blob=True)
153153
def test_gpu_hist_device_dmatrix(self, param, num_rounds, dataset):
154154
# We cannot handle empty dataset yet
155155
assume(len(dataset.y) > 0)
@@ -159,9 +159,9 @@ def test_gpu_hist_device_dmatrix(self, param, num_rounds, dataset):
159159
note(result)
160160
assert tm.non_increasing(result['train'][dataset.metric], tolerance=1e-3)
161161

162-
@given(parameter_strategy, strategies.integers(1, 20),
162+
@given(parameter_strategy, strategies.integers(1, 3),
163163
tm.dataset_strategy)
164-
@settings(deadline=None, print_blob=True)
164+
@settings(deadline=None, max_examples=10, print_blob=True)
165165
def test_external_memory(self, param, num_rounds, dataset):
166166
if dataset.name.endswith("-l1"):
167167
return
@@ -172,7 +172,6 @@ def test_external_memory(self, param, num_rounds, dataset):
172172
m = dataset.get_external_dmat()
173173
external_result = train_result(param, m, num_rounds)
174174
del m
175-
gc.collect()
176175
assert tm.non_increasing(external_result['train'][dataset.metric])
177176

178177
def test_empty_dmatrix_prediction(self):

0 commit comments

Comments
 (0)