[breaking] Remove the predictor param, allow fallback to prediction using DMatrix. (#9129)
- A `DeviceOrd` struct is implemented to indicate the device. It will eventually replace the `gpu_id` parameter. - The `predictor` parameter is removed. - Fallback to `DMatrix` when `inplace_predict` is not available. - The heuristic for choosing a predictor is only used during training.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
'''Loading a pickled model generated by test_pickling.py, only used by
|
||||
`test_gpu_with_dask.py`'''
|
||||
"""Loading a pickled model generated by test_pickling.py, only used by
|
||||
`test_gpu_with_dask.py`"""
|
||||
import json
|
||||
import os
|
||||
|
||||
@@ -12,9 +12,9 @@ from xgboost import testing as tm
|
||||
|
||||
|
||||
class TestLoadPickle:
|
||||
def test_load_pkl(self):
|
||||
'''Test whether prediction is correct.'''
|
||||
assert os.environ['CUDA_VISIBLE_DEVICES'] == '-1'
|
||||
def test_load_pkl(self) -> None:
|
||||
"""Test whether prediction is correct."""
|
||||
assert os.environ["CUDA_VISIBLE_DEVICES"] == "-1"
|
||||
bst = load_pickle(model_path)
|
||||
x, y = build_dataset()
|
||||
if isinstance(bst, xgb.Booster):
|
||||
@@ -28,46 +28,42 @@ class TestLoadPickle:
|
||||
|
||||
assert len(res) == 10
|
||||
|
||||
def test_predictor_type_is_auto(self):
|
||||
'''Under invalid CUDA_VISIBLE_DEVICES, predictor should be set to
|
||||
auto'''
|
||||
assert os.environ['CUDA_VISIBLE_DEVICES'] == '-1'
|
||||
def test_context_is_removed(self) -> None:
|
||||
"""Under invalid CUDA_VISIBLE_DEVICES, context should reset"""
|
||||
assert os.environ["CUDA_VISIBLE_DEVICES"] == "-1"
|
||||
bst = load_pickle(model_path)
|
||||
config = bst.save_config()
|
||||
config = json.loads(config)
|
||||
assert config['learner']['gradient_booster']['gbtree_train_param'][
|
||||
'predictor'] == 'auto'
|
||||
assert config["learner"]["generic_param"]["gpu_id"] == "-1"
|
||||
|
||||
def test_predictor_type_is_gpu(self):
|
||||
'''When CUDA_VISIBLE_DEVICES is not specified, keep using
|
||||
`gpu_predictor`'''
|
||||
assert 'CUDA_VISIBLE_DEVICES' not in os.environ.keys()
|
||||
def test_context_is_preserved(self) -> None:
|
||||
"""Test the device context is preserved after pickling."""
|
||||
assert "CUDA_VISIBLE_DEVICES" not in os.environ.keys()
|
||||
bst = load_pickle(model_path)
|
||||
config = bst.save_config()
|
||||
config = json.loads(config)
|
||||
assert config['learner']['gradient_booster']['gbtree_train_param'][
|
||||
'predictor'] == 'gpu_predictor'
|
||||
assert config["learner"]["generic_param"]["gpu_id"] == "0"
|
||||
|
||||
def test_wrap_gpu_id(self):
|
||||
assert os.environ['CUDA_VISIBLE_DEVICES'] == '0'
|
||||
def test_wrap_gpu_id(self) -> None:
|
||||
assert os.environ["CUDA_VISIBLE_DEVICES"] == "0"
|
||||
bst = load_pickle(model_path)
|
||||
config = bst.save_config()
|
||||
config = json.loads(config)
|
||||
assert config['learner']['generic_param']['gpu_id'] == '0'
|
||||
assert config["learner"]["generic_param"]["gpu_id"] == "0"
|
||||
|
||||
x, y = build_dataset()
|
||||
test_x = xgb.DMatrix(x)
|
||||
res = bst.predict(test_x)
|
||||
assert len(res) == 10
|
||||
|
||||
def test_training_on_cpu_only_env(self):
|
||||
assert os.environ['CUDA_VISIBLE_DEVICES'] == '-1'
|
||||
def test_training_on_cpu_only_env(self) -> None:
|
||||
assert os.environ["CUDA_VISIBLE_DEVICES"] == "-1"
|
||||
rng = np.random.RandomState(1994)
|
||||
X = rng.randn(10, 10)
|
||||
y = rng.randn(10)
|
||||
with tm.captured_output() as (out, err):
|
||||
# Test no thrust exception is thrown
|
||||
with pytest.raises(xgb.core.XGBoostError):
|
||||
xgb.train({'tree_method': 'gpu_hist'}, xgb.DMatrix(X, y))
|
||||
xgb.train({"tree_method": "gpu_hist"}, xgb.DMatrix(X, y))
|
||||
|
||||
assert out.getvalue().find('No visible GPU is found') != -1
|
||||
assert out.getvalue().find("No visible GPU is found") != -1
|
||||
|
||||
Reference in New Issue
Block a user