12
12
class TestGPUBasicModels (unittest .TestCase ):
13
13
cputest = test_bm .TestModels ()
14
14
15
- def test_eta_decay_gpu_hist (self ):
16
- self .cputest .run_eta_decay ('gpu_hist' )
17
-
18
- def test_deterministic_gpu_hist (self ):
19
- kRows = 1000
20
- kCols = 64
21
- kClasses = 4
22
- # Create large values to force rounding.
23
- X = np .random .randn (kRows , kCols ) * 1e4
24
- y = np .random .randint (0 , kClasses , size = kRows )
25
-
15
+ def run_cls (self , X , y , deterministic ):
26
16
cls = xgb .XGBClassifier (tree_method = 'gpu_hist' ,
27
- deterministic_histogram = True ,
17
+ deterministic_histogram = deterministic ,
28
18
single_precision_histogram = True )
29
19
cls .fit (X , y )
30
20
cls .get_booster ().save_model ('test_deterministic_gpu_hist-0.json' )
31
21
32
22
cls = xgb .XGBClassifier (tree_method = 'gpu_hist' ,
33
- deterministic_histogram = True ,
23
+ deterministic_histogram = deterministic ,
34
24
single_precision_histogram = True )
35
25
cls .fit (X , y )
36
26
cls .get_booster ().save_model ('test_deterministic_gpu_hist-1.json' )
@@ -40,7 +30,24 @@ def test_deterministic_gpu_hist(self):
40
30
with open ('test_deterministic_gpu_hist-1.json' , 'r' ) as fd :
41
31
model_1 = fd .read ()
42
32
43
- assert hash (model_0 ) == hash (model_1 )
44
-
45
33
os .remove ('test_deterministic_gpu_hist-0.json' )
46
34
os .remove ('test_deterministic_gpu_hist-1.json' )
35
+
36
+ return hash (model_0 ), hash (model_1 )
37
+
38
+ def test_eta_decay_gpu_hist (self ):
39
+ self .cputest .run_eta_decay ('gpu_hist' )
40
+
41
+ def test_deterministic_gpu_hist (self ):
42
+ kRows = 1000
43
+ kCols = 64
44
+ kClasses = 4
45
+ # Create large values to force rounding.
46
+ X = np .random .randn (kRows , kCols ) * 1e4
47
+ y = np .random .randint (0 , kClasses , size = kRows ) * 1e4
48
+
49
+ model_0 , model_1 = self .run_cls (X , y , True )
50
+ assert model_0 == model_1
51
+
52
+ model_0 , model_1 = self .run_cls (X , y , False )
53
+ assert model_0 != model_1
0 commit comments