Skip to content

Commit 9099d2c

Browse files
committed
Remove cpp tests for deprecated binary model.
1 parent 843d5ee commit 9099d2c

File tree

3 files changed

+15
-142
lines changed

3 files changed

+15
-142
lines changed

src/tree/updater_sync.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
/**
2-
* Copyright 2014-2024, XBGoost Contributors
2+
* Copyright 2014-2025, XBGoost Contributors
33
* \file updater_sync.cc
44
* \brief synchronize the tree in all distributed nodes
55
*/
6-
#include <xgboost/tree_updater.h>
7-
86
#include <string>
97
#include <vector>
108

119
#include "../collective/broadcast.h"
12-
#include "../collective/communicator-inl.h"
13-
#include "../common/io.h"
14-
#include "xgboost/json.h"
10+
#include "../collective/communicator-inl.h" // for GetRank, GetWorldSize
11+
#include "xgboost/context.h" // for Context
12+
#include "xgboost/json.h" // for Json, Object
13+
#include "xgboost/linalg.h" // for Matrix
14+
#include "xgboost/tree_updater.h" // for TreeUpdater
1515

1616
namespace xgboost::tree {
1717

@@ -29,25 +29,26 @@ class TreeSyncher : public TreeUpdater {
2929
void LoadConfig(Json const&) override {}
3030
void SaveConfig(Json*) const override {}
3131

32-
[[nodiscard]] char const* Name() const override { return "prune"; }
32+
[[nodiscard]] char const* Name() const override { return "sync"; }
3333

3434
void Update(TrainParam const*, linalg::Matrix<GradientPair>*, DMatrix*,
3535
common::Span<HostDeviceVector<bst_node_t>> /*out_position*/,
3636
const std::vector<RegTree*>& trees) override {
37-
if (collective::GetWorldSize() == 1) return;
38-
std::string s_model;
39-
common::MemoryBufferStream fs(&s_model);
37+
if (collective::GetWorldSize() == 1) {
38+
return;
39+
}
40+
Json model{Object{}};
4041
int rank = collective::GetRank();
4142
if (rank == 0) {
4243
for (auto tree : trees) {
43-
tree->Save(&fs);
44+
tree->SaveModel(&model);
4445
}
4546
}
46-
fs.Seek(0);
47+
auto s_model = Json::Dump(model);
4748
auto rc = collective::Broadcast(ctx_, linalg::MakeVec(s_model.data(), s_model.size()), 0);
4849
SafeColl(rc);
4950
for (auto tree : trees) {
50-
tree->Load(&fs);
51+
tree->LoadModel(model);
5152
}
5253
}
5354
};

tests/cpp/test_learner.cc

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2017-2024, XGBoost contributors
2+
* Copyright 2017-2025, XGBoost contributors
33
*/
44
#include <gmock/gmock.h>
55
#include <gtest/gtest.h>
@@ -283,38 +283,6 @@ TEST(Learner, MultiThreadedPredict) {
283283
}
284284
}
285285

286-
TEST(Learner, BinaryModelIO) {
287-
size_t constexpr kRows = 8;
288-
int32_t constexpr kIters = 4;
289-
auto p_dmat = RandomDataGenerator{kRows, 10, 0}.GenerateDMatrix();
290-
p_dmat->Info().labels.Reshape(kRows);
291-
292-
std::unique_ptr<Learner> learner{Learner::Create({p_dmat})};
293-
learner->SetParam("eval_metric", "rmsle");
294-
learner->Configure();
295-
for (int32_t iter = 0; iter < kIters; ++iter) {
296-
learner->UpdateOneIter(iter, p_dmat);
297-
}
298-
dmlc::TemporaryDirectory tempdir;
299-
std::string const fname = tempdir.path + "binary_model_io.bin";
300-
{
301-
// Make sure the write is complete before loading.
302-
std::unique_ptr<dmlc::Stream> fo(dmlc::Stream::Create(fname.c_str(), "w"));
303-
learner->SaveModel(fo.get());
304-
}
305-
306-
learner.reset(Learner::Create({p_dmat}));
307-
std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(fname.c_str(), "r"));
308-
learner->LoadModel(fi.get());
309-
learner->Configure();
310-
Json config { Object() };
311-
learner->SaveConfig(&config);
312-
std::string config_str;
313-
Json::Dump(config, &config_str);
314-
ASSERT_NE(config_str.find("rmsle"), std::string::npos);
315-
ASSERT_EQ(config_str.find("WARNING"), std::string::npos);
316-
}
317-
318286
#if defined(XGBOOST_USE_CUDA)
319287
// Tests for automatic GPU configuration.
320288
TEST(Learner, GPUConfiguration) {

tests/cpp/tree/test_tree_model.cc

Lines changed: 0 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,6 @@ TEST(Tree, ModelShape) {
1616
RegTree tree{1u, n_features};
1717
ASSERT_EQ(tree.NumFeatures(), n_features);
1818

19-
dmlc::TemporaryDirectory tempdir;
20-
const std::string tmp_file = tempdir.path + "/tree.model";
21-
{
22-
// binary dump
23-
std::unique_ptr<dmlc::Stream> fo(dmlc::Stream::Create(tmp_file.c_str(), "w"));
24-
tree.Save(fo.get());
25-
}
26-
{
27-
// binary load
28-
RegTree new_tree;
29-
std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(tmp_file.c_str(), "r"));
30-
new_tree.Load(fi.get());
31-
ASSERT_EQ(new_tree.NumFeatures(), n_features);
32-
}
3319
{
3420
// json
3521
Json j_tree{Object{}};
@@ -56,88 +42,6 @@ TEST(Tree, ModelShape) {
5642
}
5743
}
5844

59-
#if DMLC_IO_NO_ENDIAN_SWAP // skip on big-endian machines
60-
// Manually construct tree in binary format
61-
// Do not use structs in case they change
62-
// We want to preserve backwards compatibility
63-
TEST(Tree, Load) {
64-
dmlc::TemporaryDirectory tempdir;
65-
const std::string tmp_file = tempdir.path + "/tree.model";
66-
std::unique_ptr<dmlc::Stream> fo(dmlc::Stream::Create(tmp_file.c_str(), "w"));
67-
68-
// Write params
69-
EXPECT_EQ(sizeof(TreeParam), (31 + 6) * sizeof(int));
70-
int num_roots = 1;
71-
int num_nodes = 2;
72-
int num_deleted = 0;
73-
int max_depth = 1;
74-
int num_feature = 0;
75-
int size_leaf_vector = 0;
76-
int reserved[31];
77-
fo->Write(&num_roots, sizeof(int));
78-
fo->Write(&num_nodes, sizeof(int));
79-
fo->Write(&num_deleted, sizeof(int));
80-
fo->Write(&max_depth, sizeof(int));
81-
fo->Write(&num_feature, sizeof(int));
82-
fo->Write(&size_leaf_vector, sizeof(int));
83-
fo->Write(reserved, sizeof(int) * 31);
84-
85-
// Write 2 nodes
86-
EXPECT_EQ(sizeof(RegTree::Node),
87-
3 * sizeof(int) + 1 * sizeof(unsigned) + sizeof(float));
88-
int parent = -1;
89-
int cleft = 1;
90-
int cright = -1;
91-
unsigned sindex = 5;
92-
float split_or_weight = 0.5;
93-
fo->Write(&parent, sizeof(int));
94-
fo->Write(&cleft, sizeof(int));
95-
fo->Write(&cright, sizeof(int));
96-
fo->Write(&sindex, sizeof(unsigned));
97-
fo->Write(&split_or_weight, sizeof(float));
98-
parent = 0;
99-
cleft = -1;
100-
cright = -1;
101-
sindex = 2;
102-
split_or_weight = 0.1;
103-
fo->Write(&parent, sizeof(int));
104-
fo->Write(&cleft, sizeof(int));
105-
fo->Write(&cright, sizeof(int));
106-
fo->Write(&sindex, sizeof(unsigned));
107-
fo->Write(&split_or_weight, sizeof(float));
108-
109-
// Write 2x node stats
110-
EXPECT_EQ(sizeof(RTreeNodeStat), 3 * sizeof(float) + sizeof(int));
111-
bst_float loss_chg = 5.0;
112-
bst_float sum_hess = 1.0;
113-
bst_float base_weight = 3.0;
114-
int leaf_child_cnt = 0;
115-
fo->Write(&loss_chg, sizeof(float));
116-
fo->Write(&sum_hess, sizeof(float));
117-
fo->Write(&base_weight, sizeof(float));
118-
fo->Write(&leaf_child_cnt, sizeof(int));
119-
120-
loss_chg = 50.0;
121-
sum_hess = 10.0;
122-
base_weight = 30.0;
123-
leaf_child_cnt = 0;
124-
fo->Write(&loss_chg, sizeof(float));
125-
fo->Write(&sum_hess, sizeof(float));
126-
fo->Write(&base_weight, sizeof(float));
127-
fo->Write(&leaf_child_cnt, sizeof(int));
128-
fo.reset();
129-
std::unique_ptr<dmlc::Stream> fi(dmlc::Stream::Create(tmp_file.c_str(), "r"));
130-
131-
xgboost::RegTree tree;
132-
tree.Load(fi.get());
133-
EXPECT_EQ(tree.GetDepth(1), 1);
134-
EXPECT_EQ(tree[0].SplitCond(), 0.5f);
135-
EXPECT_EQ(tree[0].SplitIndex(), 5ul);
136-
EXPECT_EQ(tree[1].LeafValue(), 0.1f);
137-
EXPECT_TRUE(tree[1].IsLeaf());
138-
}
139-
#endif // DMLC_IO_NO_ENDIAN_SWAP
140-
14145
TEST(Tree, AllocateNode) {
14246
RegTree tree;
14347
tree.ExpandNode(0, 0, 0.0f, false, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f,

0 commit comments

Comments
 (0)