@@ -170,13 +170,13 @@ def test_training(self, sparsity: float) -> None:
170170 }
171171 xgb .train (parameters , Xy )
172172
173- def run_ref_dmatrix (self , rng : Any , tree_method : str , enable_cat : bool ) -> None :
173+ def run_ref_dmatrix (self , rng : Any , device : str , enable_cat : bool ) -> None :
174174 n_samples , n_features = 2048 , 17
175175 if enable_cat :
176176 X , y = make_categorical (
177177 n_samples , n_features , n_categories = 13 , onehot = False
178178 )
179- if tree_method == "gpu_hist " :
179+ if device == "cuda " :
180180 import cudf
181181
182182 X = cudf .from_pandas (X )
@@ -189,10 +189,12 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
189189
190190 # Use ref
191191 Xy = xgb .QuantileDMatrix (X , y , enable_categorical = enable_cat )
192- Xy_valid = xgb .QuantileDMatrix (X , y , ref = Xy , enable_categorical = enable_cat )
192+ Xy_valid : xgb .DMatrix = xgb .QuantileDMatrix (
193+ X , y , ref = Xy , enable_categorical = enable_cat
194+ )
193195 qdm_results : Dict [str , Dict [str , List [float ]]] = {}
194196 xgb .train (
195- {"tree_method" : tree_method },
197+ {"tree_method" : "hist" , "device" : device },
196198 Xy ,
197199 evals = [(Xy , "Train" ), (Xy_valid , "valid" )],
198200 evals_result = qdm_results ,
@@ -201,10 +203,10 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
201203 qdm_results ["Train" ]["rmse" ], qdm_results ["valid" ]["rmse" ]
202204 )
203205 # No ref
204- Xy_valid = xgb .QuantileDMatrix (X , y , enable_categorical = enable_cat )
206+ Xy_valid = xgb .DMatrix (X , y , enable_categorical = enable_cat )
205207 qdm_results = {}
206208 xgb .train (
207- {"tree_method" : tree_method },
209+ {"tree_method" : "hist" , "device" : device },
208210 Xy ,
209211 evals = [(Xy , "Train" ), (Xy_valid , "valid" )],
210212 evals_result = qdm_results ,
@@ -229,7 +231,7 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
229231 n_samples , n_features = 256 , 17
230232 if enable_cat :
231233 X , y = make_categorical (n_samples , n_features , 13 , onehot = False )
232- if tree_method == "gpu_hist " :
234+ if device == "cuda " :
233235 import cudf
234236
235237 X = cudf .from_pandas (X )
@@ -246,15 +248,15 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
246248
247249 qdm_results = {}
248250 xgb .train (
249- {"tree_method" : tree_method },
251+ {"tree_method" : "hist" , "device" : device },
250252 Xy ,
251253 evals = [(Xy , "Train" ), (Xy_valid , "valid" )],
252254 evals_result = qdm_results ,
253255 )
254256
255257 dm_results : Dict [str , Dict [str , List [float ]]] = {}
256258 xgb .train (
257- {"tree_method" : tree_method },
259+ {"tree_method" : "hist" , "device" : device },
258260 dXy ,
259261 evals = [(dXy , "Train" ), (dXy_valid , "valid" ), (Xy_valid_d , "dvalid" )],
260262 evals_result = dm_results ,
@@ -269,13 +271,19 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
269271 dm_results ["dvalid" ]["rmse" ], qdm_results ["valid" ]["rmse" ]
270272 )
271273
274+ Xy_valid = xgb .QuantileDMatrix (X , y , enable_categorical = enable_cat )
275+ with pytest .raises (ValueError , match = "should be used as a reference" ):
276+ xgb .train (
277+ {"device" : device }, dXy , evals = [(dXy , "Train" ), (Xy_valid , "Valid" )]
278+ )
279+
272280 def test_ref_quantile_cut (self ) -> None :
273281 check_ref_quantile_cut ("cpu" )
274282
275283 def test_ref_dmatrix (self ) -> None :
276284 rng = np .random .RandomState (1994 )
277- self .run_ref_dmatrix (rng , "hist " , True )
278- self .run_ref_dmatrix (rng , "hist " , False )
285+ self .run_ref_dmatrix (rng , "cpu " , True )
286+ self .run_ref_dmatrix (rng , "cpu " , False )
279287
280288 @pytest .mark .parametrize ("sparsity" , [0.0 , 0.5 ])
281289 def test_predict (self , sparsity : float ) -> None :
0 commit comments