MLflow for Darts implementation#3022
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
|
Hey @daidahao, adding this draft PR in the meantime so you and @dennisbader can have a look at what I have currently regarding the integration. There are still some decisions I am not too thrilled about and decisions to be made about the overall direction, but I'm happy to talk more about it during the meeting. Thanks for being so active for the library, really nice to be working together :) |
|
Sorry to hear that. Thank you for all your work and I can attest that you absolutely built a solid foundation for MLflow in Darts! |
|
@jakubchlapek @dennisbader @mizeller I've reviewed and provided some comments here for the code (except for unit tests and notebook). Overall, I agree with most of the design choices by @jakubchlapek and there are only a few deviations from mine (e.g., using MLflow existing APIs, Darts I wonder if it would be easier if @jakubchlapek could allow me to edit the code directly to address my comments here? That way, @mizeller can then continue the work here with the best of both worlds, and focus on unit tests or extension, etc. Let me know what you think. Once again, thank you for the great work @jakubchlapek and I am glad that our impl. align so well. |
|
@daidahao Perfect timing - I wrapped my head around @jakubchlapek's implementation & had a short meeting w/ @dennisbader last Friday about what needs to be done. I did fork off of @jakubchlapek's branch here. You can add your changes there and we can merge into @jakubchlapek's branch when we're done (or wait for him to give you access to his branch.) Just added you as collaborator there. Whatever you prefer :) I'll try to squeeze this PR in this week and ping you here if something's unclear if that's okay! |
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
darts/utils/utils.py
Outdated
| try: | ||
| import pytorch_lightning as pl # noqa: F401 | ||
|
|
||
| PL_AVAILABLE = True |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
pyproject.toml
Outdated
| ] | ||
| notorch = [ | ||
| "catboost>=1.0.6", | ||
| "catboost>=1.0.6,<=1.2.9", |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
| "statsforecast>=1.4", | ||
| "xgboost>=2.1.4", | ||
| ] | ||
| mlflow = ["mlflow>=2.0"] |
There was a problem hiding this comment.
I would like a discussion on the new option here. My understanding is that users who would need the Darts-MLflow integration probably have MLFlow installed already and set up properly. For users who have not, MLflow itself has options for databricks, which some users might find useful. Could we instead direct users to MLflow official guide for installation?
There was a problem hiding this comment.
Also, @MichaelVerdegaal raised a suggestion for mlflow>=3.0. I have not used MLflow 2.x before but I think the minimum version should be deliberated as well.
| does not apply the `with_managed_run` wrapper to the specified | ||
| `patch_function`. | ||
| """ | ||
| # Enable/disable mlflow.pytorch.autolog for per-epoch metrics on torch models. |
There was a problem hiding this comment.
Sorry, I don't understand why the decorator would short-circuit here if we call mlflow.pytorch.autolog() with disable=True. Looking at XGBoost flavour, it seems they are able to call mlflow.sklearn._autolog() within mlflow.xgboost.autolog(). Is it because mlflow.sklearn._autolog() is not wrapped but mlflow.pytorch.autolog() is?
darts/utils/mlflow.py
Outdated
|
|
||
| classes_to_patch = [ForecastingModel] | ||
|
|
||
| for subclass in get_all_subclasses(ForecastingModel): |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
|
|
||
| def log_model( | ||
| model, | ||
| artifact_path: str | None = None, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
darts/utils/mlflow.py
Outdated
| log_models: bool = True, | ||
| log_params: bool = True, | ||
| log_metrics: bool = True, | ||
| inject_per_epoch_callbacks: bool = True, |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
darts/utils/mlflow.py
Outdated
| A list of pip requirement strings. | ||
| """ | ||
| reqs = [_get_pinned_requirement("darts")] | ||
| if is_torch: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
darts/utils/mlflow.py
Outdated
| if code_dir_subpath is not None: | ||
| darts_flavor_conf["code"] = code_dir_subpath | ||
|
|
||
| default_reqs = None if pip_requirements else get_default_pip_requirements(is_torch) |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
darts/utils/mlflow.py
Outdated
| bool | ||
| True if the model is a TorchForecastingModel, False otherwise. | ||
| """ | ||
| try: |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
Co-authored-by: Zhihao Dai <zhihao.dai@eng.ox.ac.uk>
|
@mizeller @jakubchlapek @dennisbader Greetings! I've addressed most of the comments here, except for a few discussion points. I've left a Sincere apologies for suggesting post-fitting metrics in the first place! I didn't realise the complexity involved. My suggestion is to skip post-fitting metrics for now or settle for compromises such as non-terminated active runs (at the risk of cross-logging). Other than that, I am truly proud of what we have achieved here and will hand this over to @mizeller for runups and more great work. |
Checklist before merging this PR:
Addresses #2092 .
Summary
Provides a custom MLflow flavor for Darts on Darts' side. Supports autologging, logging, saving and loading of the models.
This PR focuses on the base MLflow integration, leaving serving of the models to be discussed in the future.
Included an example quickstart for the integration, however consider all of this a draft :)
Find example code in the .ipynb, however also providing a code snippet here as a quick reproducible example: