-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 1 commit
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
Temp
Signed-off-by: Felix Wang <wangfelix98@gmail.com>
- Loading branch information
commit 40d7965a752fd673c194156945c004af6b1961c2
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
| 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,28 +86,30 @@ 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): | ||
| projection = feature_grouping.projection | ||
|
|
||
| if fvs_to_update and feature_grouping.name in fvs_to_update: | ||
| # There are three situations to be handled. First, the projection specifies | ||
| # desired features, in which case we should select those desired features. | ||
| # Second, the projection does not specify any desired features but has | ||
| # already selected features, in which case nothing needs to be done. And | ||
| # third, the projection does not specify any desired features but has not | ||
| # yet selected features (since the original feature view did not yet have | ||
| # features), in which case we should select all possible inferred features. | ||
| if projection.desired_features: | ||
| # First case, so we select the specific desired features. | ||
|
|
||
|
|
||
| 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: | ||
| # Validate that the selected features have actually been inferred. | ||
| desired_features = set(projection.desired_features) | ||
| actual_features = set( | ||
| [ | ||
|
|
@@ -116,27 +119,32 @@ def infer_features(self, fvs_to_update: Optional[Dict[str, FeatureView]] = None) | |
| ) | ||
| 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. | ||
| # 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: | ||
| projection.features.append(f) | ||
| elif not projection.desired_features and projection.features: | ||
| # Second cass, so nothing needs to be done. In case something went wrong | ||
| # during feature inference, we check that the selected features still exist. | ||
| actual_features = set( | ||
| [ | ||
| f.name | ||
| for f in fvs_to_update[feature_grouping.name].features | ||
| ] | ||
| ) | ||
| assert projection.features.issubset(actual_features) | ||
| else: | ||
| # Third case, so all inferred features will be selected. | ||
| 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'. | ||
| 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. | ||
| projection.features = fvs_to_update[ | ||
| feature_grouping.name | ||
| ].features | ||
| else: | ||
| raise ValueError( | ||
| f"The feature service {self.name} has been provided with an invalid type " | ||
|
|
||
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.