Skip to content

JSON configuration IO. - #5111

Merged
trivialfis merged 9 commits into
dmlc:masterfrom
trivialfis:JSON-config
Dec 15, 2019
Merged

trivialfis merged 9 commits into
dmlc:masterfrom
trivialfis:JSON-config

Conversation

@trivialfis

@trivialfis trivialfis commented Dec 11, 2019 •

Copy link
Copy Markdown
Member

The "Configuration" part of #4732 . See the saving_model.rst in #4732 for what does the configuration look like.

  • Enable using JSON configuration in Python pickle.

@trivialfis

trivialfis commented Dec 11, 2019 •

Copy link
Copy Markdown
Member Author

Made the naming more consistent across XGBoost: #5112 .

@trivialfis
trivialfis requested review from RAMitchell and chyunsu3 and removed request for chyunsu3 December 11, 2019 08:13
@chyunsu3

Copy link
Copy Markdown
Collaborator

I wonder why tests are failing. Is this WIP?

@trivialfis

Copy link
Copy Markdown
Member Author

I made some extra cleanup and found some problems in existing code.

@chyunsu3

Copy link
Copy Markdown
Collaborator

Got it. Let me know if I can help in any way.

@trivialfis

trivialfis commented Dec 12, 2019 •

Copy link
Copy Markdown
Member Author

I thought with JSON we can enable a fully restored model from pickle, except I missed the prediction cache. The DMatrix cache is missing. It generates a very small (<1e-7) floating difference due to different floating point errors. Also slower performance.

Comment thread include/xgboost/parameter.h Resolved
Comment thread src/gbm/gbtree.cc
fromJson(in["gbtree_train_param"], &tparam_);
int32_t const n_gpus = xgboost::common::AllVisibleGPUs();
if (n_gpus == 0 && tparam_.predictor == PredictorType::kGPUPredictor) {
tparam_.UpdateAllowUnknown(Args{{"predictor", "auto"}});

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

YES! This is so much better than my previous hack in #3856

Comment thread src/learner.cc
Comment on lines -379 to -393
if (saved_param == "predictor" || saved_param == "gpu_id") {
cfg_[saved_param] = kv.second;
LOG(INFO)
<< "Parameter '" << saved_param << "' has been recovered from "
<< "the saved model. It will be set to "
<< RenderParamVal(kv.second) << " for prediction. To "
<< "override the predictor behavior, explicitly set '"
<< saved_param << "' parameter as follows:\n"
<< " * Python package: bst.set_param('"
<< saved_param << "', [new value])\n"
<< " * R package: xgb.parameters(bst) <- list("
<< saved_param << " = [new value])\n"
<< " * JVM packages: bst.setParam(\""
<< saved_param << "\", [new value])";
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(cry of joy)

@RAMitchell RAMitchell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. A few in-line comments would help me a lot if I ever have to deal with python serialisation code.

Comment thread python-package/xgboost/core.py Resolved
@trivialfis

Copy link
Copy Markdown
Member Author

On a second thought, let me lower down the serialization code into c++, might get rid of one big FIXME.

@trivialfis trivialfis changed the title JSON configuration IO. [WIP] JSON configuration IO. Dec 13, 2019
@trivialfis trivialfis changed the title [WIP] JSON configuration IO. JSON configuration IO. Dec 13, 2019
@trivialfis

trivialfis commented Dec 13, 2019 •

Copy link
Copy Markdown
Member Author

@hcho3 @RAMitchell I moved the concatenation into c++ from Python. This saves me from the trouble of handling R code, also formalize the difference between "Saving model" and "Serialization" in C API.

@RAMitchell RAMitchell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am a little confused. What is the difference between all of the following
XGBoosterLoadModel/XGBoosterSaveModel
XGBoosterLoadModelFromBuffer
XGBoosterGetModelRaw
XGBoosterSerializeToBuffer/XGBoosterUnserializeFromBuffer

Did you decide to abandon json for python pickling or is this more of a hybrid approach? What is the usefulness of python methods for save_config/load_config with json? Is it just for testing/parameter validation?

@trivialfis

Copy link
Copy Markdown
Member Author

@RAMitchell With the term "Model" it means saving only the tree, with the term "Config" it means all internal parameters, with the term "Serialization" it means save everything, the two of above combined.

Saving config is just an extra bonus for showing the internal parameters of XGBoos t.

@trivialfis
trivialfis merged commit 3136185 into dmlc:master Dec 15, 2019
@trivialfis
trivialfis deleted the JSON-config branch December 23, 2019 12:10
@lock lock Bot locked as resolved and limited conversation to collaborators Mar 22, 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