Autologging functionality for scikit-learn integration with LightGBM (Part 1)#5130
Conversation
Signed-off-by: Junwen Yao <jwyiao@gmail.com>
Signed-off-by: Junwen Yao <jwyiao@gmail.com>
|
Hi @dbczumar @harupy, I made the first PR to support autologging for LightGBM sklearn model. Unlike XGBoost sklearn models, LightGBM sklearn models don't support Please let me your feedback and suggestions when you have time to review it! Thank you so much! |
|
Hi @dbczumar @harupy, it seems the LightGBM community doesn't have a plan to implement |
dbczumar
left a comment
There was a problem hiding this comment.
@jwyyy Excellent work! Apologies for the delayed response due to a busy holiday season. Regarding your question about serialization / deserialization, I think it's probably best to use pickle for now. This is less likely to break across LightGBM versions. Can we test out serialization / deserialization with custom objective functions (see docs for eval_metric here: https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm.LGBMClassifier.fit) and make sure that pickle works successfully? If it doesn't, we may want to use cloudpickle.
| return None | ||
|
|
||
|
|
||
| def _save_lgb_model(lgb_model, model_path) -> None: |
There was a problem hiding this comment.
Following from #5130 (comment), I think it's probably safest to use pickle to save / load the model, since the LightGBM developers could make breaking changes that break the serialization / deserialization code. Thank you so much for taking the time to reach out to the LightGBM community and get some insight into the recommended best practices here.
Can we test out serialization / deserialization with custom objective functions (see docs for eval_metric here: https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMClassifier.html#lightgbm.LGBMClassifier.fit) and make sure that pickle works successfully? If it doesn't, we may want to use cloudpickle.
|
Hi @dbczumar, no worries! Thank you for your review and feedback! I will update the PR accordingly. |
Signed-off-by: Junwen Yao <jwyiao@gmail.com>
Signed-off-by: Junwen Yao <jwyiao@gmail.com>
|
Hi @dbczumar @harupy, I made some changes to the PR. For serialization / deserialization of LightGBM sklearn models, I used |
| that, at minimum, contains these requirements. | ||
| """ | ||
| return [_get_pinned_requirement("lightgbm")] | ||
| return [_get_pinned_requirement("lightgbm"), _get_pinned_requirement("cloudpickle")] |
There was a problem hiding this comment.
Can we add cloudpickle conditionally because users who don't use scikit-learn estimators don't need cloudpickle?
There was a problem hiding this comment.
Hi @harupy, thank you for your suggestion! Does that mean we also need to provide an option to turn on / off autologging for scikit-learn estimators? I assumed mlflow.lightgbm.autolog() enables autologging for all models.
| if isinstance(lgb_model, lgb.Booster): | ||
| model_data_subpath = "model.lgb" | ||
| else: | ||
| model_data_subpath = "model.pkl" |
There was a problem hiding this comment.
| if isinstance(lgb_model, lgb.Booster): | |
| model_data_subpath = "model.lgb" | |
| else: | |
| model_data_subpath = "model.pkl" | |
| model_data_subpath = "model.lgb" if isinstance(lgb_model, lgb.Booster) else "model.pkl" |
nit
Signed-off-by: Junwen Yao <jwyiao@gmail.com>
Signed-off-by: Junwen Yao <jwyiao@gmail.com>
|
@harupy Thank you for your review! |
What changes are proposed in this pull request?
This PR enables the support for saving and loading all LightGBM models.
(Draft + discussion: #4296, #4885. Template: #4954)
How is this patch tested?
New test methods are added.
Does this PR change the documentation?
ci/circleci: build_doccheck. If it's successful, proceed to thenext step, otherwise fix it.
Detailson the right to open the job page of CircleCI.Artifactstab.docs/build/html/index.html.Release Notes
Is this a user-facing change?
This PR will enable saving and loading LightGBM models, including sklearn models, with model class specification.
Functions
save_model()/load_model()inmlflow.lightgbmcan be used as before.What component(s), interfaces, languages, and integrations does this PR affect?
Components
area/artifacts: Artifact stores and artifact loggingarea/build: Build and test infrastructure for MLflowarea/docs: MLflow documentation pagesarea/examples: Example codearea/model-registry: Model Registry service, APIs, and the fluent client calls for Model Registryarea/models: MLmodel format, model serialization/deserialization, flavorsarea/projects: MLproject format, project running backendsarea/scoring: MLflow Model server, model deployment tools, Spark UDFsarea/server-infra: MLflow Tracking server backendarea/tracking: Tracking Service, tracking client APIs, autologgingInterface
area/uiux: Front-end, user experience, plotting, JavaScript, JavaScript dev serverarea/docker: Docker use across MLflow's components, such as MLflow Projects and MLflow Modelsarea/sqlalchemy: Use of SQLAlchemy in the Tracking Service or Model Registryarea/windows: Windows supportLanguage
language/r: R APIs and clientslanguage/java: Java APIs and clientslanguage/new: Proposals for new client languagesIntegrations
integrations/azure: Azure and Azure ML integrationsintegrations/sagemaker: SageMaker integrationsintegrations/databricks: Databricks integrationsHow should the PR be classified in the release notes? Choose one:
rn/breaking-change- The PR will be mentioned in the "Breaking Changes" sectionrn/none- No description will be included. The PR will be mentioned only by the PR number in the "Small Bugfixes and Documentation Updates" sectionrn/feature- A new user-facing feature worth mentioning in the release notesrn/bug-fix- A user-facing bug fix worth mentioning in the release notesrn/documentation- A user-facing documentation change worth mentioning in the release notes