Skip to content

feat: Add Explanations to service APIs#216

Merged
vinnysenthil merged 8 commits into
googleapis:devfrom
vinnysenthil:xai-api-only
Mar 4, 2021
Merged

feat: Add Explanations to service APIs#216
vinnysenthil merged 8 commits into
googleapis:devfrom
vinnysenthil:xai-api-only

Conversation

@vinnysenthil

Copy link
Copy Markdown
Contributor
  • Lifts the GAPIC types ExplanationMetadata and ExplanationParameters to the aiplatform namespace
  • Adds the ability to pass the two fields in ExplanationSpec to the following methods
    • Model.batch_predict()
    • Model.deploy()
    • Model.upload()
    • Endpoint.deploy()
    • BatchPredictionJob.create()
  • Add the method Endpoint.explain() to get predictions with explanations on deployed models
  • Unit tests for all the above changes

Fixes b/174502675 and part 1 of b/172828587 🦕

@google-cla google-cla Bot added the cla: yes This human has signed the Contributor License Agreement. label Feb 9, 2021

@ivanmkc ivanmkc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I haven't used explanations before but in general LGTM

@sasha-gitg sasha-gitg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Added a few comments. Thanks!

Comment thread google/cloud/aiplatform/jobs.py Outdated
Comment thread google/cloud/aiplatform/jobs.py Outdated
Comment thread google/cloud/aiplatform/__init__.py Outdated
from google.cloud.aiplatform_v1beta1.types.explanation_metadata import (
ExplanationMetadata,
)
from google.cloud.aiplatform_v1beta1.types.explanation import ExplanationParameters

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It makes sense to elevate these protos to the aiplatform namespace but ExplanationParameters relies on additional protos which are not elevated, requiring the user import from multiple modules to build the spec. Perhaps all of the required explanation protos should be encapsulated in the aiplatform.explain namespace.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sounds good, will elevate all Explanation protos to aiplatform.explain

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually only including protos that are used as inputs, and only raising ExplanationMetadata subclasses that are two levels deep. Lmk if you think we should include outputs too.

Comment thread google/cloud/aiplatform/models.py Outdated
@vinnysenthil vinnysenthil requested review from a team and sasha-gitg February 17, 2021 00:53

@sasha-gitg sasha-gitg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. Left a two more comments.

Comment thread google/cloud/aiplatform/jobs.py Outdated
Comment thread google/cloud/aiplatform/models.py
@vinnysenthil vinnysenthil added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Feb 17, 2021
@vinnysenthil

Copy link
Copy Markdown
Contributor Author

All requested changes from MB SDK Dev addressed. Blocking merge until receiving LGTM from XAI Eng.

@besimav besimav left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

LGTM overall.

Encoding = ExplanationMetadata.InputMetadata.Encoding
FeatureValueDomain = ExplanationMetadata.InputMetadata.FeatureValueDomain
Visualization = ExplanationMetadata.InputMetadata.Visualization

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

a bit orthogonal question: why don't we have Modality class?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It appears that modality is a string field in InputMetadata according to the protos. Should it be an enum?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I was looking at this proto. Do you know why it is an Enum in the DB one and not in the other by any chance? Anyhow, lgtm.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Interesting, I raised this with jianan@ and he explained they lean towards string over enums in the API protos to avoid having to make frequent changes to those files while the DB protos are more strongly typed. If it improves usability, we could manually add the enum in the SDK but it would have to be kept in sync.

@nanchenchen nanchenchen left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Thanks for working on this! It looks good to me 👍
I only have a minor comment. Should be good to go after addressing it.

Comment thread google/cloud/aiplatform/models.py Outdated
Comment on lines +754 to +759
if explanation_metadata or explanation_parameters:
explanation_spec = gca_endpoint.explanation.ExplanationSpec()
explanation_spec.metadata = explanation_metadata
explanation_spec.parameters = explanation_parameters
deployed_model.explanation_spec = explanation_spec

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since explanation_metadata and explanation_parameters must pass together, shouldn't this be an and instead of or?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The thought behind this was allowing the service to throw the exception about them being passed together instead of creating two sets of validation. I confirmed that an error response is returned service-side right away if only one is passed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We inform the user in the docstring. Do you think we should add validation in the library as well?

Both `explanation_metadata` and `explanation_parameters` must be
passed together when used. For more details, see

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think telling users what will fail as early as possible will be better. We don't necessary need full validation (though it is good to have if it is low cost), but having some basic sanity check can help prevent user frustration (especially since all the operations here are async and have some wait time).

Also, I noticed that there other similar logics are using and (e.g., Ln 1287), so I thought it was unintentional :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point, I've added the local validation for ensuring they are passed together.

@vinnysenthil vinnysenthil removed the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label Mar 3, 2021
@vinnysenthil vinnysenthil merged commit 350ffd5 into googleapis:dev Mar 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla: yes This human has signed the Contributor License Agreement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants