Define the new device parameter. (#9362)
This commit is contained in:
@@ -65,16 +65,20 @@ class TestGPUBasicModels:
|
||||
@pytest.mark.skipif(**tm.no_sklearn())
|
||||
def test_invalid_gpu_id(self):
|
||||
from sklearn.datasets import load_digits
|
||||
|
||||
X, y = load_digits(return_X_y=True)
|
||||
# should pass with invalid gpu id
|
||||
cls1 = xgb.XGBClassifier(tree_method='gpu_hist', gpu_id=9999)
|
||||
cls1 = xgb.XGBClassifier(tree_method="gpu_hist", gpu_id=9999)
|
||||
cls1.fit(X, y)
|
||||
# should throw error with fail_on_invalid_gpu_id enabled
|
||||
cls2 = xgb.XGBClassifier(
|
||||
tree_method='gpu_hist', gpu_id=9999, fail_on_invalid_gpu_id=True
|
||||
tree_method="gpu_hist", gpu_id=9999, fail_on_invalid_gpu_id=True
|
||||
)
|
||||
try:
|
||||
with pytest.raises(ValueError, match="ordinal 9999 is invalid"):
|
||||
cls2.fit(X, y)
|
||||
|
||||
cls2 = xgb.XGBClassifier(
|
||||
tree_method="hist", device="cuda:9999", fail_on_invalid_gpu_id=True
|
||||
)
|
||||
with pytest.raises(ValueError, match="ordinal 9999 is invalid"):
|
||||
cls2.fit(X, y)
|
||||
assert False, "Should have failed with with fail_on_invalid_gpu_id enabled"
|
||||
except xgb.core.XGBoostError as err:
|
||||
assert "gpu_id 9999 is invalid" in str(err)
|
||||
|
||||
Reference in New Issue
Block a user