-
Notifications
You must be signed in to change notification settings - Fork 103
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
Hotfix for serializer #273
Merged
+222
−33
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
1690380
Hotfix for serializer
hcho3 b9b8cdd
Add test cases to demonstrate the serializer bug
hcho3 24e72d4
Reduce amount of time for PyBufferInterfaceRoundTrip.DeepFullTree
hcho3 1056b88
Add case PyBufferInterfaceRoundTrip.XGBoostBoston
hcho3 561cb0e
Address reviewer's feedback
hcho3 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add test cases to demonstrate the serializer bug
commit b9b8cdd53fc94fa72fe372395a14ec9de2e7195e
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ inline void TestRoundTrip(treelite::Model* model) { | |
auto buffer = model->GetPyBuffer(); | ||
std::unique_ptr<treelite::Model> received_model = treelite::Model::CreateFromPyBuffer(buffer); | ||
|
||
ASSERT_EQ(TreeliteToBytes(model), TreeliteToBytes(received_model.get())); | ||
ASSERT_TRUE(TreeliteToBytes(model) == TreeliteToBytes(received_model.get())); | ||
} | ||
|
||
for (int i = 0; i < 2; ++i) { | ||
|
@@ -44,7 +44,7 @@ inline void TestRoundTrip(treelite::Model* model) { | |
std::unique_ptr<treelite::Model> received_model = treelite::Model::DeserializeFromFile(fp); | ||
std::fclose(fp); | ||
|
||
ASSERT_EQ(TreeliteToBytes(model), TreeliteToBytes(received_model.get())); | ||
ASSERT_TRUE(TreeliteToBytes(model) == TreeliteToBytes(received_model.get())); | ||
} | ||
} | ||
|
||
|
@@ -178,7 +178,7 @@ void PyBufferInterfaceRoundTrip_TreeDepth2() { | |
}; | ||
builder->SetModelParam("pred_transform", "sigmoid"); | ||
builder->SetModelParam("global_bias", "0.5"); | ||
for (int tree_id = 0; tree_id < 2; ++tree_id) { | ||
for (int tree_id = 0; tree_id < 3; ++tree_id) { | ||
std::unique_ptr<frontend::TreeBuilder> tree{ | ||
new frontend::TreeBuilder(threshold_type, leaf_output_type) | ||
}; | ||
|
@@ -189,10 +189,10 @@ void PyBufferInterfaceRoundTrip_TreeDepth2() { | |
tree->SetCategoricalTestNode(1, 0, {0, 1}, true, 3, 4); | ||
tree->SetCategoricalTestNode(2, 1, {0}, true, 5, 6); | ||
tree->SetRootNode(0); | ||
tree->SetLeafNode(3, frontend::Value::Create<LeafOutputType>(3)); | ||
tree->SetLeafNode(4, frontend::Value::Create<LeafOutputType>(1)); | ||
tree->SetLeafNode(5, frontend::Value::Create<LeafOutputType>(4)); | ||
tree->SetLeafNode(6, frontend::Value::Create<LeafOutputType>(2)); | ||
tree->SetLeafNode(3, frontend::Value::Create<LeafOutputType>(tree_id + 3)); | ||
tree->SetLeafNode(4, frontend::Value::Create<LeafOutputType>(tree_id + 1)); | ||
tree->SetLeafNode(5, frontend::Value::Create<LeafOutputType>(tree_id + 4)); | ||
tree->SetLeafNode(6, frontend::Value::Create<LeafOutputType>(tree_id + 2)); | ||
Comment on lines
+196
to
+199
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I crafted the test case so that all the trees will have different leaf outputs. The bug being addressed causes all trees to be identical. |
||
builder->InsertTree(tree.get()); | ||
} | ||
|
||
|
@@ -221,28 +221,30 @@ void PyBufferInterfaceRoundTrip_DeepFullTree() { | |
std::unique_ptr<frontend::ModelBuilder> builder{ | ||
new frontend::ModelBuilder(3, 1, false, threshold_type, leaf_output_type) | ||
}; | ||
std::unique_ptr<frontend::TreeBuilder> tree{ | ||
new frontend::TreeBuilder(threshold_type, leaf_output_type) | ||
}; | ||
for (int level = 0; level <= depth; ++level) { | ||
for (int i = 0; i < (1 << level); ++i) { | ||
const int nid = (1 << level) - 1 + i; | ||
tree->CreateNode(nid); | ||
for (int tree_id = 0; tree_id < 3; ++tree_id) { | ||
std::unique_ptr<frontend::TreeBuilder> tree{ | ||
new frontend::TreeBuilder(threshold_type, leaf_output_type) | ||
}; | ||
for (int level = 0; level <= depth; ++level) { | ||
for (int i = 0; i < (1 << level); ++i) { | ||
const int nid = (1 << level) - 1 + i; | ||
tree->CreateNode(nid); | ||
} | ||
} | ||
} | ||
for (int level = 0; level <= depth; ++level) { | ||
for (int i = 0; i < (1 << level); ++i) { | ||
const int nid = (1 << level) - 1 + i; | ||
if (level == depth) { | ||
tree->SetLeafNode(nid, frontend::Value::Create<LeafOutputType>(1)); | ||
} else { | ||
tree->SetNumericalTestNode(nid, (level % 2), "<", frontend::Value::Create<ThresholdType>(0), | ||
true, 2 * nid + 1, 2 * nid + 2); | ||
for (int level = 0; level <= depth; ++level) { | ||
for (int i = 0; i < (1 << level); ++i) { | ||
const int nid = (1 << level) - 1 + i; | ||
if (level == depth) { | ||
tree->SetLeafNode(nid, frontend::Value::Create<LeafOutputType>(tree_id + 1)); | ||
} else { | ||
tree->SetNumericalTestNode(nid, (level % 2), "<", frontend::Value::Create<ThresholdType>(0), | ||
true, 2 * nid + 1, 2 * nid + 2); | ||
} | ||
} | ||
} | ||
tree->SetRootNode(0); | ||
builder->InsertTree(tree.get()); | ||
} | ||
tree->SetRootNode(0); | ||
builder->InsertTree(tree.get()); | ||
|
||
std::unique_ptr<Model> model = builder->CommitModel(); | ||
TestRoundTrip(model.get()); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ASSERT_EQ
will dump all the raw bytes into a string, leading to OOM error for this test case. So useASSERT_TRUE
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment to this effect so that someone doesn't naively reintroduce this problem down the line?