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

Load models from a model registry rather than path #149

Merged
merged 7 commits into from
Jul 21, 2022

Conversation

nv-alaiacano
Copy link
Collaborator

This gives the option to load models into PredictTensorflow from any model registry, and includes an implementation for mlflow.

Example usage:

PredictTensorflow.from_model_registry(
    MLFlowModelRegistry("my_production_model", "version-1", "http://tracking-uri")
)

The implementation simply gets the path to the model and uses it to call PredictTensorflow's init method.

One issue that I ran into is that it seems like it would be nice to have this available for all implementations of InferenceOperator, but not all of those implementations accept a model path as an input - in fact only PredictTensorflow does. FIL only takes a model input as an input, and TransformWorkflow doesn't use a model at all.

I came up with a questionable solution of looking for model_or_path in the signature of the implementation class's __init__ method (in fact, it should be the first argument to that method). I'd love to hear a suggestion of a better way to do this.

@nvidia-merlin-bot
Copy link

Click to view CI Results
GitHub pull request #149 of commit 7525fc31a4dead4371890b60c719c5efc8c6ec4e, no merge conflicts.
Running as SYSTEM
Setting status of 7525fc31a4dead4371890b60c719c5efc8c6ec4e to PENDING with url https://10.20.13.93:8080/job/merlin_systems/152/console and message: 'Pending'
Using context: Jenkins
Building on master in workspace /var/jenkins_home/workspace/merlin_systems
using credential fce1c729-5d7c-48e8-90cb-b0c314b1076e
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/NVIDIA-Merlin/systems # timeout=10
Fetching upstream changes from https://github.com/NVIDIA-Merlin/systems
 > git --version # timeout=10
using GIT_ASKPASS to set credentials login for merlin-systems user + githubtoken
 > git fetch --tags --force --progress -- https://github.com/NVIDIA-Merlin/systems +refs/pull/149/*:refs/remotes/origin/pr/149/* # timeout=10
 > git rev-parse 7525fc31a4dead4371890b60c719c5efc8c6ec4e^{commit} # timeout=10
Checking out Revision 7525fc31a4dead4371890b60c719c5efc8c6ec4e (detached)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 7525fc31a4dead4371890b60c719c5efc8c6ec4e # timeout=10
Commit message: "remove implementation classes from tests"
 > git rev-list --no-walk 9910bfe09817c83159a425874220a69c59878d57 # timeout=10
[merlin_systems] $ /bin/bash /tmp/jenkins5494403820059294037.sh
PYTHONPATH=:/usr/local/lib/python3.8/dist-packages/:/usr/local/hugectr/lib:/var/jenkins_home/workspace/merlin_systems/systems
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0
rootdir: /var/jenkins_home/workspace/merlin_systems/systems, configfile: pyproject.toml
plugins: anyio-3.6.1, xdist-2.5.0, forked-1.4.0, cov-3.0.0
collected 51 items

tests/unit/test_version.py . [ 1%]
tests/unit/examples/test_serving_ranking_models_with_merlin_systems.py . [ 3%]
[ 3%]
tests/unit/systems/test_ensemble.py .... [ 11%]
tests/unit/systems/test_ensemble_ops.py .. [ 15%]
tests/unit/systems/test_export.py . [ 17%]
tests/unit/systems/test_graph.py . [ 19%]
tests/unit/systems/test_inference_ops.py .... [ 27%]
tests/unit/systems/test_model_registry.py . [ 29%]
tests/unit/systems/test_op_runner.py .... [ 37%]
tests/unit/systems/test_tensorflow_inf_op.py ... [ 43%]
tests/unit/systems/fil/test_fil.py .......................... [ 94%]
tests/unit/systems/fil/test_forest.py ... [100%]

=============================== warnings summary ===============================
../../../../../usr/local/lib/python3.8/dist-packages/nvtabular/framework_utils/init.py:18
/usr/local/lib/python3.8/dist-packages/nvtabular/framework_utils/init.py:18: DeprecationWarning: The nvtabular.framework_utils module is being replaced by the Merlin Models library. Support for importing from nvtabular.framework_utils is deprecated, and will be removed in a future version. Please consider using the models and layers from Merlin Models instead.
warnings.warn(

tests/unit/examples/test_serving_ranking_models_with_merlin_systems.py: 1 warning
tests/unit/systems/test_ensemble.py: 2 warnings
tests/unit/systems/test_export.py: 1 warning
tests/unit/systems/test_inference_ops.py: 2 warnings
tests/unit/systems/test_op_runner.py: 4 warnings
/usr/local/lib/python3.8/dist-packages/cudf/core/frame.py:384: UserWarning: The deep parameter is ignored and is only included for pandas compatibility.
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column x is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column y is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column id is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/fil/test_fil.py::test_binary_classifier_default[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_binary_classifier_with_proba[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_multi_classifier[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_regressor[sklearn_forest_regressor-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_model_file[sklearn_forest_regressor-checkpoint.tl]
/usr/local/lib/python3.8/dist-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute n_features_ was deprecated in version 1.0 and will be removed in 1.2. Use n_features_in_ instead.
warnings.warn(msg, category=FutureWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================= 51 passed, 19 warnings in 252.90s (0:04:12) ==================
Performing Post build task...
Match found for : : True
Logical operation result is TRUE
Running script : #!/bin/bash
cd /var/jenkins_home/
CUDA_VISIBLE_DEVICES=1 python test_res_push.py "https://api.GitHub.com/repos/NVIDIA-Merlin/systems/issues/$ghprbPullId/comments" "/var/jenkins_home/jobs/$JOB_NAME/builds/$BUILD_NUMBER/log"
[merlin_systems] $ /bin/bash /tmp/jenkins15926708347621448097.sh

@github-actions
Copy link

Documentation preview

https://nvidia-merlin.github.io/systems/review/pr-149

@nvidia-merlin-bot
Copy link

Click to view CI Results
GitHub pull request #149 of commit 3f7534853b39af8d7042e05e5d378d390948c92d, no merge conflicts.
Running as SYSTEM
Setting status of 3f7534853b39af8d7042e05e5d378d390948c92d to PENDING with url https://10.20.13.93:8080/job/merlin_systems/153/console and message: 'Pending'
Using context: Jenkins
Building on master in workspace /var/jenkins_home/workspace/merlin_systems
using credential fce1c729-5d7c-48e8-90cb-b0c314b1076e
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/NVIDIA-Merlin/systems # timeout=10
Fetching upstream changes from https://github.com/NVIDIA-Merlin/systems
 > git --version # timeout=10
using GIT_ASKPASS to set credentials login for merlin-systems user + githubtoken
 > git fetch --tags --force --progress -- https://github.com/NVIDIA-Merlin/systems +refs/pull/149/*:refs/remotes/origin/pr/149/* # timeout=10
 > git rev-parse 3f7534853b39af8d7042e05e5d378d390948c92d^{commit} # timeout=10
Checking out Revision 3f7534853b39af8d7042e05e5d378d390948c92d (detached)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f 3f7534853b39af8d7042e05e5d378d390948c92d # timeout=10
Commit message: "fix typo"
 > git rev-list --no-walk 7525fc31a4dead4371890b60c719c5efc8c6ec4e # timeout=10
[merlin_systems] $ /bin/bash /tmp/jenkins9378471006788988482.sh
PYTHONPATH=:/usr/local/lib/python3.8/dist-packages/:/usr/local/hugectr/lib:/var/jenkins_home/workspace/merlin_systems/systems
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0
rootdir: /var/jenkins_home/workspace/merlin_systems/systems, configfile: pyproject.toml
plugins: anyio-3.6.1, xdist-2.5.0, forked-1.4.0, cov-3.0.0
collected 51 items

tests/unit/test_version.py . [ 1%]
tests/unit/examples/test_serving_ranking_models_with_merlin_systems.py . [ 3%]
[ 3%]
tests/unit/systems/test_ensemble.py .... [ 11%]
tests/unit/systems/test_ensemble_ops.py .. [ 15%]
tests/unit/systems/test_export.py . [ 17%]
tests/unit/systems/test_graph.py . [ 19%]
tests/unit/systems/test_inference_ops.py .... [ 27%]
tests/unit/systems/test_model_registry.py . [ 29%]
tests/unit/systems/test_op_runner.py .... [ 37%]
tests/unit/systems/test_tensorflow_inf_op.py ... [ 43%]
tests/unit/systems/fil/test_fil.py .......................... [ 94%]
tests/unit/systems/fil/test_forest.py ... [100%]

=============================== warnings summary ===============================
../../../../../usr/local/lib/python3.8/dist-packages/nvtabular/framework_utils/init.py:18
/usr/local/lib/python3.8/dist-packages/nvtabular/framework_utils/init.py:18: DeprecationWarning: The nvtabular.framework_utils module is being replaced by the Merlin Models library. Support for importing from nvtabular.framework_utils is deprecated, and will be removed in a future version. Please consider using the models and layers from Merlin Models instead.
warnings.warn(

tests/unit/examples/test_serving_ranking_models_with_merlin_systems.py: 1 warning
tests/unit/systems/test_ensemble.py: 2 warnings
tests/unit/systems/test_export.py: 1 warning
tests/unit/systems/test_inference_ops.py: 2 warnings
tests/unit/systems/test_op_runner.py: 4 warnings
/usr/local/lib/python3.8/dist-packages/cudf/core/frame.py:384: UserWarning: The deep parameter is ignored and is only included for pandas compatibility.
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column x is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column y is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column id is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/fil/test_fil.py::test_binary_classifier_default[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_binary_classifier_with_proba[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_multi_classifier[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_regressor[sklearn_forest_regressor-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_model_file[sklearn_forest_regressor-checkpoint.tl]
/usr/local/lib/python3.8/dist-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute n_features_ was deprecated in version 1.0 and will be removed in 1.2. Use n_features_in_ instead.
warnings.warn(msg, category=FutureWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================= 51 passed, 19 warnings in 239.64s (0:03:59) ==================
Performing Post build task...
Match found for : : True
Logical operation result is TRUE
Running script : #!/bin/bash
cd /var/jenkins_home/
CUDA_VISIBLE_DEVICES=1 python test_res_push.py "https://api.GitHub.com/repos/NVIDIA-Merlin/systems/issues/$ghprbPullId/comments" "/var/jenkins_home/jobs/$JOB_NAME/builds/$BUILD_NUMBER/log"
[merlin_systems] $ /bin/bash /tmp/jenkins14350907838927751959.sh


# validate that we have a model_or_path argument. This is a total hack and perhaps a smell
# that all inference operators should accept a model_or_path, or at least we introduce
# another layer of base class that does.
Copy link
Contributor

Choose a reason for hiding this comment

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

One trick I use sometimes when there are two options is to make one of them the type expected by the constructor and then add a class method that takes the other type and converts it. In this case, I'd probably pass the model type into constructors, and add a class method like from_path that loads the models and passes them to the constructors.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That's a great idea. In the case of TransformWorkflow the from_path method could throw some kind of exception since it doesn't really make sense for that operator.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make sense if you want to load a Workflow from a file, which is not an uncommon thing to do.

import requests


class ModelRegistry:
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this only has an abstract method, maybe the class should be abstract too?

@karlhigley karlhigley added the enhancement New feature or request label Jul 21, 2022
@nvidia-merlin-bot
Copy link

Click to view CI Results
GitHub pull request #149 of commit a07858a826a9a11109436ae3cd16701876e6df9c, no merge conflicts.
Running as SYSTEM
Setting status of a07858a826a9a11109436ae3cd16701876e6df9c to PENDING with url https://10.20.13.93:8080/job/merlin_systems/154/console and message: 'Pending'
Using context: Jenkins
Building on master in workspace /var/jenkins_home/workspace/merlin_systems
using credential fce1c729-5d7c-48e8-90cb-b0c314b1076e
 > git rev-parse --is-inside-work-tree # timeout=10
Fetching changes from the remote Git repository
 > git config remote.origin.url https://github.com/NVIDIA-Merlin/systems # timeout=10
Fetching upstream changes from https://github.com/NVIDIA-Merlin/systems
 > git --version # timeout=10
using GIT_ASKPASS to set credentials login for merlin-systems user + githubtoken
 > git fetch --tags --force --progress -- https://github.com/NVIDIA-Merlin/systems +refs/pull/149/*:refs/remotes/origin/pr/149/* # timeout=10
 > git rev-parse a07858a826a9a11109436ae3cd16701876e6df9c^{commit} # timeout=10
Checking out Revision a07858a826a9a11109436ae3cd16701876e6df9c (detached)
 > git config core.sparsecheckout # timeout=10
 > git checkout -f a07858a826a9a11109436ae3cd16701876e6df9c # timeout=10
Commit message: "refactor to add from_path method"
 > git rev-list --no-walk 3f7534853b39af8d7042e05e5d378d390948c92d # timeout=10
[merlin_systems] $ /bin/bash /tmp/jenkins17333612293791564833.sh
PYTHONPATH=:/usr/local/lib/python3.8/dist-packages/:/usr/local/hugectr/lib:/var/jenkins_home/workspace/merlin_systems/systems
============================= test session starts ==============================
platform linux -- Python 3.8.10, pytest-7.1.2, pluggy-1.0.0
rootdir: /var/jenkins_home/workspace/merlin_systems/systems, configfile: pyproject.toml
plugins: anyio-3.6.1, xdist-2.5.0, forked-1.4.0, cov-3.0.0
collected 50 items

tests/unit/test_version.py . [ 2%]
tests/unit/examples/test_serving_ranking_models_with_merlin_systems.py . [ 4%]
[ 4%]
tests/unit/systems/test_ensemble.py .... [ 12%]
tests/unit/systems/test_ensemble_ops.py .. [ 16%]
tests/unit/systems/test_export.py . [ 18%]
tests/unit/systems/test_graph.py . [ 20%]
tests/unit/systems/test_inference_ops.py ... [ 26%]
tests/unit/systems/test_model_registry.py . [ 28%]
tests/unit/systems/test_op_runner.py .... [ 36%]
tests/unit/systems/test_tensorflow_inf_op.py ... [ 42%]
tests/unit/systems/fil/test_fil.py .......................... [ 94%]
tests/unit/systems/fil/test_forest.py ... [100%]

=============================== warnings summary ===============================
../../../../../usr/local/lib/python3.8/dist-packages/nvtabular/framework_utils/init.py:18
/usr/local/lib/python3.8/dist-packages/nvtabular/framework_utils/init.py:18: DeprecationWarning: The nvtabular.framework_utils module is being replaced by the Merlin Models library. Support for importing from nvtabular.framework_utils is deprecated, and will be removed in a future version. Please consider using the models and layers from Merlin Models instead.
warnings.warn(

tests/unit/examples/test_serving_ranking_models_with_merlin_systems.py: 1 warning
tests/unit/systems/test_ensemble.py: 2 warnings
tests/unit/systems/test_export.py: 1 warning
tests/unit/systems/test_inference_ops.py: 2 warnings
tests/unit/systems/test_op_runner.py: 4 warnings
/usr/local/lib/python3.8/dist-packages/cudf/core/frame.py:384: UserWarning: The deep parameter is ignored and is only included for pandas compatibility.
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column x is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column y is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/test_export.py::test_export_run_ensemble_triton[tensorflow-parquet]
/var/jenkins_home/workspace/merlin_systems/systems/merlin/systems/triton/export.py:304: UserWarning: Column id is being generated by NVTabular workflow but is unused in test_name_tf model
warnings.warn(

tests/unit/systems/fil/test_fil.py::test_binary_classifier_default[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_binary_classifier_with_proba[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_multi_classifier[sklearn_forest_classifier-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_regressor[sklearn_forest_regressor-get_model_params4]
tests/unit/systems/fil/test_fil.py::test_model_file[sklearn_forest_regressor-checkpoint.tl]
/usr/local/lib/python3.8/dist-packages/sklearn/utils/deprecation.py:103: FutureWarning: Attribute n_features_ was deprecated in version 1.0 and will be removed in 1.2. Use n_features_in_ instead.
warnings.warn(msg, category=FutureWarning)

-- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
================= 50 passed, 19 warnings in 278.28s (0:04:38) ==================
Performing Post build task...
Match found for : : True
Logical operation result is TRUE
Running script : #!/bin/bash
cd /var/jenkins_home/
CUDA_VISIBLE_DEVICES=1 python test_res_push.py "https://api.GitHub.com/repos/NVIDIA-Merlin/systems/issues/$ghprbPullId/comments" "/var/jenkins_home/jobs/$JOB_NAME/builds/$BUILD_NUMBER/log"
[merlin_systems] $ /bin/bash /tmp/jenkins438915323002614669.sh

Copy link
Contributor

@karlhigley karlhigley left a comment

Choose a reason for hiding this comment

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

🚀

@nv-alaiacano nv-alaiacano merged commit 07bf4ab into NVIDIA-Merlin:main Jul 21, 2022
@nv-alaiacano nv-alaiacano deleted the alaiacano/from-mlflow branch July 21, 2022 19:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants