Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test column sampler with column-wise data split #9609

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 66 additions & 0 deletions tests/cpp/test_learner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -718,4 +718,70 @@ INSTANTIATE_TEST_SUITE_P(ColumnSplitObjective, TestColumnSplit,
[](const ::testing::TestParamInfo<TestColumnSplit::ParamType>& info) {
return ObjTestNameGenerator(info);
});

namespace {
void VerifyColumnSplitColumnSampler(std::string const& tree_method, bool use_gpu,
Json const& expected_model) {
Json model{Object{}};
{
auto const world_size = collective::GetWorldSize();
auto const rank = collective::GetRank();
auto const objective = "reg:logistic";
auto p_fmat = MakeFmatForObjTest(objective);
std::shared_ptr<DMatrix> sliced{p_fmat->SliceCol(world_size, rank)};
std::unique_ptr<Learner> learner{Learner::Create({sliced})};
learner->SetParam("tree_method", tree_method);
if (use_gpu) {
auto gpu_id = common::AllVisibleGPUs() == 1 ? 0 : rank;
learner->SetParam("device", "cuda:" + std::to_string(gpu_id));
}
learner->SetParam("objective", objective);
learner->SetParam("colsample_bytree", "0.5");
learner->SetParam("colsample_bylevel", "0.6");
learner->SetParam("colsample_bynode", "0.7");
learner->UpdateOneIter(0, sliced);
learner->SaveModel(&model);
}
ASSERT_EQ(model, expected_model);
}

void TestColumnSplitColumnSampler(std::string const& tree_method, bool use_gpu) {
Json model{Object{}};
{
auto objective = "reg:logistic";
auto p_fmat = MakeFmatForObjTest(objective);
std::unique_ptr<Learner> learner{Learner::Create({p_fmat})};
learner->SetParam("tree_method", tree_method);
if (use_gpu) {
learner->SetParam("device", "cuda:0");
}
learner->SetParam("objective", objective);
learner->SetParam("colsample_bytree", "0.5");
learner->SetParam("colsample_bylevel", "0.6");
learner->SetParam("colsample_bynode", "0.7");
learner->UpdateOneIter(0, p_fmat);
learner->SaveModel(&model);
}
auto world_size{3};
if (use_gpu) {
world_size = common::AllVisibleGPUs();
// Simulate MPU on a single GPU.
if (world_size == 1) {
world_size = 3;
}
}
RunWithInMemoryCommunicator(world_size, VerifyColumnSplitColumnSampler, tree_method, use_gpu,
model);
}
} // anonymous namespace

TEST(ColumnSplitColumnSampler, Approx) { TestColumnSplitColumnSampler("approx", false); }

TEST(ColumnSplitColumnSampler, Hist) { TestColumnSplitColumnSampler("hist", false); }

#if defined(XGBOOST_USE_CUDA)
TEST(ColumnSplitColumnSampler, GPUApprox) { TestColumnSplitColumnSampler("approx", true); }

TEST(ColumnSplitColumnSampler, GPUHist) { TestColumnSplitColumnSampler("hist", true); }
#endif // defined(XGBOOST_USE_CUDA)
} // namespace xgboost
Loading