Skip to content

Conversation

@rabah-khalek
Copy link
Contributor

@rabah-khalek rabah-khalek commented Aug 2, 2023

Integration

Prerequisites

  1. Create a wandb account here.
  2. Open your docker app
  3. Install python package and server
    pip install wandb
    wandb login --relogin # input the API key you get from the website
    wandb server start --upgrade # this will download the docker images if they're not already downloaded

Features

import giskard, wandb
# [...] wrap model and dataset with giskard
scan_results = giskard.scan(giskard_model, giskard_dataset)
test_suite_results = scan_results.generate_test_suite().run()
shap_results = giskard.explain_with_shap(giskard_model, giskard_dataset)

wandb.login()
giskard_dataset.to_wandb() # log dataset
scan_results.to_wandb() # log scan results
test_suite_results.to_wandb() # log test suite results
shap_results.to_wandb() # log shap results as plots 

Todo

@linear
Copy link

linear bot commented Aug 2, 2023

@rabah-khalek rabah-khalek added the Python Pull requests that update Python code label Aug 2, 2023
@rabah-khalek rabah-khalek marked this pull request as draft August 2, 2023 11:59
AbSsEnT and others added 4 commits August 3, 2023 19:10
@rabah-khalek rabah-khalek changed the title [GSK-1505] Integration with W&B [GSK-1504] Integration with W&B Aug 4, 2023
@linear
Copy link

linear bot commented Aug 4, 2023

rabah-khalek and others added 13 commits August 4, 2023 14:55
* Added new method to the TestSuiteResult class to log its execution results to the WandB run.

* Resolved issues.

* refactoring _parse_test_name

---------

Co-authored-by: Rabah Abdul Khalek <[email protected]>
* Initial commit with the implementation of the SHAP explanation graphs logging to the WandB run.

* Changed logic of obtaining feature names and types.

* Removed redundant 'model.prepare_dataframe'. Small refactoring.

* Added sorting of logged dataset, test suite result and scan result to distinct panels.

* Moved 'explain' function below shap-related functions.

* Code refactoring.

* Changed naming for variables inside functions.

* Removed explainer return, as it is not needed.

* Moved 'prepare_df' to the separate utils.py file to avoid code duplication.

* Added docstring to the '_get_cls_prediction_explanation'

* Created dataclass ShapResult to store shap explanations there and encapsulate the logic of uploading SHAP charts to the WandB.

* Refactoring of the 'background_example' function.

* Refactoring.

* Refactoring.

* Changed enum class declaration.

* Refactored model_explanation.py to be able to perform testing of explanation results equality. Added unit-tests for the SHAP logging to the WandB.

* Small fix in comments.

* Uncommented fixture.

* Refactored "_get_highest_prob_shap" function. Made it more compact and self-explainable.

* Removed #noqa options from the shap imports. Optimized imports.

* Refactored _prepare_for_explanation function. Changed naming of the function output to highlight, that this data will be explained.

* Renamed explain_full(one) to "_calculate_dataset(sample)_shap_values"

* Refactored _get_background_example function.

* Refactored 'explain_with_shap' function and 'ShapResult' dataclass for better handling classification models explanation.

* Fixed bugs with unit-tests for wandb.

* Transferred '_compare_explain_functions' to the 'test_model_explanation.py'

* Refactoring. Renaming and functions replacement.

* Renaming.

* Transferred plotting functions from the shap_result.py to the wandb_utils.py to better handle wandb importing necessity.

* small update to error msg

* updated unit test

* small update

---------

Co-authored-by: Rabah Abdul Khalek <[email protected]>
@rabah-khalek rabah-khalek marked this pull request as ready for review August 16, 2023 17:48
Copy link
Contributor

@andreybavt andreybavt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking looks good to me, I left a few non-major comments

rabah-khalek and others added 4 commits August 28, 2023 16:39
* Added docstrings to the "model_explanation.py".

* Added docstrings to the "shap_result.py".

* Fix in docstrings

* Added docstring to the 'Dataset.to_wandb'.

* Added docstring to the 'ScanResult.to_wandb'.

* Added docstring to the 'TestSuiteResult.to_wandb'.

* Resolved issues after PR review.

* updated docstrings

---------

Co-authored-by: Rabah Abdul Khalek <[email protected]>
Copy link
Contributor

@andreybavt andreybavt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@andreybavt andreybavt merged commit cb2a75a into main Aug 30, 2023
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

91.6% 91.6% Coverage
0.0% 0.0% Duplication

@Hartorn Hartorn deleted the GSK-1505-wandb branch September 22, 2023 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Integrations Python Pull requests that update Python code

Development

Successfully merging this pull request may close these issues.

4 participants