Speed up python test (#5752)

* Speed up tests

* Prevent DeviceQuantileDMatrix initialisation with numpy

* Use joblib.memory

* Use RandomState
This commit is contained in:
Rory Mitchell
2020-06-05 11:39:24 +12:00
committed by GitHub
parent cfc23c6a6b
commit 359023c0fa
5 changed files with 53 additions and 18 deletions

View File

@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-
import numpy as np
import xgboost as xgb
import unittest
import pytest
import sys
sys.path.append("tests/python")
import testing as tm
class TestDeviceQuantileDMatrix(unittest.TestCase):
def test_dmatrix_numpy_init(self):
data = np.random.randn(5, 5)
with pytest.raises(AssertionError, match='is not supported for DeviceQuantileDMatrix'):
dm = xgb.DeviceQuantileDMatrix(data, np.ones(5, dtype=np.float64))
@pytest.mark.skipif(**tm.no_cupy())
def test_dmatrix_cupy_init(self):
import cupy as cp
data = cp.random.randn(5, 5)
dm = xgb.DeviceQuantileDMatrix(data, cp.ones(5, dtype=np.float64))

View File

@@ -3,12 +3,11 @@ import pytest
import unittest
sys.path.append('tests/python/')
import test_linear # noqa: E402
import testing as tm # noqa: E402
import test_linear # noqa: E402
import testing as tm # noqa: E402
class TestGPULinear(unittest.TestCase):
datasets = ["Boston", "Digits", "Cancer", "Sparse regression"]
common_param = {
'booster': ['gblinear'],
@@ -16,7 +15,7 @@ class TestGPULinear(unittest.TestCase):
'eta': [0.5],
'top_k': [10],
'tolerance': [1e-5],
'alpha': [.005, .1],
'alpha': [.1],
'lambda': [0.005],
'coordinate_selection': ['cyclic', 'random', 'greedy']}
@@ -26,6 +25,6 @@ class TestGPULinear(unittest.TestCase):
parameters['gpu_id'] = [0]
for param in test_linear.parameter_combinations(parameters):
results = test_linear.run_suite(
param, 150, self.datasets, scale_features=True)
param, 100, self.datasets, scale_features=True)
test_linear.assert_regression_result(results, 1e-2)
test_linear.assert_classification_result(results)

View File

@@ -47,6 +47,7 @@ class TestGPU(unittest.TestCase):
device_dmatrix_datasets = ["Boston", "Cancer", "Digits"]
for param in test_param:
param['tree_method'] = 'gpu_hist'
gpu_results_device_dmatrix = run_suite(param, select_datasets=device_dmatrix_datasets,
DMatrixT=xgb.DeviceQuantileDMatrix,
dmatrix_params={'max_bin': param['max_bin']})