mitigate flaky test with distributed l1 error. (#9499)

This commit is contained in:
Jiaming Yuan 2023-08-22 13:46:35 +08:00 committed by GitHub
parent 044fea1281
commit 302bbdc958
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,7 +18,7 @@ import numpy as np
import pytest import pytest
import scipy import scipy
import sklearn import sklearn
from hypothesis import HealthCheck, given, note, settings from hypothesis import HealthCheck, assume, given, note, settings
from sklearn.datasets import make_classification, make_regression from sklearn.datasets import make_classification, make_regression
import xgboost as xgb import xgboost as xgb
@ -1462,10 +1462,9 @@ class TestWithDask:
params["tree_method"] = tree_method params["tree_method"] = tree_method
params["debug_synchronize"] = True params["debug_synchronize"] = True
params = dataset.set_params(params) params = dataset.set_params(params)
# It doesn't make sense to distribute a completely
# empty dataset. # It doesn't make sense to distribute a completely empty dataset.
if dataset.X.shape[0] == 0: assume(dataset.X.shape[0] != 0)
return
chunk = 128 chunk = 128
y_chunk = chunk if len(dataset.y.shape) == 1 else (chunk, dataset.y.shape[1]) y_chunk = chunk if len(dataset.y.shape) == 1 else (chunk, dataset.y.shape[1])
@ -1498,8 +1497,8 @@ class TestWithDask:
# See note on `ObjFunction::UpdateTreeLeaf`. # See note on `ObjFunction::UpdateTreeLeaf`.
update_leaf = dataset.name.endswith("-l1") update_leaf = dataset.name.endswith("-l1")
if update_leaf and len(history) >= 2: if update_leaf and (is_stump() or minimum_bin()):
assert history[0] >= history[-1] assert tm.non_increasing(history, tolerance=1e-2)
return return
elif minimum_bin() and is_stump(): elif minimum_bin() and is_stump():
assert tm.non_increasing(history, tolerance=1e-3) assert tm.non_increasing(history, tolerance=1e-3)
@ -1508,7 +1507,7 @@ class TestWithDask:
# Make sure that it's decreasing # Make sure that it's decreasing
if is_stump(): if is_stump():
# we might have already got the best score with base_score. # we might have already got the best score with base_score.
assert history[-1] <= history[0] assert history[-1] <= history[0] + 1e-3
else: else:
assert history[-1] < history[0] assert history[-1] < history[0]