Skip to content

Save Scikit-Learn attributes into learner attributes. - #5245

Merged
trivialfis merged 6 commits into
dmlc:masterfrom
trivialfis:remove-pickle-warning
Jan 30, 2020
Merged

trivialfis merged 6 commits into
dmlc:masterfrom
trivialfis:remove-pickle-warning

Conversation

@trivialfis

@trivialfis trivialfis commented Jan 29, 2020 •

Copy link
Copy Markdown
Member

This PR modifies the behavior of saving Scikit-Learn model, pickle is no longer
recommended. Instead an additional JSON file is produced for saving
Scikit-Learn specific attributes. When using JSON output format in XGBoost,
the additional file is subsumed into main model file.

Instead the attributes are saved into Learner::attributes_.

This PR modifies the behavior of saving Scikit-Learn model, pickle is no longer
recommended.  Instead an additional JSON file is produced for saving
Scikit-Learn specific attributes.  When using JSON output format in XGBoost,
the additional file is subsumed into main model file.

This will hurt IO performance as additional parsing/generating is required.  We
can mitigate it in the future by utilizing `XGBoosterGetModelRaw` with JSON,
eliminating intermediate file IO.
@trivialfis trivialfis changed the title Remove pickle warning [Breaking] Save Scikit-Learn attributes into an additional file. Jan 29, 2020
@chyunsu3

Copy link
Copy Markdown
Collaborator

Is this blocking?

@trivialfis

trivialfis commented Jan 29, 2020 •

Copy link
Copy Markdown
Member Author

@hcho3 I hope so, but will value your opinion. It's gonna be painful for everyone who had used pickle before. So let's get started as soon as possible.

@trivialfis

trivialfis commented Jan 29, 2020 •

Copy link
Copy Markdown
Member Author

@hcho3 @RAMitchell Please help with this PR as we will have to maintain it for a very long time. We promise the stability of output model, which includes this meta file. If you have suggestions or doubt, please share.

@trivialfis trivialfis changed the title [Breaking] Save Scikit-Learn attributes into an additional file. [Breaking] Save Scikit-Learn attributes into learner attributes. Jan 29, 2020
@trivialfis

trivialfis commented Jan 29, 2020 •

Copy link
Copy Markdown
Member Author

I saved the additional attributes into Learner::attributes_ instead of a separated file. It's a hack, but seems nicer than producing another file or parsing the model multiple times. One drawback is the when loading a model generated by scikit-learn by native booster, there's an additional attribute that can not be deleted.

It can be reverted to 9a364a7 if the previous approach is preferred.

@trivialfis trivialfis changed the title [Breaking] Save Scikit-Learn attributes into learner attributes. Save Scikit-Learn attributes into learner attributes. Jan 29, 2020

@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'm not very comfortable with these changes at the last minute. Saving an additional file is a bit of a strange behaviour, and I can't foresee how flexible this approach is going to be in future. I think it's acceptable that we break compatibility with 1.0 release.

@chyunsu3

Copy link
Copy Markdown
Collaborator

Serialization has been a headache for Python objects in sklearn interface, and this is a welcome corrective.

@RAMitchell

Copy link
Copy Markdown
Member

I was looking at the older commit, I like your new version much better than the file. The additional attribute is harmless right? I'm ok with this and defer to the two of you.

@chyunsu3

Copy link
Copy Markdown
Collaborator

I'd like to merge it soon, if there's no objection.

@trivialfis
trivialfis merged commit 472ded5 into dmlc:master Jan 30, 2020
@trivialfis
trivialfis deleted the remove-pickle-warning branch January 30, 2020 08:00
@lock lock Bot locked as resolved and limited conversation to collaborators May 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants