PAIR-code / what-if-tool

Source code/webpage/demos for the What-If Tool
https://pair-code.github.io/what-if-tool
Apache License 2.0
892 stars 165 forks source link

GOOGLE APPLICATION CREDENTIALS #210

Closed callysthenes closed 1 year ago

callysthenes commented 1 year ago

I am getting an error on a large dataset asking for google application credentials. I created a new project in google cloud and linked the json file to the code but I am not able to get the tool to work properly, only the datapoint editor works and not the fairness part. I also tried to reduce the dataset but it still does not workl. Any hints?

RuntimeError('<HttpError 403 when requesting https://ml.googleapis.com/v1/projects/folkloric-grid-353308/models/580576910686/versions/v1:predict?alt=json returned "Access to project denied. This might be a transient error and a retry may succeed. If the error persists, please check the IAM permissions on your project.". Details: "Access to project denied. This might be a transient error and a retry may succeed. If the error persists, please check the IAM permissions on your project.">')

jameswex commented 1 year ago

Thanks for reaching out. Are you able to share the exact code that is failing to execute and what is your setup? Is this inside a notebook environment?

callysthenes commented 1 year ago

Thanks for the response. I am running a Jupyter notebook with Python 3.9.12 in an Anaconda framework:

C:\Users\Equipo\anaconda3\python.exe 3.9.12 (main, Apr 4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] sys.version_info(major=3, minor=9, micro=12, releaselevel='final', serial=0) Selected Jupyter core packages... IPython : 8.2.0 ipykernel : 6.9.1 ipywidgets : 7.6.5 jupyter_client : 6.1.12 jupyter_core : 4.9.2 jupyter_server : 1.13.5 jupyterlab : 3.3.2 nbclient : 0.5.13 nbconvert : 6.4.4 nbformat : 5.3.0 notebook : 6.4.8 qtconsole : 5.3.0 traitlets : 5.1.1

The code is as follows, (after fitting an XGBoost model)

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"]="folkloric-grid-353308-c47f8ed05edf.json"
def adjust_prediction(y_test_predict):
  return [1 - y_test_predict, y_test_predict]

config_builder = (WitConfigBuilder(test_examples.tolist(), data.columns.tolist() + ['Target'])
  .set_ai_platform_model('folkloric-grid-353308', 'Whatif', 'v1', adjust_prediction=adjust_prediction)
  .set_target_feature('Target')
  .set_label_vocab([0, 1]))
WitWidget(config_builder, height=1000)

Tool works partially, but not sure how to get the permissions so to have the full functionality (i.e. optimizaiton strategies, confusion matrixes, etc)

jameswex commented 1 year ago

The What-If Tool wasn't updated to work with the new Vertex AI models/cloud deployments, but only works with the old AI Platform models. I wonder if that is the issue you are running into. That being said, if you can query your model through other means in the jupyter notebook (outside of the What-If Tool), then you could put that same code inside a custom prediction function for WIT instead of using the set_ai_platform_model functionality.