| 14 | |
| 15 | namespace xgboost::tree { |
| 16 | void TestColumnSplit(bst_target_t n_targets, bool categorical, std::string name, float sparsity) { |
| 17 | auto constexpr kRows = 32; |
| 18 | auto constexpr kCols = 16; |
| 19 | |
| 20 | RegTree expected_tree{n_targets, static_cast<bst_feature_t>(kCols)}; |
| 21 | ObjInfo task{ObjInfo::kRegression}; |
| 22 | Context ctx; |
| 23 | { |
| 24 | auto p_dmat = GenerateCatDMatrix(kRows, kCols, sparsity, categorical); |
| 25 | auto gpair = GenerateRandomGradients(&ctx, kRows, n_targets); |
| 26 | std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create(name, &ctx, &task)}; |
| 27 | std::vector<HostDeviceVector<bst_node_t>> position(1); |
| 28 | TrainParam param; |
| 29 | param.Init(Args{}); |
| 30 | updater->Configure(Args{}); |
| 31 | updater->Update(¶m, &gpair, p_dmat.get(), position, {&expected_tree}); |
| 32 | } |
| 33 | |
| 34 | auto constexpr kWorldSize = 2; |
| 35 | |
| 36 | auto verify = [&] { |
| 37 | Context ctx; |
| 38 | collective::GetWorkerLocalThreads(kWorldSize, &ctx); |
| 39 | |
| 40 | auto p_dmat = GenerateCatDMatrix(kRows, kCols, sparsity, categorical); |
| 41 | auto gpair = GenerateRandomGradients(&ctx, kRows, n_targets); |
| 42 | |
| 43 | ObjInfo task{ObjInfo::kRegression}; |
| 44 | std::unique_ptr<TreeUpdater> updater{TreeUpdater::Create(name, &ctx, &task)}; |
| 45 | std::vector<HostDeviceVector<bst_node_t>> position(1); |
| 46 | |
| 47 | std::unique_ptr<DMatrix> sliced{ |
| 48 | p_dmat->SliceCol(collective::GetWorldSize(), collective::GetRank())}; |
| 49 | |
| 50 | RegTree tree{n_targets, static_cast<bst_feature_t>(kCols)}; |
| 51 | TrainParam param; |
| 52 | param.Init(Args{}); |
| 53 | updater->Configure(Args{}); |
| 54 | updater->Update(¶m, &gpair, sliced.get(), position, {&tree}); |
| 55 | |
| 56 | Json json{Object{}}; |
| 57 | tree.SaveModel(&json); |
| 58 | Json expected_json{Object{}}; |
| 59 | expected_tree.SaveModel(&expected_json); |
| 60 | ASSERT_EQ(json, expected_json); |
| 61 | }; |
| 62 | |
| 63 | collective::TestDistributedGlobal(kWorldSize, [&] { verify(); }); |
| 64 | } |
| 65 | } // namespace xgboost::tree |
no test coverage detected