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

Model IO in JSON. #5110

Merged
merged 2 commits into from
Dec 11, 2019
Merged

Model IO in JSON. #5110

merged 2 commits into from
Dec 11, 2019

Conversation

trivialfis
Copy link
Member

@trivialfis trivialfis commented Dec 10, 2019

The "model" part of #4732. Follow up PRs will be for "Configuration".

@trivialfis trivialfis requested a review from hcho3 December 10, 2019 14:37
@trivialfis
Copy link
Member Author

trivialfis commented Dec 10, 2019

@hcho3 The schema of tree is different from our original design, suggested by @trams I split up each component of a node for future extensibility. Will update the schema accordingly.

@trivialfis trivialfis merged commit 208ab3b into dmlc:master Dec 11, 2019
@trivialfis trivialfis deleted the json-model branch December 11, 2019 03:20
src/learner.cc Show resolved Hide resolved
Copy link
Collaborator

@hcho3 hcho3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I love how the JSON object abstraction lets us write serialization succinctly and clearly. See my minor comments.

}

{
model = Json::Load({model_str.c_str(), model_str.size()});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: It took me a little bit to realize that StringView object was being implicitly constructed. Personally I'd prefer declaring StringView constructor to be explicit.


{
model = Json::Load({model_str.c_str(), model_str.size()});
model = model["model"];
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Is this simply a shallow copy (pointer assignment), or is this involving a deep copy?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hcho3 It involves a deep copy. Use reference if you don't want a copy

Comment on lines +47 to +52
{
model = Json::Load({model_str.c_str(), model_str.size()});
model = model["model"];
auto weights = get<Array>(model["weights"]);
ASSERT_EQ(weights.size(), 17); // 16 + 1 (bias)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this block a duplicate of line 38-45?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hcho3 No, the model is reloaded. But I will structure it more clearly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the model is loaded from model_str twice?

Comment on lines +149 to +152
auto& j_model = model["model"];
model["parameters"] = Object();

gbm->SaveModel(&j_model);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, this snippet is a good exhibit of the power and flexibility of a nested key-value store.

for (int32_t iter = 0; iter < kIters; ++iter) {
learner->UpdateOneIter(iter, p_dmat.get());
}
learner->SetAttr("bset_score", "15.2");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you mean base_score?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hcho3 Typo, opening a new PR for addressing your comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hcho3 See #5112 .

@lock lock bot locked as resolved and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants