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

docs: add mlflow logging and loading #1641

Merged
merged 3 commits into from Sep 6, 2022
Merged

docs: add mlflow logging and loading #1641

merged 3 commits into from Sep 6, 2022

Conversation

thinkall
Copy link
Contributor

@thinkall thinkall commented Sep 1, 2022

Related Issues/PRs

None

What changes are proposed in this pull request?

Updated aisample notebooks.

  • Added sections for mlflow logging and loading.
  • Updated pip install with magic command.

How is this patch tested?

  • I have written tests (not required for typo or doc fix) and confirmed the proposed feature/bug-fix/change works.

Does this PR change any dependencies?

  • No. You can skip this section.
  • Yes. Make sure the dependencies are resolved correctly, and list changes here.

Does this PR add a new feature? If so, have you added samples on website?

  • No. You can skip this section.
  • Yes. Make sure you have added samples following below steps.
  1. Find the corresponding markdown file for your new feature in website/docs/documentation folder.
    Make sure you choose the correct class estimators/transformers and namespace.
  2. Follow the pattern in markdown file and add another section for your new API, including pyspark, scala (and .NET potentially) samples.
  3. Make sure the DocTable points to correct API link.
  4. Navigate to website folder, and run yarn run start to make sure the website renders correctly.
  5. Don't forget to add <!--pytest-codeblocks:cont--> before each python code blocks to enable auto-tests for python samples.
  6. Make sure the WebsiteSamplesTests job pass in the pipeline.

AB#1958014

@github-actions
Copy link

github-actions bot commented Sep 1, 2022

Hey @thinkall 👋!
Thank you so much for contributing to our repository 🙌.
Someone from SynapseML Team will be reviewing this pull request soon.
We appreciate your patience and contributions 💯!

@thinkall thinkall changed the title doc: add mlflow logging and loading docs: add mlflow logging and loading Sep 1, 2022
@thinkall
Copy link
Contributor Author

thinkall commented Sep 1, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@codecov-commenter
Copy link

codecov-commenter commented Sep 1, 2022

Codecov Report

Merging #1641 (515a58b) into master (4115d4f) will increase coverage by 0.04%.
The diff coverage is n/a.

@@            Coverage Diff             @@
##           master    #1641      +/-   ##
==========================================
+ Coverage   85.74%   85.79%   +0.04%     
==========================================
  Files         272      272              
  Lines       14230    14230              
  Branches      739      739              
==========================================
+ Hits        12202    12208       +6     
+ Misses       2028     2022       -6     
Impacted Files Coverage Δ
...rosoft/azure/synapse/ml/stages/EnsembleByKey.scala 88.73% <0.00%> (+1.40%) ⬆️
...oft/azure/synapse/ml/lightgbm/NetworkManager.scala 92.22% <0.00%> (+2.77%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

"source": [
"# load model back\n",
"# mlflow will use PipelineModel to wrapper the original model, thus here we extract the original ALSModel from the stages.\n",
"loaded_model = mlflow.spark.load_model(model_uri, dfs_tmpdir=\"Files/spark\").stages[-1]"
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think serena might have fixed this behavior in MLFlow so that it just loads and saves original model, can you check with her to see?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hihi, I didn't change this part lol and we can't. Because they need a consistent API to load the model back, which only PipelineModel does, so we have to fetch the stages within it. I was using the similar logic in our dotnet stuff, because you can't know the real type only after you load it back, and sometimes we might just save a PipelineModel so you don't need to fetch the stages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks Mark. Just checked with Serena. MLflow still wraps original model with PipelineModel. In most cases, we only use model.transform which also works with PipelineModel. Only in this case, ALSModel has method like recommendForAllUsers which is needed in recommendation scenario. Maybe it's acceptable to extract original model from stages in special cases like this one.

thinkall and others added 2 commits September 2, 2022 09:38
Co-authored-by: Mark Hamilton <mhamilton723@gmail.com>
@thinkall
Copy link
Contributor Author

thinkall commented Sep 2, 2022

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Comment on lines +1279 to +1302
"with mlflow.start_run() as run:\n",
" print(\"log model:\")\n",
" mlflow.spark.log_model(\n",
" model,\n",
" f\"{EXPERIMENT_NAME}-alsmodel\",\n",
" registered_model_name=f\"{EXPERIMENT_NAME}-alsmodel\",\n",
" dfs_tmpdir=\"Files/spark\",\n",
" )\n",
"\n",
" print(\"log metrics:\")\n",
" mlflow.log_metrics({\"RMSE\": rmse, \"MAE\": mae, \"R2\": r2, \"Explained variance\": var})\n",
"\n",
" print(\"log parameters:\")\n",
" mlflow.log_params(\n",
" {\n",
" \"num_epochs\": num_epochs,\n",
" \"rank_size_list\": rank_size_list,\n",
" \"reg_param_list\": reg_param_list,\n",
" \"model_tuning_method\": model_tuning_method,\n",
" \"DATA_FOLDER\": DATA_FOLDER,\n",
" }\n",
" )\n",
"\n",
" model_uri = f\"runs:/{run.info.run_id}/{EXPERIMENT_NAME}-alsmodel\"\n",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can this be simplified with @serena-ruan 's Autologging?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently mlflow.pyspark.ml.autolog doesn't work since the default dfs_tmpdir is /tmp/mlflow, which doesn't work in our platform. Need to wait for another release of mlflow which will include Serena's PR for setting DFS_TMP as an environment variable. Moreover, for ALS model, it's not supported by autolog. I see Serena has two PRs for supporting modifying logModelAllowlistFile in a user friendly way, I guess those will be released in the next version of mlflow too.

Copy link
Collaborator

@mhamilton723 mhamilton723 left a comment

Choose a reason for hiding this comment

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

It looks good, i would just check with Serena if we can further simplify with her autologging, then the story will be full and very nice

@mhamilton723 mhamilton723 merged commit 59a922b into microsoft:master Sep 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants