-
Notifications
You must be signed in to change notification settings - Fork 237
Add support for white-box explainers to alibi-explain runtime #1279
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
adriangonz
merged 20 commits into
SeldonIO:master
from
ascillitoe:feature/white_box_explainers
Jul 6, 2023
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
5b88618
Minor generic refactors
082c54b
White box sklearn api runtime
e29b940
Move _explain_impl up a class, and add test for TreeShap
035de83
Add test for TreePartialDependence
5cfa207
Update tests to use case generator
c4ea56f
Test init_parameters and remove PartialDependenceVariance case
58a5d33
Change scope of sklearn model/data fixtures
e8629f0
Minor changes
016902d
Remove remaining tab changes
f5d5846
Add PartialDependenceVariance (white-box) test back in
4214f39
Correct sklearn model type annotation
ed0a1b9
Rename AlibiExplainSKLearnAPIRuntime to SKLearnRuntime
53ce0b0
Rename test_end_2_end to test_explain
75ab2e4
Remove sk_model helper
5f14616
Move income model and data from conftest.py to test_white_box_sklearn…
f193a8d
Update pyproject.toml and poetry.lock
33b1fd7
Remove loading as lgb.Booster
afae1e6
Add test for _get_inference_model
fdf4ce4
Fix linting
452d02e
Fix mypy errors
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
32 changes: 32 additions & 0 deletions
32
runtimes/alibi-explain/mlserver_alibi_explain/explainers/sklearn_api_runtime.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,32 @@ | ||
| from typing import Any | ||
|
|
||
| import joblib | ||
| from xgboost.core import XGBoostError | ||
|
|
||
| from mlserver_xgboost.xgboost import _load_sklearn_interface as load_xgb_model | ||
| from mlserver.errors import InvalidModelURI | ||
| from mlserver_alibi_explain.explainers.white_box_runtime import ( | ||
| AlibiExplainWhiteBoxRuntime, | ||
| ) | ||
|
|
||
|
|
||
| class SKLearnRuntime(AlibiExplainWhiteBoxRuntime): | ||
| """ | ||
| Runtime for white-box explainers that require access to a tree-based model matching | ||
| the SKLearn API, such as a sklearn, XGBoost, or LightGBM model. Example explainers | ||
| include TreeShap and TreePartialDependence. | ||
| """ | ||
|
|
||
| async def _get_inference_model(self) -> Any: | ||
| inference_model_path = self.alibi_explain_settings.infer_uri | ||
| # Attempt to load model. | ||
| try: | ||
|
adriangonz marked this conversation as resolved.
|
||
| # Try to load as joblib model first | ||
| model = joblib.load(inference_model_path) | ||
| except (IndexError, KeyError, IOError): | ||
| try: | ||
| # Try to load as XGBoost model | ||
| model = load_xgb_model(inference_model_path) | ||
| except XGBoostError: | ||
| raise InvalidModelURI(self.name, inference_model_path) | ||
| return model | ||
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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.