-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: Fix feature service inference logic #3089
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
feast-ci-bot
merged 11 commits into
feast-dev:master
from
felixwang9817:fix_feature_service_inference
Aug 19, 2022
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e09ad3
Add __init__.py files to allow test files to share names
felixwang9817 5a5c6f6
Add feature service tests
felixwang9817 07eaba6
Fix feature service inference logic
felixwang9817 51174b3
Remove stray `__init__.py` file
felixwang9817 45ec63c
Fix comments
felixwang9817 7a43b8f
Add check
felixwang9817 40d7965
Temp
felixwang9817 8dfb6db
Address comments
felixwang9817 c4d9c5a
Fix
felixwang9817 64dfdef
Address comments
felixwang9817 31115ac
Fix
felixwang9817 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| from typeguard import typechecked | ||
|
|
||
| from feast.base_feature_view import BaseFeatureView | ||
| from feast.errors import FeatureViewMissingDuringFeatureServiceInference | ||
| from feast.feature_logging import LoggingConfig | ||
| from feast.feature_view import FeatureView | ||
| from feast.feature_view_projection import FeatureViewProjection | ||
|
|
@@ -85,32 +86,68 @@ def __init__( | |
| if isinstance(feature_grouping, BaseFeatureView): | ||
| self.feature_view_projections.append(feature_grouping.projection) | ||
|
|
||
| def infer_features(self, fvs_to_update: Optional[Dict[str, FeatureView]] = None): | ||
| def infer_features(self, fvs_to_update: Dict[str, FeatureView]): | ||
| """ | ||
| Infers the features for the projections of this feature service, and updates this feature | ||
| service in place. | ||
|
|
||
| This method is necessary since feature services may rely on feature views which require | ||
| feature inference. | ||
|
|
||
| Args: | ||
| fvs_to_update: A mapping of feature view names to corresponding feature views that | ||
| contains all the feature views necessary to run inference. | ||
| """ | ||
| for feature_grouping in self._features: | ||
| if isinstance(feature_grouping, BaseFeatureView): | ||
| # For feature services that depend on an unspecified feature view, apply inferred schema | ||
| if fvs_to_update and feature_grouping.name in fvs_to_update: | ||
| if feature_grouping.projection.desired_features: | ||
| desired_features = set( | ||
| feature_grouping.projection.desired_features | ||
| ) | ||
| projection = feature_grouping.projection | ||
|
|
||
| if projection.desired_features: | ||
| # The projection wants to select a specific set of inferred features. | ||
| # Example: FeatureService(features=[fv[["inferred_feature"]]]), where | ||
| # 'fv' is a feature view that was defined without a schema. | ||
| if feature_grouping.name in fvs_to_update: | ||
| # First we validate that the selected features have actually been inferred. | ||
| desired_features = set(projection.desired_features) | ||
| actual_features = set( | ||
| [ | ||
| f.name | ||
| for f in fvs_to_update[feature_grouping.name].features | ||
| ] | ||
| ) | ||
| assert desired_features.issubset(actual_features) | ||
| # We need to set the features for the projection at this point so we ensure we're starting with | ||
| # an empty list. | ||
| feature_grouping.projection.features = [] | ||
|
|
||
| # Then we extract the selected features and add them to the projection. | ||
| projection.features = [] | ||
| for f in fvs_to_update[feature_grouping.name].features: | ||
| if f.name in desired_features: | ||
| feature_grouping.projection.features.append(f) | ||
| projection.features.append(f) | ||
| else: | ||
| feature_grouping.projection.features = fvs_to_update[ | ||
| feature_grouping.name | ||
| ].features | ||
| raise FeatureViewMissingDuringFeatureServiceInference( | ||
| feature_view_name=feature_grouping.name, | ||
| feature_service_name=self.name, | ||
| ) | ||
|
|
||
| continue | ||
|
|
||
| if projection.features: | ||
| # The projection has already selected features from a feature view with a | ||
| # known schema, so no action needs to be taken. | ||
| # Example: FeatureService(features=[fv[["existing_feature"]]]), where | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also applies if the user is selecting from a fv with a known schema, but doesn't select features right? |
||
| # 'existing_feature' was defined as part of the schema of 'fv'. | ||
| # Example: FeatureService(features=[fv]), where 'fv' was defined with a schema. | ||
| continue | ||
|
|
||
| # The projection wants to select all possible inferred features. | ||
| # Example: FeatureService(features=[fv]), where 'fv' is a feature view that | ||
| # was defined without a schema. | ||
| if feature_grouping.name in fvs_to_update: | ||
| projection.features = fvs_to_update[feature_grouping.name].features | ||
| else: | ||
| raise FeatureViewMissingDuringFeatureServiceInference( | ||
| feature_view_name=feature_grouping.name, | ||
| feature_service_name=self.name, | ||
| ) | ||
| else: | ||
| raise ValueError( | ||
| f"The feature service {self.name} has been provided with an invalid type " | ||
|
|
||
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
Empty file.
63 changes: 63 additions & 0 deletions
63
sdk/python/tests/example_repos/example_feature_repo_with_feature_service_2.py
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,63 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from feast import Entity, FeatureService, FeatureView, Field, FileSource | ||
| from feast.types import Float32, Int32, Int64 | ||
|
|
||
| driver_hourly_stats = FileSource( | ||
| path="data/driver_stats.parquet", # Fake path | ||
| timestamp_field="event_timestamp", | ||
| created_timestamp_column="created", | ||
| ) | ||
|
|
||
| driver = Entity( | ||
| name="driver_id", | ||
| ) | ||
|
|
||
| driver_hourly_stats_view = FeatureView( | ||
| name="driver_hourly_stats", | ||
| entities=[driver], | ||
| ttl=timedelta(days=1), | ||
| schema=[ | ||
| Field(name="conv_rate", dtype=Float32), | ||
| Field(name="acc_rate", dtype=Float32), | ||
| Field(name="avg_daily_trips", dtype=Int64), | ||
| Field(name="driver_id", dtype=Int32), | ||
| ], | ||
| online=True, | ||
| source=driver_hourly_stats, | ||
| tags={}, | ||
| ) | ||
|
|
||
| global_daily_stats = FileSource( | ||
| path="data/global_stats.parquet", # Fake path | ||
| timestamp_field="event_timestamp", | ||
| created_timestamp_column="created", | ||
| ) | ||
|
|
||
| global_stats_feature_view = FeatureView( | ||
| name="global_daily_stats", | ||
| entities=[], | ||
| ttl=timedelta(days=1), | ||
| schema=[ | ||
| Field(name="num_rides", dtype=Int32), | ||
| Field(name="avg_ride_length", dtype=Float32), | ||
| ], | ||
| online=True, | ||
| source=global_daily_stats, | ||
| tags={}, | ||
| ) | ||
|
|
||
| all_stats_service = FeatureService( | ||
| name="all_stats", | ||
| features=[driver_hourly_stats_view, global_stats_feature_view], | ||
| tags={"release": "production"}, | ||
| ) | ||
|
|
||
| some_stats_service = FeatureService( | ||
| name="some_stats", | ||
| features=[ | ||
| driver_hourly_stats_view[["conv_rate"]], | ||
| global_stats_feature_view[["num_rides"]], | ||
| ], | ||
| tags={"release": "production"}, | ||
| ) |
52 changes: 52 additions & 0 deletions
52
sdk/python/tests/example_repos/example_feature_repo_with_feature_service_3.py
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,52 @@ | ||
| from datetime import timedelta | ||
|
|
||
| from feast import Entity, FeatureService, FeatureView, FileSource | ||
|
|
||
| driver_hourly_stats = FileSource( | ||
| path="%PARQUET_PATH%", # placeholder to be replaced by the test | ||
| timestamp_field="event_timestamp", | ||
| created_timestamp_column="created", | ||
| ) | ||
|
|
||
| driver = Entity( | ||
| name="driver_id", | ||
| ) | ||
|
|
||
| driver_hourly_stats_view = FeatureView( | ||
| name="driver_hourly_stats", | ||
| entities=[driver], | ||
| ttl=timedelta(days=1), | ||
| online=True, | ||
| source=driver_hourly_stats, | ||
| tags={}, | ||
| ) | ||
|
|
||
| global_daily_stats = FileSource( | ||
| path="%PARQUET_PATH_GLOBAL%", # placeholder to be replaced by the test | ||
| timestamp_field="event_timestamp", | ||
| created_timestamp_column="created", | ||
| ) | ||
|
|
||
| global_stats_feature_view = FeatureView( | ||
| name="global_daily_stats", | ||
| entities=[], | ||
| ttl=timedelta(days=1), | ||
| online=True, | ||
| source=global_daily_stats, | ||
| tags={}, | ||
| ) | ||
|
|
||
| all_stats_service = FeatureService( | ||
| name="all_stats", | ||
| features=[driver_hourly_stats_view, global_stats_feature_view], | ||
| tags={"release": "production"}, | ||
| ) | ||
|
|
||
| some_stats_service = FeatureService( | ||
| name="some_stats", | ||
| features=[ | ||
| driver_hourly_stats_view[["conv_rate"]], | ||
| global_stats_feature_view[["num_rides"]], | ||
| ], | ||
| tags={"release": "production"}, | ||
| ) |
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
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
Empty file.
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.