MCPcopy Create free account
hub / github.com/dmlc/xgboost / run_data_iterator

Function run_data_iterator

tests/python/test_data_iterator.py:77–162  ·  view source on GitHub ↗
(
    n_samples_per_batch: int,
    n_features: int,
    n_batches: int,
    tree_method: str,
    subsample: bool,
    device: str,
    use_cupy: bool,
    on_host: bool,
)

Source from the content-addressed store, hash-verified

75
76
77def run_data_iterator(
78 n_samples_per_batch: int,
79 n_features: int,
80 n_batches: int,
81 tree_method: str,
82 subsample: bool,
83 device: str,
84 use_cupy: bool,
85 on_host: bool,
86) -> None:
87 n_rounds = 2
88 # The test is more difficult to pass if the subsample rate is smaller as the root_sum
89 # is accumulated in parallel. Reductions with different number of entries lead to
90 # different floating point errors.
91 subsample_rate = 0.8 if subsample else 1.0
92
93 it = IteratorForTest(
94 *make_batches(n_samples_per_batch, n_features, n_batches, use_cupy),
95 cache="cache",
96 on_host=on_host,
97 )
98 if n_batches == 0:
99 with pytest.raises(ValueError, match="1 batch"):
100 Xy = xgb.DMatrix(it)
101 return
102
103 Xy_it = xgb.DMatrix(it)
104 assert Xy_it.num_row() == n_samples_per_batch * n_batches
105 assert Xy_it.num_col() == n_features
106
107 parameters = {
108 "tree_method": tree_method,
109 "max_depth": 2,
110 "subsample": subsample_rate,
111 "device": device,
112 "seed": 0,
113 }
114
115 if device.find("cuda") != -1:
116 parameters["sampling_method"] = "gradient_based"
117
118 results_from_it: Dict[str, Dict[str, List[float]]] = {}
119 from_it = xgb.train(
120 parameters,
121 Xy_it,
122 num_boost_round=n_rounds,
123 evals=[(Xy_it, "Train")],
124 evals_result=results_from_it,
125 verbose_eval=False,
126 )
127 if not subsample:
128 assert non_increasing(results_from_it["Train"]["rmse"])
129
130 X, y, w = it.as_arrays()
131 if use_cupy:
132 _y = y.get()
133 else:
134 _y = y

Callers 3

test_gpu_data_iteratorFunction · 0.90
test_cpu_data_iteratorFunction · 0.90
test_data_iteratorFunction · 0.85

Calls 11

num_rowMethod · 0.95
num_colMethod · 0.95
as_arraysMethod · 0.95
get_labelMethod · 0.95
get_quantile_cutMethod · 0.95
IteratorForTestClass · 0.90
make_batchesFunction · 0.90
non_increasingFunction · 0.90
DMatrixMethod · 0.45
trainMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected