Skip to content

Commit

Permalink
Updated Shap saving. (#881)
Browse files Browse the repository at this point in the history
* Updated Shap saving. Fixes savings for distributed KernelShap and avoids saving internal explainer.

* Fixed typo for the TreeShap saving function.
  • Loading branch information
RobertSamoilescu authored Mar 1, 2023
1 parent 58eaa34 commit 3594f71
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions alibi/saving.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,25 @@ def _save_AnchorText(explainer: 'AnchorText', path: Union[str, os.PathLike]) ->
explainer.perturbation = perturbation


def _save_KernelShap(explainer: 'KernelShap', path: Union[str, os.PathLike]) -> None:
# TODO: save internal shap objects using native pickle?
def _save_Shap(explainer: Union['KernelShap', 'TreeShap'], path: Union[str, os.PathLike]) -> None:
# set the internal explainer object to avoid saving it. The internal explainer
# object is recreated when in the `reset_predictor` function call.
_explainer = explainer._explainer
explainer._explainer = None

# simple save which does not save the predictor
_simple_save(explainer, path)

# reset the internal explainer object
explainer._explainer = _explainer

def _save_TreelShap(explainer: 'TreeShap', path: Union[str, os.PathLike]) -> None:
# TODO: save internal shap objects using native pickle?
_simple_save(explainer, path)

def _save_KernelShap(explainer: 'KernelShap', path: Union[str, os.PathLike]) -> None:
_save_Shap(explainer, path)


def _save_TreeShap(explainer: 'TreeShap', path: Union[str, os.PathLike]) -> None:
_save_Shap(explainer, path)


def _save_CounterfactualRL(explainer: 'CounterfactualRL', path: Union[str, os.PathLike]) -> None:
Expand Down

0 comments on commit 3594f71

Please sign in to comment.