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

Add docs for consuming features in online environment #609

Merged
merged 16 commits into from
Sep 14, 2022
Merged
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,12 @@ Follow the [quick start Jupyter Notebook](./samples/product_recommendation_demo.

## 🚀 Roadmap

For a complete roadmap with estimated dates, please [visit this page](https://github.com/linkedin/feathr/milestones?direction=asc&sort=title&state=open).

- [x] Support streaming
- [x] Support common data sources
- [x] Support streaming features with transformation
- [x] Support common data sources and sinks
xiaoyongzhu marked this conversation as resolved.
Show resolved Hide resolved
- [x] Support feature store UI, including Lineage and Search functionalities
- [ ] Support a sandbox Feathr environment for better getting started experience
- [ ] Support online transformation
- [ ] More online client libraries such as Java
xiaoyongzhu marked this conversation as resolved.
Show resolved Hide resolved
- [ ] Support feature versioning
- [ ] Support feature monitoring
- [ ] Support feature data deletion and retention
Expand Down
58 changes: 58 additions & 0 deletions docs/how-to-guides/model-inference-with-feathr.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
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, usually end users want to consume those features in production environment for model inference.

With Feathr's online client, 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.
xiaoyongzhu marked this conversation as resolved.
Show resolved Hide resolved

```python

## put the section below into the initialization handler
import os
from feathr import FeathrClient

# Set Redis endpoint
os.environ['online_store__redis__host'] = "xx.redis.cache.windows.net"
xiaoyongzhu marked this conversation as resolved.
Show resolved Hide resolved
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",
xiaoyongzhu marked this conversation as resolved.
Show resolved Hide resolved
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)
```