-
Notifications
You must be signed in to change notification settings - Fork 243
Add docs for consuming features in online environment #609
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
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
40a2dd5
Create consume-features.md
xiaoyongzhu 8fe6a24
Update consume-features.md
xiaoyongzhu 0a3d06d
rename docs
xiaoyongzhu dd55769
Update model-inference-with-feathr.md
xiaoyongzhu 7e8e75a
Update README.md
xiaoyongzhu d8147ee
update docs per feedback
xiaoyongzhu 9a9050d
Merge branch 'main' into consume_features
xiaoyongzhu 8aa79c1
Update streaming-source-ingestion.md
xiaoyongzhu 547c832
update docs
xiaoyongzhu e45bac9
update docs
xiaoyongzhu e9a5c5f
Update azure-deployment-arm.md
xiaoyongzhu 873687f
Update model-inference-with-feathr.md
xiaoyongzhu 0cbee7f
add sign off message
xiaoyongzhu 8f9bdbb
fix comments
xiaoyongzhu 59c59ad
Delete deploy-feathr-api-as-webapp.md
xiaoyongzhu cde63d2
Update model-inference-with-feathr.md
xiaoyongzhu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| --- | ||
| layout: default | ||
| title: Online Model Inference with Features from Feathr | ||
| parent: How-to Guides | ||
| --- | ||
|
|
||
| # Online Model Inference with Features from Feathr | ||
|
|
||
| After you have materialized features in online store such as Redis or Azure Cosmos DB, usually end users want to consume those features in production environment for model inference. | ||
|
|
||
| With Feathr's [online client](https://feathr.readthedocs.io/en/latest/#feathr.FeathrClient.get_online_features), it is quite straightforward to do that. The sample code is as below, where users only need to configure the online store endpoint (if using Redis), and call `client.get_online_features()` to get the features for a particular key. | ||
|
|
||
| ```python | ||
|
|
||
| ## put the section below into the initialization handler | ||
| import os | ||
| from feathr import FeathrClient | ||
|
|
||
| # Set Redis endpoint | ||
| os.environ['online_store__redis__host'] = "<replace_with_your_redis_name>.redis.cache.windows.net" | ||
| os.environ['online_store__redis__port'] = "6380" | ||
| os.environ['online_store__redis__ssl_enabled'] = "True" | ||
| os.environ['REDIS_PASSWORD'] = "<put-your-key-here>" | ||
|
|
||
| client = FeathrClient() | ||
|
|
||
|
|
||
| # put this section in the model inference handler | ||
| feature = client.get_online_features(feature_table="nycTaxiCITable", | ||
| key='2020-04-15', | ||
| feature_names=['f_is_long_trip_distance', 'f_day_of_week']) | ||
| # `res` will be an array representing the features of that particular key. | ||
|
|
||
|
|
||
| # `model` will be a ML model that is loaded previously. | ||
| result = model.predict(feature) | ||
| ``` | ||
|
|
||
| ## Best Practices | ||
|
|
||
| Usually for ML platforms such as Azure Machine Learning, Sagemaker, or DataRobot, there are options where you can "bring your own container" or using "container inference". Basically it requires end users to write an "entry script" and provide a few functions. In those cases, there are usually two handlers: | ||
|
|
||
| - an initialization handler to allow users to load configurations. For example, in Azure Machine Learning, it is a function called `init()`, and in Sagemaker, it is `model_fn()`. | ||
| - a model inference handler to do the model inference. For example, in Azure Machine Learning, it is called `init()`, and in Sagemaker, it is called `predict_fn()`. | ||
|
|
||
| In the initialization handler, initialize the environment variables and initialize `FeathrClient` as shown in the above script; in the inference handler, call this line: | ||
|
|
||
| ```python | ||
| # put this section in the model inference handler | ||
| feature = client.get_online_features(feature_table="nycTaxiCITable", | ||
| key='2020-04-15', | ||
| feature_names=['f_is_long_trip_distance', 'f_day_of_week']) | ||
| # `res` will be an array representing the features of that particular key. | ||
| # `model` will be a ML model that is loaded previously. | ||
| result = model.predict(feature) | ||
| ``` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.