@@ -170,13 +170,13 @@ def test_training(self, sparsity: float) -> None:
170
170
}
171
171
xgb .train (parameters , Xy )
172
172
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 :
174
174
n_samples , n_features = 2048 , 17
175
175
if enable_cat :
176
176
X , y = make_categorical (
177
177
n_samples , n_features , n_categories = 13 , onehot = False
178
178
)
179
- if tree_method == "gpu_hist " :
179
+ if device == "cuda " :
180
180
import cudf
181
181
182
182
X = cudf .from_pandas (X )
@@ -189,10 +189,12 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
189
189
190
190
# Use ref
191
191
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
+ )
193
195
qdm_results : Dict [str , Dict [str , List [float ]]] = {}
194
196
xgb .train (
195
- {"tree_method" : tree_method },
197
+ {"tree_method" : "hist" , "device" : device },
196
198
Xy ,
197
199
evals = [(Xy , "Train" ), (Xy_valid , "valid" )],
198
200
evals_result = qdm_results ,
@@ -201,10 +203,10 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
201
203
qdm_results ["Train" ]["rmse" ], qdm_results ["valid" ]["rmse" ]
202
204
)
203
205
# No ref
204
- Xy_valid = xgb .QuantileDMatrix (X , y , enable_categorical = enable_cat )
206
+ Xy_valid = xgb .DMatrix (X , y , enable_categorical = enable_cat )
205
207
qdm_results = {}
206
208
xgb .train (
207
- {"tree_method" : tree_method },
209
+ {"tree_method" : "hist" , "device" : device },
208
210
Xy ,
209
211
evals = [(Xy , "Train" ), (Xy_valid , "valid" )],
210
212
evals_result = qdm_results ,
@@ -229,7 +231,7 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
229
231
n_samples , n_features = 256 , 17
230
232
if enable_cat :
231
233
X , y = make_categorical (n_samples , n_features , 13 , onehot = False )
232
- if tree_method == "gpu_hist " :
234
+ if device == "cuda " :
233
235
import cudf
234
236
235
237
X = cudf .from_pandas (X )
@@ -246,15 +248,15 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
246
248
247
249
qdm_results = {}
248
250
xgb .train (
249
- {"tree_method" : tree_method },
251
+ {"tree_method" : "hist" , "device" : device },
250
252
Xy ,
251
253
evals = [(Xy , "Train" ), (Xy_valid , "valid" )],
252
254
evals_result = qdm_results ,
253
255
)
254
256
255
257
dm_results : Dict [str , Dict [str , List [float ]]] = {}
256
258
xgb .train (
257
- {"tree_method" : tree_method },
259
+ {"tree_method" : "hist" , "device" : device },
258
260
dXy ,
259
261
evals = [(dXy , "Train" ), (dXy_valid , "valid" ), (Xy_valid_d , "dvalid" )],
260
262
evals_result = dm_results ,
@@ -269,13 +271,19 @@ def run_ref_dmatrix(self, rng: Any, tree_method: str, enable_cat: bool) -> None:
269
271
dm_results ["dvalid" ]["rmse" ], qdm_results ["valid" ]["rmse" ]
270
272
)
271
273
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
+
272
280
def test_ref_quantile_cut (self ) -> None :
273
281
check_ref_quantile_cut ("cpu" )
274
282
275
283
def test_ref_dmatrix (self ) -> None :
276
284
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 )
279
287
280
288
@pytest .mark .parametrize ("sparsity" , [0.0 , 0.5 ])
281
289
def test_predict (self , sparsity : float ) -> None :
0 commit comments